From 0b4988c9d35eb61d40e2aa3dce4f918ec20734df Mon Sep 17 00:00:00 2001 From: "Luis A. Leiva" Date: Sun, 8 Nov 2015 23:56:52 +0100 Subject: [PATCH] Unified touch event callbacks --- jquery.sketchable.js | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/jquery.sketchable.js b/jquery.sketchable.js index 2bf97ef..392ed6d 100644 --- a/jquery.sketchable.js +++ b/jquery.sketchable.js @@ -334,20 +334,29 @@ upHandler(e); }; - /** - * @private - */ - function touchdownHandler(e) { + function execTouchEvent(e, callback) { var elem = $(e.target), data = elem.data(_ns), options = data.options; var touches = e.originalEvent.changedTouches; if (options.multitouch) { for (var i = 0; i < touches.length; i++) { var touch = touches[i]; - downHandler(touch); + // Add the type of event to the touch object. + touch.type = e.type; + callback(touch); } } else { - downHandler(touches[0]); + var touch = touches[0]; + // Add the type of event to the touch object. + touch.type = e.type; + callback(touch); } + }; + + /** + * @private + */ + function touchdownHandler(e) { + execTouchEvent(e, downHandler); e.preventDefault(); }; @@ -355,16 +364,7 @@ * @private */ function touchmoveHandler(e) { - var elem = $(e.target), data = elem.data(_ns), options = data.options; - var touches = e.originalEvent.changedTouches; - if (options.multitouch) { - for (var i = 0; i < touches.length; i++) { - var touch = touches[i]; - moveHandler(touch); - } - } else { - moveHandler(touches[0]); - } + execTouchEvent(e, moveHandler); e.preventDefault(); }; @@ -372,16 +372,7 @@ * @private */ function touchupHandler(e) { - var elem = $(e.target), data = elem.data(_ns), options = data.options; - var touches = e.originalEvent.changedTouches; - if (options.multitouch) { - for (var i = 0; i < touches.length; i++) { - var touch = touches[i]; - upHandler(touch); - } - } else { - upHandler(touches[0]); - } + execTouchEvent(e, upHandler); e.preventDefault(); };