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

Commit deeb8b6

Browse files
committed
Swipe: Do not call preventDefault when without touch support
1 parent 4a6395d commit deeb8b6

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

js/events/touch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ $.event.special.swipe = {
246246
}
247247
}
248248
// prevent scrolling
249-
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
249+
if ( supportTouch && Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
250250
event.preventDefault();
251251
}
252252
};

tests/unit/event/event_core.js

+42
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ var forceTouchSupport = function() {
125125
} );
126126
};
127127

128+
var forceNoTouchSupport = function() {
129+
$.mobile.support.touch = false;
130+
$.each( components, function( index, value ) {
131+
$.testHelper.reloadLib( value );
132+
} );
133+
};
134+
128135
QUnit.asyncTest( "long press fires tap hold after taphold duration", function( assert ) {
129136
var taphold = false,
130137
target;
@@ -477,6 +484,41 @@ QUnit.asyncTest( "scrolling prevented when coordinate change > 10", function( as
477484
$( "#qunit-fixture" ).trigger( "touchmove" );
478485
} );
479486

487+
QUnit.asyncTest( "mouse action not prevented when coordinate change > 10", function( assert ) {
488+
assert.expect( 1 );
489+
490+
forceNoTouchSupport();
491+
492+
// Ensure the swipe custome event is setup
493+
$( "#qunit-fixture" ).bind( "swipe", function() {} );
494+
495+
$.Event.prototype.preventDefault = function() {
496+
assert.ok( false, "prevent default called" );
497+
};
498+
499+
$( "#qunit-fixture" ).one( "mouseup", function() {
500+
QUnit.start();
501+
} );
502+
503+
// NOTE bypass the trigger source check
504+
$.testHelper.mockOriginalEvent( {
505+
clientX: 0,
506+
clientY: 0
507+
} );
508+
509+
$( "#qunit-fixture" ).trigger( "mousedown" );
510+
511+
// NOTE bypass the trigger source check
512+
$.testHelper.mockOriginalEvent( {
513+
clientX: 200,
514+
clientY: 0
515+
} );
516+
517+
$( "#qunit-fixture" ).trigger( "mousemove" );
518+
519+
$( "#qunit-fixture" ).trigger( "mouseup" );
520+
} );
521+
480522
QUnit.test( "Swipe get cords returns proper values", function( assert ) {
481523
var location,
482524
event = {

0 commit comments

Comments
 (0)