1

I'm trying to integrate this plug-in into my site so I can swipe to delete. The problem however is that this plugin is triggered with a 'swiperight', the same swipe event is used to reveal my panel. I managed to separate the events using event.target.tagName. When it's a A(link), I want to activate the swipe to delete button and otherwise I want my panel to slide in.

With other words the pageinit event is triggered twice so the swipe to delete button starts to appear then the same event is triggered again. I want to somehow cancel one action but i can't make it work. I already tried:

event.stopImmediatePropagation();
event.stopPropagation();
event.preventDefault();

I also tried to use some solutions given here but with no luck: jQuery Mobile: document ready vs page events

A demo of my problem can be found snip and my current pageinit function is this:

$(document).on('pageinit', function() {
    //Activate horizontal swipe after x px.
    $.event.special.swipe.horizontalDistanceThreshold = 80;
    $('div[data-role="content"]').on("swiperight", function(event) {
        //If tagname is 'A' you probably want slide to delete not the panel
        if(event.target.tagName != 'A') {
            $.mobile.activePage.find("#menu").panel("open");
        } else {
            //Cancel swipe
            event.stopImmediatePropagation();
        }
    });

    //Swipe to delete
    $("#swipe li").swiper( {
        corners: false,
        label: "Verwijder",
        swipe: function(event, ui) {
            alert('trigger');
        },
        click: function(event, ui) {
            var $item = $(this);
            //console.log($(this));
            $item.fadeOut(250, function() {
                $item.remove();
            });
        }
    });
}); 
Community
  • 1
  • 1

1 Answers1

0

Fixed issue using the following plugin: TouchSwipe which has the ability to simple exclude elements from the events.