jQuery Mobile with touchmove event

I'm trying to manage a Basic select switch like in the following documentation:

http://demos.jquerymobile.com/1.4.5/flipswitch/

My code is:

HTML

    <div class="ui-flipswitch ui-shadow-inset ui-bar-inherit ui-corner-all ui-mini">
    <a href="#" class="ui-flipswitch-on ui-btn ui-shadow ui-btn-inherit">On</a>
    <span class="ui-flipswitch-off">Off</span>
    <select data-role="flipswitch" data-mini="true" 
name="login-memo-codice-inpt" id="login-memo-codice-inpt" class="ui-
flipswitch-input" tabindex="-1" disabled="">
    <option value="off">Off</option>
    <option value="on">On</option>
    </select>
    </div> 

JAVASCRIPT

inputManager.my_slider=function(page){
    var enableTap=false;
    var executed=false;
    var flipswitch=page.find(".ui-flipswitch");
    flipswitch.on("touchstart",function(e){
        enableTap=true;
        executed=false;
    });
    flipswitch.on("tap",function(){
        if(executed){
            return false;
        }
    });     
    flipswitch.on("touchmove",function(e){
        if(enableTap){
            enableTap=false;
            $(this).trigger("click");
            executed=true;
        }           
    });
    flipswitch.on("touchend",function(e){
        enableTap=false;
    });                     
    page.find(".ui-flipswitch-input").prop("disabled",true);
    page.find(".ui-flipswitch-input").on("touchstart focus",function(event){
        event.preventDefault();             
        $(this).blur();
        return false;
    });
    if(libs.check_current_device().ieMobile){
        flipswitch.on("mousedown",function(e){
            $(this).trigger("click");
        });
    }
};

It is works when I swipe on from left (ON) to right (OFF) or from right (OFF) to left (ON).

My problems are:

  1. if I hold my finger on the ON and then I swipe to right (OFF) the status goes to OFF then come back to ON immediately;
  2. if I hold my finger on the OFF and then I swipe to left (ON) the status goes to ON then come back to OFF immediately.

How to resolve this?

Upvotes: 0

Views: 1179

Answers (0)

Related Questions