forked from furf/jquery-ui-touch-punch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.ui.touch-punch.js
executable file
·85 lines (63 loc) · 1.96 KB
/
jquery.ui.touch-punch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*!
* jQuery UI Touch Punch 0.1.0
*
* Copyright 2010, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function ($) {
$.support.touch = typeof Touch === 'object';
if (!$.support.touch) {
return;
}
var mouseProto = $.ui.mouse.prototype,
_mouseInit = mouseProto._mouseInit,
_mouseDown = mouseProto._mouseDown,
_mouseUp = mouseProto._mouseUp;
function makeMouseEvent (event, eventType) {
var touch = event.originalEvent.changedTouches[0];
return $.extend(event, {
type: eventType,
which: 1,
pageX: touch.pageX,
pageY: touch.pageY,
screenX: touch.screenX,
screenY: touch.screenY,
clientX: touch.clientX,
clientY: touch.clientY
});
}
mouseProto._mouseInit = function () {
var self = this;
self.element.bind('touchstart.' + self.widgetName, function (event) {
$(document).trigger("mousedown");
$(event.target).trigger(makeMouseEvent(event, "mouseover"));
return self._mouseDown(makeMouseEvent(event, "mousedown"));
});
_mouseInit.call(self);
};
mouseProto._mouseDown = function (event) {
var self = this,
ret = _mouseDown.call(self, event);
self._touchMoveDelegate = function (event) {
return self._mouseMove(makeMouseEvent(event, "mousemove"));
};
self._touchEndDelegate = function(event) {
return self._mouseUp(makeMouseEvent(event, "mouseup"));
};
$(document)
.bind('touchmove.' + self.widgetName, self._touchMoveDelegate)
.bind('touchend.' + self.widgetName, self._touchEndDelegate);
return ret;
};
mouseProto._mouseUp = function (event) {
var self = this;
$(document)
.unbind('touchmove.' + self.widgetName, self._touchMoveDelegate)
.unbind('touchend.' + self.widgetName, self._touchEndDelegate);
return _mouseUp.call(self, event);
};
})(jQuery);