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

Commit 65e81c0

Browse files
author
Gabriel Schulhof
committed
Swipe: Keep swiperight when tearing down swipeleft and vice versa
(cherry picked from commit 0eba6e4) Closes gh-7353 Fixes gh-7351
1 parent bf06f5e commit 65e81c0

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

js/events/touch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
313313
$.each({
314314
scrollstop: "scrollstart",
315315
taphold: "tap",
316-
swipeleft: "swipe",
317-
swiperight: "swipe"
316+
swipeleft: "swipe.left",
317+
swiperight: "swipe.right"
318318
}, function( event, sourceEvent ) {
319319

320320
$.event.special[ event ] = {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Swipe Event Test Suite</title>
7+
8+
<script src="../../../external/requirejs/require.js"></script>
9+
<script src="../../../js/requirejs.config.js"></script>
10+
<script src="../../../js/jquery.tag.inserter.js"></script>
11+
<script src="../../jquery.setNameSpace.js"></script>
12+
<script src="../../../tests/jquery.testHelper.js"></script>
13+
14+
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
15+
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
16+
<link rel="stylesheet" href="../../jqm-tests.css"/>
17+
<script src="../../../external/qunit/qunit.js"></script>
18+
19+
<script>
20+
$.testHelper.asyncLoad([
21+
[
22+
"events/touch"
23+
],
24+
[ "init" ],
25+
[
26+
"binding_tests_core.js"
27+
]
28+
]);
29+
</script>
30+
<script src="../../swarminject.js"></script>
31+
</head>
32+
<body>
33+
<div id="qunit"></div>
34+
35+
<div data-nstest-role="page" id="start-page">
36+
<div class="ui-content" id="page-content"></div>
37+
</div>
38+
</body>
39+
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
test( "Unbinding swipeleft leaves swiperight handler alone", function() {
2+
var dummy = function() {},
3+
swipeLength = function() {
4+
var swipe = $._data( document, "events" ).swipe;
5+
6+
return swipe ? swipe.length : 0;
7+
},
8+
initialSwipeLength = swipeLength();
9+
10+
$( document ).on( "swipeleft swiperight", ".ui-page", dummy );
11+
12+
deepEqual( swipeLength(), initialSwipeLength + 2,
13+
"Two swipe handlers are present after attaching swipeleft and swiperight" );
14+
15+
$( document ).off( "swipeleft", ".ui-page", dummy );
16+
17+
deepEqual( swipeLength(), initialSwipeLength + 1,
18+
"One swipe handler is present after detaching swipeleft" );
19+
20+
$( document ).on( "swipeleft", ".ui-page", dummy );
21+
22+
deepEqual( swipeLength(), initialSwipeLength + 2,
23+
"Two swipe handlers are present after reattaching swipeleft" );
24+
25+
$( document ).off( "swiperight", ".ui-page", dummy );
26+
27+
deepEqual( swipeLength(), initialSwipeLength + 1,
28+
"One swipe handler is present after detaching swiperight" );
29+
30+
$( document ).on( "swiperight", ".ui-page", dummy );
31+
32+
deepEqual( swipeLength(), initialSwipeLength + 2,
33+
"Two swipe handlers are present after reattaching swiperight" );
34+
35+
$( document ).off( "swipeleft swiperight", ".ui-page", dummy );
36+
37+
deepEqual( swipeLength(), initialSwipeLength,
38+
"No swipe handlers are present after detaching both swipeleft and swiperight" );
39+
});

0 commit comments

Comments
 (0)