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);
};
/**
* @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();
};