Repository navigation
Expand file tree
/
Copy pathpqtouch.js
More file actions
93 lines (87 loc) · 3.18 KB
/
Copy pathpqtouch.js
File metadata and controls
93 lines (87 loc) · 3.18 KB
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
86
87
88
89
90
91
92
93
/*!
* ParamQuery Touch v1.1.0
*
* Copyright (c) 2012-2026 Paramvir Dhindsa (http://paramquery.com)
* Released under MIT license
*
*/
(function(factory) {
"use strict";
const root = typeof window !== 'undefined' ? window : globalThis;
if (typeof define === "function" && define.amd) {
// AMD
define(["jquery"], factory);
} else if (typeof module === "object" && module.exports) {
// CommonJS
const jQuery = require("jquery");
factory(jQuery);
module.exports = jQuery;
} else {
// Browser globals
if (root && root.jQuery) {
factory(root.jQuery);
} else {
throw new Error("jquery-ui-pack requires jQuery to be loaded first.");
}
}
})(function(jQuery) {
(function($) {
if (!("ontouchstart" in window)) return;
function fireMouseEvent(type, touch, target, relatedTarget) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent(type, true, true, window, 0, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, relatedTarget);
target.dispatchEvent(evt);
return evt
}
function touchStart(evt) {
if (evt.touches.length == 1) {
var touch = evt.changedTouches[0],
evtM, target = evt.target;
fireMouseEvent("mouseover", touch, target);
fireMouseEvent("mousemove", touch, target);
evtM = fireMouseEvent("mousedown", touch, target);
if (evtM.defaultPrevented) {
target.addEventListener("touchmove", touchMove);
target.addEventListener("touchend", touchEnd)
}
}
}
function touchMove(evt) {
var touch = evt.changedTouches[0],
target = document.elementFromPoint(touch.clientX, touch.clientY);
if (target) {
if (prevTarget) {
if (target && prevTarget !== target) {
fireMouseEvent("mouseover", touch, target, prevTarget);
fireMouseEvent("mouseout", touch, prevTarget, target);
prevTarget = target
}
} else {
prevTarget = target
}
evt.preventDefault();
fireMouseEvent("mousemove", touch, target)
}
}
function touchEnd(evt) {
var touch = evt.changedTouches[0],
target = document.elementFromPoint(touch.clientX, touch.clientY),
targetOrig = evt.target;
fireMouseEvent("mouseup", touch, target);
fireMouseEvent("mouseout", touch, target);
targetOrig.removeEventListener("touchmove", touchMove);
targetOrig.removeEventListener("touchend", touchEnd)
}
var prevTarget, proto = $.ui.mouse.prototype,
mouseInit = proto._mouseInit,
mouseDestroy = proto._mouseDestroy;
proto._mouseInit = function() {
this.element[0].addEventListener("touchstart", touchStart);
mouseInit.apply(this, arguments)
};
proto._mouseDestroy = function() {
this.element[0].removeEventListener("touchstart", touchStart);
mouseDestroy.apply(this, arguments)
}
})(jQuery);
});