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

Swipe: Do not call preventDefault when without touch support #8671

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( 0 );

forceNoTouchSupport();

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

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

$( "#qunit-fixture" ).one( "mouseup", 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