Permalink
Browse files

Swipe: Do not process move if its default is prevented

(cherry picked from commit 0920b15)

Closes gh-7585
Fixes gh-7573
1 parent e23d56d commit a6aef45254f12874317cebc366834d28ea8fb0ed @gabrielschulhof gabrielschulhof committed Jul 23, 2014
Showing with 115 additions and 1 deletion.
  1. +1 −1 js/events/touch.js
  2. +41 −0 tests/unit/event/swipe-tests.html
  3. +73 −0 tests/unit/event/swipe_core.js
View
@@ -250,7 +250,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
emitted = false;
context.move = function( event ) {
- if ( !start ) {
+ if ( !start || event.isDefaultPrevented() ) {
return;
}
@@ -0,0 +1,41 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>jQuery Mobile 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>
+ <script type="text/javascript">
+ $.testHelper.setPushState();
+ </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",
+ ],
+ [
+ "swipe_core.js"
+ ]
+ ]);
+ </script>
+
+ <script src="../../swarminject.js"></script>
+</head>
+<body>
+
+ <div id="qunit"></div>
+
+</body>
+</html>
@@ -0,0 +1,73 @@
+asyncTest( "Swipe does not trigger when motion is default-prevented", function() {
+ var target = $( "#qunit" ),
+ swipeTriggered = false,
+ pointer = $.mobile.support.touch ?
+ { down: "touchstart", move: "touchmove", up: "touchend" } :
+ { down: "mousedown", move: "mousemove", up: "mouseup" };
+ recordSwipe = function() {
+ swipeTriggered = true;
+ };
+
+ target.one( "swipe", recordSwipe );
+
+ $.testHelper.sequence([
+ function() {
+ target.trigger( $.extend( $.Event( pointer.down ), {
+ originalEvent: {
+ touches: false
+ },
+ pageX: 206,
+ pageY: 190,
+ clientX: 206,
+ clientY: 190
+ }));
+ },
+ function() {
+ target.trigger( ( function( event ) {
+ event.preventDefault();
+ return event;
+ } )( $.extend( $.Event( pointer.move ), {
+ originalEvent: {
+ touches: false
+ },
+ pageX: 206,
+ pageY: 190,
+ clientX: 206,
+ clientY: 190
+ })));
+ },
+ function() {
+ target.trigger( ( function( event ) {
+ event.preventDefault();
+ return event;
+ } )( $.extend( $.Event( pointer.move ), {
+ originalEvent: {
+ touches: false
+ },
+ pageX: 170,
+ pageY: 190,
+ clientX: 170,
+ clientY: 190
+ })));
+ },
+ function() {
+ target.trigger( ( function( event ) {
+ event.preventDefault();
+ return event;
+ } )( $.extend( $.Event( pointer.up ), {
+ originalEvent: {
+ touches: false
+ },
+ pageX: 170,
+ pageY: 190,
+ clientX: 170,
+ clientY: 190
+ })));
+ },
+ function() {
+ deepEqual( swipeTriggered, false, "Swipe was not triggered" );
+ target.off( "swipe", recordSwipe );
+ start();
+ }
+ ], 100 );
+});

0 comments on commit a6aef45

Please sign in to comment.