Bind touch handlers only when it's supported.

Fix #227.
This commit is contained in:
Hyunje Alex Jun 2014-10-21 21:06:16 +01:00
parent 664dec23d6
commit ee4fc96b7a

View File

@ -531,7 +531,7 @@
}); });
} }
function bindTouchHandler() { function bindTouchHandler(supportsTouch, supportsIePointer) {
function applyTouchMove(differenceX, differenceY) { function applyTouchMove(differenceX, differenceY) {
$this.scrollTop($this.scrollTop() - differenceY); $this.scrollTop($this.scrollTop() - differenceY);
$this.scrollLeft($this.scrollLeft() - differenceX); $this.scrollLeft($this.scrollLeft() - differenceX);
@ -613,24 +613,28 @@
}, 10); }, 10);
} }
$(window).bind("touchstart" + eventClassName, globalTouchStart); if (supportsTouch) {
$(window).bind("touchend" + eventClassName, globalTouchEnd); $(window).bind("touchstart" + eventClassName, globalTouchStart);
$this.bind("touchstart" + eventClassName, touchStart); $(window).bind("touchend" + eventClassName, globalTouchEnd);
$this.bind("touchmove" + eventClassName, touchMove); $this.bind("touchstart" + eventClassName, touchStart);
$this.bind("touchend" + eventClassName, touchEnd); $this.bind("touchmove" + eventClassName, touchMove);
$this.bind("touchend" + eventClassName, touchEnd);
}
if (window.PointerEvent) { if (supportsIePointer) {
$(window).bind("pointerdown" + eventClassName, globalTouchStart); if (window.PointerEvent) {
$(window).bind("pointerup" + eventClassName, globalTouchEnd); $(window).bind("pointerdown" + eventClassName, globalTouchStart);
$this.bind("pointerdown" + eventClassName, touchStart); $(window).bind("pointerup" + eventClassName, globalTouchEnd);
$this.bind("pointermove" + eventClassName, touchMove); $this.bind("pointerdown" + eventClassName, touchStart);
$this.bind("pointerup" + eventClassName, touchEnd); $this.bind("pointermove" + eventClassName, touchMove);
} else if (window.MSPointerEvent) { $this.bind("pointerup" + eventClassName, touchEnd);
$(window).bind("MSPointerDown" + eventClassName, globalTouchStart); } else if (window.MSPointerEvent) {
$(window).bind("MSPointerUp" + eventClassName, globalTouchEnd); $(window).bind("MSPointerDown" + eventClassName, globalTouchStart);
$this.bind("MSPointerDown" + eventClassName, touchStart); $(window).bind("MSPointerUp" + eventClassName, globalTouchEnd);
$this.bind("MSPointerMove" + eventClassName, touchMove); $this.bind("MSPointerDown" + eventClassName, touchStart);
$this.bind("MSPointerUp" + eventClassName, touchEnd); $this.bind("MSPointerMove" + eventClassName, touchMove);
$this.bind("MSPointerUp" + eventClassName, touchEnd);
}
} }
} }
@ -689,7 +693,7 @@
bindMouseWheelHandler(); bindMouseWheelHandler();
if (supportsTouch || supportsIePointer) { if (supportsTouch || supportsIePointer) {
bindTouchHandler(); bindTouchHandler(supportsTouch, supportsIePointer);
} }
if (settings.useKeyboard) { if (settings.useKeyboard) {
bindKeyboardHandler(); bindKeyboardHandler();