Skip to content

Fixes Windows Swiping #355

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

Open
wants to merge 7 commits into
base: master
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 demos/Basic_swipe.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<script type="text/javascript" src="../jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="../jquery.touchSwipe.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>

<title>touchSwipe</title>
Expand Down
42 changes: 12 additions & 30 deletions jquery.touchSwipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@
PHASE_END = "end",
PHASE_CANCEL = "cancel",

SUPPORTS_TOUCH = 'ontouchstart' in window,

SUPPORTS_TOUCH = ('ontouchstart' in document),
SUPPORTS_POINTER_IE10 = window.navigator.msPointerEnabled && !window.PointerEvent && !SUPPORTS_TOUCH,

SUPPORTS_POINTER = (window.PointerEvent || window.navigator.msPointerEnabled) && !SUPPORTS_TOUCH,
SUPPORTS_POINTER = ('onpointerdown' in window || window.PointerEvent || window.navigator.msPointerEnabled) && !SUPPORTS_TOUCH,

PLUGIN_NS = 'TouchSwipe';

Expand Down Expand Up @@ -458,13 +458,13 @@
//take a local/instacne level copy of the options - should make it this.options really...
var options = $.extend({}, options);


var useTouchEvents = (SUPPORTS_TOUCH || SUPPORTS_POINTER || !options.fallbackToMouseEvents),
START_EV = useTouchEvents ? (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerDown' : 'pointerdown') : 'touchstart') : 'mousedown',
MOVE_EV = useTouchEvents ? (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerMove' : 'pointermove') : 'touchmove') : 'mousemove',
END_EV = useTouchEvents ? (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerUp' : 'pointerup') : 'touchend') : 'mouseup',
LEAVE_EV = useTouchEvents ? (SUPPORTS_POINTER ? 'mouseleave' : null) : 'mouseleave', //we manually detect leave on touch devices, so null event here
CANCEL_EV = (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerCancel' : 'pointercancel') : 'touchcancel');

START_EV = useTouchEvents ? (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerDown' : 'pointerdown') : 'touchstart') : 'mousedown',
MOVE_EV = useTouchEvents ? (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerMove' : 'pointermove') : 'touchmove') : 'mousemove',
END_EV = useTouchEvents ? (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerUp' : 'pointerup touchend') : 'touchend') : 'mouseup',
LEAVE_EV = useTouchEvents ? (SUPPORTS_POINTER ? 'mouseleave' : 'pointerleave') : 'mouseleave', //we manually detect leave on touch devices, so null event here
CANCEL_EV = (SUPPORTS_POINTER ? (SUPPORTS_POINTER_IE10 ? 'MSPointerCancel' : 'pointercancel') : 'touchcancel');


//touch properties
Expand Down Expand Up @@ -1598,24 +1598,16 @@
//Add or remove event listeners depending on touch status
if (val === true) {
$element.on(MOVE_EV, touchMove);
$element.on(END_EV, touchEnd);
$element.one(END_EV, function(e) { touchEnd(e); });

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

$element.off(MOVE_EV, touchMove, false);
$element.off(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.off(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 Expand Up @@ -1873,17 +1865,7 @@
* @param {DomNode} The DOM node to get the bounds for.
*/
function getbounds(el) {
el = $(el);
var offset = el.offset();

var bounds = {
left: offset.left,
right: offset.left + el.outerWidth(),
top: offset.top,
bottom: offset.top + el.outerHeight()
}

return bounds;
return el.getBoundingClientRect();
}


Expand Down
Loading