Unified touch event callbacks

This commit is contained in:
Luis A. Leiva 2015-11-08 23:56:52 +01:00
parent c6fab5238e
commit 0b4988c9d3
1 changed files with 17 additions and 26 deletions

View File

@ -334,20 +334,29 @@
upHandler(e); upHandler(e);
}; };
/** function execTouchEvent(e, callback) {
* @private
*/
function touchdownHandler(e) {
var elem = $(e.target), data = elem.data(_ns), options = data.options; var elem = $(e.target), data = elem.data(_ns), options = data.options;
var touches = e.originalEvent.changedTouches; var touches = e.originalEvent.changedTouches;
if (options.multitouch) { if (options.multitouch) {
for (var i = 0; i < touches.length; i++) { for (var i = 0; i < touches.length; i++) {
var touch = touches[i]; var touch = touches[i];
downHandler(touch); // Add the type of event to the touch object.
touch.type = e.type;
callback(touch);
} }
} else { } 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(); e.preventDefault();
}; };
@ -355,16 +364,7 @@
* @private * @private
*/ */
function touchmoveHandler(e) { function touchmoveHandler(e) {
var elem = $(e.target), data = elem.data(_ns), options = data.options; execTouchEvent(e, moveHandler);
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]);
}
e.preventDefault(); e.preventDefault();
}; };
@ -372,16 +372,7 @@
* @private * @private
*/ */
function touchupHandler(e) { function touchupHandler(e) {
var elem = $(e.target), data = elem.data(_ns), options = data.options; execTouchEvent(e, upHandler);
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]);
}
e.preventDefault(); e.preventDefault();
}; };