diff --git a/js/events/touch.js b/js/events/touch.js index ef3aed9f220..9f03d87b85d 100644 --- a/js/events/touch.js +++ b/js/events/touch.js @@ -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(); } }; diff --git a/tests/unit/event/event_core.js b/tests/unit/event/event_core.js index 2c6f7d7ed57..8cf263990ec 100644 --- a/tests/unit/event/event_core.js +++ b/tests/unit/event/event_core.js @@ -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; @@ -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 = {