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

Commit

Permalink
Swipe: Do not call preventDefault when without touch support
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Jul 22, 2021
1 parent 4a6395d commit d85dc2d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/events/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ $.event.special.swipe = {
}
}
// prevent scrolling
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
if ( supportTouch && Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
event.preventDefault();
}
};
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/event/event_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ var forceTouchSupport = function() {
} );
};

var forceNoTouchSupport = function() {
$.mobile.support.touch = false;
$.each( components, function( index, value ) {
$.testHelper.reloadLib( value );
} );
};

QUnit.asyncTest( "long press fires tap hold after taphold duration", function( assert ) {
var taphold = false,
target;
Expand Down Expand Up @@ -477,6 +484,41 @@ QUnit.asyncTest( "scrolling prevented when coordinate change > 10", function( as
$( "#qunit-fixture" ).trigger( "touchmove" );
} );

QUnit.asyncTest( "mouse action not prevented when coordinate change > 10", function( assert ) {
assert.expect( 1 );

forceNoTouchSupport();

// Ensure the swipe custome event is setup
$( "#qunit-fixture" ).bind( "swipe", function() {} );

$.Event.prototype.preventDefault = function() {
assert.ok( false, "prevent default called" );
};

qunitFixture.one( "swipe", function() {
QUnit.start();
} );

// NOTE bypass the trigger source check
$.testHelper.mockOriginalEvent( {
clientX: 0,
clientY: 0
} );

$( "#qunit-fixture" ).trigger( "mousedown" );

// NOTE bypass the trigger source check
$.testHelper.mockOriginalEvent( {
clientX: 200,
clientY: 0
} );

$( "#qunit-fixture" ).trigger( "mousemove" );

$( "#qunit-fixture" ).trigger( "mouseup" );
} );

QUnit.test( "Swipe get cords returns proper values", function( assert ) {
var location,
event = {
Expand Down

0 comments on commit d85dc2d

Please sign in to comment.