forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.js
More file actions
66 lines (54 loc) · 1.19 KB
/
event.js
File metadata and controls
66 lines (54 loc) · 1.19 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
function getEvent (e) {
return !e ? window.event : e
}
export function rightClick (e) {
e = getEvent(e)
if (e.which) {
return e.which == 3 // eslint-disable-line
}
if (e.button) {
return e.button == 2 // eslint-disable-line
}
return false
}
export function position (e) {
let posx, posy
e = getEvent(e)
if (e.touches && e.touches[0]) {
e = e.touches[0]
}
else if (e.changedTouches && e.changedTouches[0]) {
e = e.changedTouches[0]
}
if (e.clientX || e.clientY) {
posx = e.clientX
posy = e.clientY
}
else if (e.pageX || e.pageY) {
posx = e.pageX - document.body.scrollLeft - document.documentElement.scrollLeft
posy = e.pageY - document.body.scrollTop - document.documentElement.scrollTop
}
return {
top: posy,
left: posx
}
}
export function targetElement (e) {
let target
e = getEvent(e)
if (e.target) {
target = e.target
}
else if (e.srcElement) {
target = e.srcElement
}
// defeat Safari bug
if (target.nodeType === 3) {
target = target.parentNode
}
return target
}
export function getMouseWheelDirection (e) {
e = getEvent(e)
return Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)))
}