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
98 lines (80 loc) · 1.71 KB
/
dom.js
File metadata and controls
98 lines (80 loc) · 1.71 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
import { isRef } from 'vue'
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
for (const prop in css) {
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) {
if (el === void 0 || el === null) {
return void 0
}
if (typeof el === 'string') {
try {
return document.querySelector(el) || void 0
}
catch (err) {
return void 0
}
}
const target = isRef(el) === true
? el.value
: el
if (target) {
return target.$el || target
}
}
// internal
export function childHasFocus (el, focusedEl) {
if (el === void 0 || el === null || el.contains(focusedEl) === true) {
return true
}
for (let next = el.nextElementSibling; next !== null; next = next.nextElementSibling) {
if (next.contains(focusedEl)) {
return true
}
}
return false
}
export default {
offset,
style,
height,
width,
css,
cssBatch,
ready
}