Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing scrolling issue in Safari for iOS #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
77 changes: 42 additions & 35 deletions jquery.touchSwipe.js
Original file line number Diff line number Diff line change
@@ -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