From 8e6aaa72b4b85beb787bd7c8b227f9eef19008ef Mon Sep 17 00:00:00 2001 From: Ivan Tivonenko Date: Wed, 29 Oct 2014 22:12:27 +0200 Subject: [PATCH 1/2] clear state variable after touch ended --- src/toe.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/toe.js b/src/toe.js index 597def8..cc1d124 100644 --- a/src/toe.js +++ b/src/toe.js @@ -249,6 +249,8 @@ state.end = end; loopHandler('touchend', event, state, end); + + state = null; } touch.on(); From bfe036c016cfa545224e2123802e24ac1b1dbf45 Mon Sep 17 00:00:00 2001 From: Ivan Tivonenko Date: Wed, 29 Oct 2014 22:42:10 +0200 Subject: [PATCH 2/2] react only on IE pointer events that come from touch --- src/toe.js | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/src/toe.js b/src/toe.js index cc1d124..14ff5b0 100644 --- a/src/toe.js +++ b/src/toe.js @@ -6,6 +6,19 @@ */ (function ($, window, undefined) { + var INPUT_TYPE_TOUCH = 'touch'; + var INPUT_TYPE_PEN = 'pen'; + var INPUT_TYPE_MOUSE = 'mouse'; + var INPUT_TYPE_KINECT = 'kinect'; + + // in IE10 the pointer types is defined as an enum + var IE10_POINTER_TYPE_ENUM = { + 2: INPUT_TYPE_TOUCH, + 3: INPUT_TYPE_PEN, + 4: INPUT_TYPE_MOUSE, + 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816 + }; + var state, gestures = {}, isTouch = 'ontouchstart' in window, @@ -22,9 +35,12 @@ * will implicitly be called when including */ on: function () { - $(document).on('touchstart MSPointerDown pointerdown', touchstart) - .on('touchmove MSPointerMove MSPointerHover pointermove', touchmove) - .on('touchend touchcancel MSPointerUp MSPointerCancel pointerup pointercancel', touchend); + $(document).on('touchstart', touchstart) + .on('MSPointerDown pointerdown', pointerstart) + .on('touchmove', touchmove) + .on('MSPointerMove MSPointerHover pointermove', pointermove) + .on('touchend touchcancel', touchend) + .on('MSPointerUp MSPointerCancel pointerup pointercancel', pointerend); touch.active = true; }, @@ -216,6 +232,47 @@ }); } + + /** + * @private + * @param {Object} event + */ + function pointerEventIsTouch(event) { + var pointerType = IE10_POINTER_TYPE_ENUM[event.originalEvent.pointerType] || event.originalEvent.pointerType; + return pointerType === 'touch'; + } + + /** + * @private + * @param {Object} event + */ + function pointerstart(event) { + if (pointerEventIsTouch(event)) { + touchstart(event); + } + } + + /** + * @private + * @param {Object} event + */ + function pointermove(event) { + if (pointerEventIsTouch(event)) { + touchmove(event); + } + } + + /** + * @private + * @param {Object} event + */ + function pointerend(event) { + if (pointerEventIsTouch(event)) { + touchend(event); + } + } + + /** * @private * @param {Object} event