Skip to content

Commit

Permalink
implement teardown
Browse files Browse the repository at this point in the history
based on marcandre#15
  • Loading branch information
butesa committed Sep 30, 2023
1 parent 67ea527 commit bf4cd42
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions jquery.detect_swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,21 @@
}

function teardown() {
this.removeEventListener('touchstart', onTouchStart);
this.removeEventListener && this.removeEventListener('touchstart', onTouchStart);
}

$.event.special.swipe = { setup: setup };
$.event.special.swipe = { setup: setup, teardown: teardown };

$.each(['left', 'up', 'down', 'right'], function () {
$.event.special['swipe' + this] = { setup: function(){
$(this).on('swipe', $.noop);
} };
$.each(['left', 'up', 'down', 'right'], function (i, name) {
$.event.special['swipe' + this] = {
setup: function(){
// Register a noop on a namespaced swipe event, this will call setup()
// See https://learn.jquery.com/events/event-basics/#namespacing-events
$(this).on('swipe.internal' + name, $.noop);
},
teardown: function() {
$(this).off('swipe.internal' + name);
}
};
});
}));

0 comments on commit bf4cd42

Please sign in to comment.