-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdom.js
More file actions
76 lines (67 loc) · 2.41 KB
/
dom.js
File metadata and controls
76 lines (67 loc) · 2.41 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
import * as functions from 'helpers/functions'
export function waitForElement (selector, callback, waitTime = 100) {
const el = document.querySelector(selector)
if (el) {
callback(el)
} else {
setTimeout(() => waitForElement(selector, callback, waitTime), waitTime)
}
}
export function showElements (selectors) {
selectors = Array.isArray(selectors) ? selectors : [selectors]
selectors.forEach(selector => {
const elements = document.querySelectorAll(selector)
elements.forEach(element => { element.classList.remove('hidden'); element.classList.add('show') })
})
}
export function hideElements (selectors) {
selectors = Array.isArray(selectors) ? selectors : [selectors]
selectors.forEach(selector => {
const elements = document.querySelectorAll(selector)
elements.forEach(element => { element.classList.add('hidden'); element.classList.remove('show') })
})
}
export function deleteElements(selectors) {
selectors = Array.isArray(selectors) ? selectors : [selectors]
selectors.forEach(selector => {
const elements = document.querySelectorAll(selector)
elements.forEach(element => { element.remove() })
})
}
// available animations: http://michalsnik.github.io/aos/
export function animateElement (selector, effect = 'fade-in', delay = 0) {
functions.e(selector, e => {
e.classList.remove('aos-animate')
e.setAttribute('data-aos', effect)
e.setAttribute('data-aos-delay', delay)
e.classList.remove('hidden')
window.AOS.refreshHard()
})
}
// initialize bs5 tooltips
export function initTooltips (root = document) {
if (!functions.isTouchDevice()) {
root.querySelectorAll('[data-toggle="tooltip"]').forEach(element => {
if (typeof bootstrap !== 'undefined') {
let tooltip = bootstrap.Tooltip.getInstance(element)
if (tooltip) tooltip.dispose()
return new window.bootstrap.Tooltip(element)
}
})
}
}
export function closeTooltips (root = document) {
root.querySelectorAll('[data-toggle="tooltip"]').forEach(e => {
const tooltip = bootstrap.Tooltip.getInstance(e)
if (tooltip) tooltip.dispose()
})
}
export function scrollToId(elementId) {
const element = document.getElementById(elementId)
if (element) {
element.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
}
export function isInputElement(target) {
return target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT'
}