UNPKG

985 BJavaScriptView Raw
1
2!function(Event, document) {
3 function touchMove(e) {
4 var touch = e.changedTouches[0]
5 , ev = document.createEvent("MouseEvent")
6 if (e.type === "touchmove") {
7 e.preventDefault()
8 }
9 ev.initMouseEvent(
10 e.type.replace("touch", "mouse").replace("start", "down").replace("end", "up"),
11 true, true, window, 1,
12 touch.screenX, touch.screenY, touch.clientX, touch.clientY,
13 false, false, false, false, 0, null)
14 touch.target.dispatchEvent(ev)
15 }
16
17 function touchStart(e) {
18 if (e.touches.length == 1) {
19 El.on(document, "touchend", touchEnd)
20 El.on(document, "touchcancel", touchEnd)
21 El.on(document, "touchmove", touchMove)
22 touchMove(e)
23 }
24 }
25
26 function touchEnd(e) {
27 El.off(document, "touchend", touchEnd)
28 El.off(document, "touchcancel", touchEnd)
29 El.off(document, "touchmove", touchMove)
30 touchMove(e)
31 }
32
33 Event.touchAsMouse = function(el) {
34 El.css(el, "touch-action", "manipulation")
35 El.on(el, "touchstart", touchStart)
36 }
37}(Event, document)
38
39