-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
59 lines (47 loc) · 1.63 KB
/
bootstrap.js
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
import * as bootstrap from "bootstrap";
export const initBootstrap = function (config) {
// Enabling tooltips
if (config.tooltip) {
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
}
// Enabling popovers
if (config.popover) {
const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl, {})
})
}
// Enabling toasts
if (config.toasts) {
const toastTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="toast"]'))
toastTriggerList.map(function (toastTriggerEl) {
// Define the target property
let toastTarget = null
if ("A" === toastTriggerEl.nodeName) {
toastTarget = toastTriggerEl.href || null
if (toastTarget.includes('#')) {
toastTarget = `#${toastTarget.split("#").pop()}`
} else {
return
}
} else if ("BUTTON" === toastTriggerEl.nodeName) {
toastTarget = toastTriggerEl.dataset.bsTarget || null
}
// Check if the target exists
const toastTargetEl = document.querySelector(toastTarget);
if (!toastTargetEl) {
return
}
// Init toast
const toast = new bootstrap.Toast(toastTargetEl)
// Add click even to trigger
toastTriggerEl.addEventListener("click", function (event) {
event.preventDefault();
toast.show()
})
})
}
}