forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom.js
More file actions
103 lines (84 loc) · 1.82 KB
/
dom.js
File metadata and controls
103 lines (84 loc) · 1.82 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
94
95
96
97
98
99
100
101
102
103
export function offset (el) {
if (el === window) {
return { top: 0, left: 0 }
}
const { top, left } = el.getBoundingClientRect()
return { top, left }
}
export function style (el, property) {
return window.getComputedStyle(el).getPropertyValue(property)
}
export function height (el) {
return el === window
? window.innerHeight
: el.getBoundingClientRect().height
}
export function width (el) {
return el === window
? window.innerWidth
: el.getBoundingClientRect().width
}
export function css (element, css) {
const style = element.style
Object.keys(css).forEach(prop => {
style[prop] = css[prop]
})
}
export function cssBatch (elements, style) {
elements.forEach(el => css(el, style))
}
export function ready (fn) {
if (typeof fn !== 'function') {
return
}
if (document.readyState !== 'loading') {
return fn()
}
document.addEventListener('DOMContentLoaded', fn, false)
}
// internal
export function getElement (el) {
const type = typeof el
if (type === 'function') {
el = el()
}
if (type === 'string') {
try {
el = document.querySelector(el)
}
catch (err) {}
}
if (el !== Object(el)) {
return null
}
return el._isVue === true && el.$el !== void 0
? el.$el
: el
}
// internal
export function childHasFocus (el, focusedEl) {
if (el === void 0 || el.contains(focusedEl) === true) {
return true
}
for (let next = el.nextElementSibling; next !== null; next = next.nextElementSibling) {
if (next.contains(focusedEl)) {
return true
}
}
return false
}
// internal
export function getBodyFullscreenElement (activeEl) {
return activeEl === document.documentElement || activeEl === null
? document.body
: activeEl
}
export default {
offset,
style,
height,
width,
css,
cssBatch,
ready
}