Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Swipe: Keep swiperight when tearing down swipeleft and vice versa
Browse files Browse the repository at this point in the history
(cherry picked from commit 0eba6e4)

Closes gh-7353
Fixes gh-7351
  • Loading branch information
Gabriel Schulhof committed May 23, 2014
1 parent bf06f5e commit 65e81c0
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
4 changes: 2 additions & 2 deletions js/events/touch.js
Expand Up @@ -313,8 +313,8 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
$.each({
scrollstop: "scrollstart",
taphold: "tap",
swipeleft: "swipe",
swiperight: "swipe"
swipeleft: "swipe.left",
swiperight: "swipe.right"
}, function( event, sourceEvent ) {

$.event.special[ event ] = {
Expand Down
39 changes: 39 additions & 0 deletions tests/integration/swipe/binding-tests.html
@@ -0,0 +1,39 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Swipe Event Test Suite</title>

<script src="../../../external/requirejs/require.js"></script>
<script src="../../../js/requirejs.config.js"></script>
<script src="../../../js/jquery.tag.inserter.js"></script>
<script src="../../jquery.setNameSpace.js"></script>
<script src="../../../tests/jquery.testHelper.js"></script>

<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
<link rel="stylesheet" href="../../jqm-tests.css"/>
<script src="../../../external/qunit/qunit.js"></script>

<script>
$.testHelper.asyncLoad([
[
"events/touch"
],
[ "init" ],
[
"binding_tests_core.js"
]
]);
</script>
<script src="../../swarminject.js"></script>
</head>
<body>
<div id="qunit"></div>

<div data-nstest-role="page" id="start-page">
<div class="ui-content" id="page-content"></div>
</div>
</body>
</html>
39 changes: 39 additions & 0 deletions tests/integration/swipe/binding_tests_core.js
@@ -0,0 +1,39 @@
test( "Unbinding swipeleft leaves swiperight handler alone", function() {
var dummy = function() {},
swipeLength = function() {
var swipe = $._data( document, "events" ).swipe;

return swipe ? swipe.length : 0;
},
initialSwipeLength = swipeLength();

$( document ).on( "swipeleft swiperight", ".ui-page", dummy );

deepEqual( swipeLength(), initialSwipeLength + 2,
"Two swipe handlers are present after attaching swipeleft and swiperight" );

$( document ).off( "swipeleft", ".ui-page", dummy );

deepEqual( swipeLength(), initialSwipeLength + 1,
"One swipe handler is present after detaching swipeleft" );

$( document ).on( "swipeleft", ".ui-page", dummy );

deepEqual( swipeLength(), initialSwipeLength + 2,
"Two swipe handlers are present after reattaching swipeleft" );

$( document ).off( "swiperight", ".ui-page", dummy );

deepEqual( swipeLength(), initialSwipeLength + 1,
"One swipe handler is present after detaching swiperight" );

$( document ).on( "swiperight", ".ui-page", dummy );

deepEqual( swipeLength(), initialSwipeLength + 2,
"Two swipe handlers are present after reattaching swiperight" );

$( document ).off( "swipeleft swiperight", ".ui-page", dummy );

deepEqual( swipeLength(), initialSwipeLength,
"No swipe handlers are present after detaching both swipeleft and swiperight" );
});

0 comments on commit 65e81c0

Please sign in to comment.