Skip to content

Commit

Permalink
Fixing scrolling issue in Safari for iOS
Browse files Browse the repository at this point in the history
Implemented fix proposed in mattbryson#326 .
Works like a charm, thx @breville !

¡¡¡¡ Further work required !!!!
====================
* test on other mobile browsers (Android)
* update minified file as well
  • Loading branch information
Sebastian Keller committed Oct 4, 2017
1 parent 4cc4c4f commit ab9cd1e
Showing 1 changed file with 42 additions and 35 deletions.
77 changes: 42 additions & 35 deletions jquery.touchSwipe.js
@@ -1,6 +1,6 @@
/*!
* @fileOverview TouchSwipe - jQuery Plugin
* @version 1.6.18
* @version 1.6.19
*
* @author Matt Bryson http://www.github.com/mattbryson
* @see https://github.com/mattbryson/TouchSwipe-Jquery-Plugin
Expand Down Expand Up @@ -124,10 +124,13 @@
* $Date: 2016-04-29 (Fri, 29 April 2016) $
* $version 1.6.16 - Swipes with 0 distance now allow default events to trigger. So tapping any form elements or A tags will allow default interaction, but swiping will trigger a swipe.
Removed the a, input, select etc from the excluded Children list as the 0 distance tap solves that issue.
* $Date: 2016-05-19 (Fri, 29 April 2016) $
* $version 1.6.17 - Fixed context issue when calling instance methods via $("selector").swipe("method");
* $version 1.6.18 - now honors fallbackToMouseEvents=false for MS Pointer events when a Mouse is used.
* $Date: 2016-05-19 (Fri, 29 April 2016) $
* $version 1.6.17 - Fixed context issue when calling instance methods via $("selector").swipe("method");
* $version 1.6.18 - now honors fallbackToMouseEvents=false for MS Pointer events when a Mouse is used.
* $Date: 2017-10-04 (Wed, 04 October 2017) $
* $version 1.6.19 - fixed scrolling issue in Safari for iOS
*/

/**
Expand Down Expand Up @@ -504,13 +507,7 @@
var singleTapTimeout = null,
holdTimeout = null;

// Add gestures to all swipable areas if supported
try {
$element.bind(START_EV, touchStart);
$element.bind(CANCEL_EV, touchCancel);
} catch (e) {
$.error('events not supported ' + START_EV + ',' + CANCEL_EV + ' on jQuery.swipe');
}
addListeners();

//
//Public methods
Expand All @@ -526,8 +523,7 @@
this.enable = function() {
//Incase we are already enabled, clean up...
this.disable();
$element.bind(START_EV, touchStart);
$element.bind(CANCEL_EV, touchCancel);
addListeners();
return $element;
};

Expand Down Expand Up @@ -711,7 +707,10 @@
* @param {object} jqEvent The normalised jQuery event object.
*/
function touchMove(jqEvent) {

//instanciate all event handler at init, so check if we shall fire
if(!getTouchInProgress()){
return;
}
//As we use Jquery bind for events, we need to target the original event object
//If these events are being programmatically triggered, we don't have an original event object, so use the Jq one.
var event = jqEvent.originalEvent ? jqEvent.originalEvent : jqEvent;
Expand Down Expand Up @@ -828,6 +827,10 @@
* @param {object} jqEvent The normalised jQuery event object.
*/
function touchEnd(jqEvent) {
//instanciate all event handler at init, so check if we shall fire
if(!getTouchInProgress()){
return;
}
//As we use Jquery bind for events, we need to target the original event object
//If these events are being programmatically triggered, we don't have an original event object, so use the Jq one.
var event = jqEvent.originalEvent ? jqEvent.originalEvent : jqEvent,
Expand Down Expand Up @@ -915,6 +918,10 @@
* @inner
*/
function touchLeave(jqEvent) {
//instanciate all event handler at init, so check if we shall fire
if(!getTouchInProgress()){
return;
}
//If these events are being programmatically triggered, we don't have an original event object, so use the Jq one.
var event = jqEvent.originalEvent ? jqEvent.originalEvent : jqEvent;

Expand All @@ -925,6 +932,26 @@
}
}

/**
* Adds all listeners to all swipable areas if supported
* @inner
*/
function addListeners(){
try {
$element.bind(START_EV, touchStart);
$element.bind(CANCEL_EV, touchCancel);
$element.bind(MOVE_EV, touchMove);
$element.bind(END_EV, touchEnd);

//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if (LEAVE_EV) {
$element.bind(LEAVE_EV, touchLeave);
}
} catch (e) {
$.error('events not supported ' + START_EV + ',' + CANCEL_EV + ',' + MOVE_EV + ',' + END_EV + (LEAVE_EV?',' + LEAVE_EV:'') + ' on jQuery.swipe');
}
}

/**
* Removes all listeners that were associated with the plugin
* @inner
Expand Down Expand Up @@ -1581,6 +1608,7 @@
* @inner
*/
function getTouchInProgress() {
if(!$element) { return false; }
//strict equality to ensure only true and false are returned
return !!($element.data(PLUGIN_NS + '_intouch') === true);
}
Expand All @@ -1595,27 +1623,6 @@
//If destroy is called in an event handler, we have no el, and we have already cleaned up, so return.
if(!$element) { return; }

//Add or remove event listeners depending on touch status
if (val === true) {
$element.bind(MOVE_EV, touchMove);
$element.bind(END_EV, touchEnd);

//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if (LEAVE_EV) {
$element.bind(LEAVE_EV, touchLeave);
}
} else {

$element.unbind(MOVE_EV, touchMove, false);
$element.unbind(END_EV, touchEnd, false);

//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if (LEAVE_EV) {
$element.unbind(LEAVE_EV, touchLeave, false);
}
}


//strict equality to ensure only true and false can update the value
$element.data(PLUGIN_NS + '_intouch', val === true);
}
Expand Down

0 comments on commit ab9cd1e

Please sign in to comment.