var touchmove_flg = false; var touchdirection = ""; var direction = 0; var startX; var startY; var diffX; var diffY; var diffX_2; var diffY_2; var totalmove = 0; var move = 0; var move_x = 0; var move_y = 0; var ToRadian = function(degree){ return (degree) * (Math.PI / 180.0); }; var ToDegree = function(radian){ return (radian) * (180.0 / Math.PI); }; var isTouch = function(e){ //e.preventDefault(); var touch = e.originalEvent.touches[0]; if (e.type == "touchstart") { //画面にタッチした //タッチ開始時のX座標( startX ) startX = touch.pageX; startY = touch.pageY; totalmove = 0; move = 0; move_x = 0; move_y = 0; touchmove_flg = false; touchdirection = ""; direction = 0; } else if (e.type == "touchmove") { //画面をスライドした //スライド時のX座標 - 開始時のX座標 = 移動距離( diffX ) diffX = Math.abs(touch.pageX - startX); diffY = Math.abs(touch.pageY - startY); diffX_2 = touch.pageX - startX; diffY_2 = touch.pageY - startY; //総移動距離を計算 totalmove += Math.abs(Math.floor(Math.sqrt((diffX*diffX) + (diffY*diffY)))); //atan2に変更 move += Math.sqrt((diffX_2*diffX_2) + (diffY_2*diffY_2)); move_x += diffX_2; move_y += diffY_2; direction = Math.atan2(move_y, move_x); //方向を計算 //if((diffX_2 >= 10 || diffX_2 <= -10) && (diffY_2 <= 20 && diffY_2 >= -20)){ if((Math.abs(ToDegree(direction)) < 45 && Math.abs(ToDegree(direction)) >= 0) || Math.abs(ToDegree(direction)) > 325){ touchdirection = "right"; }else if(Math.abs(ToDegree(direction)) < 225 && Math.abs(ToDegree(direction)) > 135){ touchdirection = "left"; }else{ touchdirection = ""; } //移動距離が一定以下の場合はtouchendイベントを許可(touchmoveイベントが発生しないないことにする) if(totalmove < 10 && touchmove_flg == false){ touchmove_flg = false; }else{ touchmove_flg = true; } } else if (e.type == "touchend") { //画面から指を離した // //方向を計算 // //移動量のアークコサインでやろうとしたけど頭が回らなかったので簡単に計算 // if((diffX >= 1 || diffX <= -1) && (diffY <= 20 && diffY >= -20)){ // if(totalmove >= 10){ // touchdirection = "right"; // }else if(totalmove <= -10){ // touchdirection = "left"; // } // }else{ // touchdirection = ""; // } } }; $(document).on({ touchstart: function(e){ isTouch(e); }, touchmove: function(e){ isTouch(e); }, touchend: function(e){ isTouch(e); }}); $(document).on("mobileinit", function(){ $.mobile.ajaxEnabled = false; $.mobile.allowCrossDomainPages = true; $.mobile.linkBindingEnabled = false; $.mobile.defaultPageTransition = "fade"; }); //各イベント処理 $(document).on("touchend",".collapsible_title",function(){ if(!touchmove_flg){ $(this).next(".collapsible_contents").toggleClass("hidden"); $(this).toggleClass("ui-icon-carat-u"); $(this).toggleClass("ui-icon-carat-d"); } }); // $(document).on("touchend",".ui_btn",function(){ if(!touchmove_flg){ var href = $(this).children("a").attr("href"); if(href){ location.href = href; } } }); //チェックボックス切り替え $(document).on("change",".ui_checkbox_label input",function(){ if($(this).is(":checked") == true){ $(this).parent("label").not(".ui_checkbox_disabled").addClass("ui_state_checked"); }else{ $(this).parent("label").not(".ui_checkbox_disabled").removeClass("ui_state_checked"); } if($("input[id*=city_]:checked").length > 0){ //0以上 $(".ui_btn_submit").removeClass("ui_btn_submit_disabled"); }else{ if($("input[id*=line_]:checked").length > 0){ //0以上 $(".ui_btn_submit").removeClass("ui_btn_submit_disabled"); }else{ if($("input[id*=station_]:checked").length > 0){ //0以上 $(".ui_btn_submit").removeClass("ui_btn_submit_disabled"); }else{ $(".ui_btn_submit").addClass("ui_btn_submit_disabled"); } } } }); $(document).on("touchend",".ui_btn_submit",function(){ if(!touchmove_flg){ if(!$(this).hasClass("ui_btn_submit_disabled")){ var form = $(this).children("input")[0].dataset.form; if(form){ $("#" + form).submit(); } } } }); //ラジオボタン切り替え $(document).on("touchend",".radio_control .ui_btn",function(){ if(!touchmove_flg){ $(this).parent().children(".ui_state_radio_selected").removeClass("ui_state_radio_selected"); $(this).addClass("ui_state_radio_selected"); } }); $(document).on("touchend",".close_menu",function(){ if(!touchmove_flg){ var panelId = $(this)[0].offsetParent.id; // $("#" + panelId).panel(); $("." + panelId).panel("close"); //$(this).parents(".menu_panel").panel(); //$(this).parents(".menu_panel").panel("close"); //$(".menu_panel").panel("close"); } });