2019-02-23 00:37:55 +02:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2021-09-07 18:37:44 +03:00
|
|
|
* Bootstrap (v5.1.1): util/index.js
|
2020-06-16 21:41:47 +03:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
2019-02-23 00:37:55 +02:00
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
const MAX_UID = 1000000
|
|
|
|
const MILLISECONDS_MULTIPLIER = 1000
|
|
|
|
const TRANSITION_END = 'transitionend'
|
|
|
|
|
|
|
|
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
2020-03-18 12:10:55 +01:00
|
|
|
const toType = obj => {
|
|
|
|
if (obj === null || obj === undefined) {
|
|
|
|
return `${obj}`
|
|
|
|
}
|
|
|
|
|
|
|
|
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
|
|
|
|
}
|
2019-02-23 00:37:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
* Public Util Api
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2019-02-26 13:20:34 +02:00
|
|
|
const getUID = prefix => {
|
2019-02-23 00:37:55 +02:00
|
|
|
do {
|
2020-05-14 09:46:42 +03:00
|
|
|
prefix += Math.floor(Math.random() * MAX_UID)
|
2019-02-23 00:37:55 +02:00
|
|
|
} while (document.getElementById(prefix))
|
2019-02-26 13:20:34 +02:00
|
|
|
|
2019-02-23 00:37:55 +02:00
|
|
|
return prefix
|
|
|
|
}
|
|
|
|
|
2019-07-23 21:15:00 +02:00
|
|
|
const getSelector = element => {
|
2020-07-22 22:33:11 +03:00
|
|
|
let selector = element.getAttribute('data-bs-target')
|
2019-02-23 00:37:55 +02:00
|
|
|
|
|
|
|
if (!selector || selector === '#') {
|
2021-02-03 20:58:54 +01:00
|
|
|
let hrefAttr = element.getAttribute('href')
|
|
|
|
|
|
|
|
// The only valid content that could double as a selector are IDs or classes,
|
|
|
|
// so everything starting with `#` or `.`. If a "real" URL is used as the selector,
|
|
|
|
// `document.querySelector` will rightfully complain it is invalid.
|
|
|
|
// See https://github.com/twbs/bootstrap/issues/32273
|
|
|
|
if (!hrefAttr || (!hrefAttr.includes('#') && !hrefAttr.startsWith('.'))) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just in case some CMS puts out a full URL with the anchor appended
|
|
|
|
if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
|
2021-03-30 11:27:05 +05:30
|
|
|
hrefAttr = `#${hrefAttr.split('#')[1]}`
|
2021-02-03 20:58:54 +01:00
|
|
|
}
|
2019-02-23 00:37:55 +02:00
|
|
|
|
2019-07-23 21:15:00 +02:00
|
|
|
selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|
|
|
|
|
2019-07-23 21:15:00 +02:00
|
|
|
return selector
|
|
|
|
}
|
|
|
|
|
|
|
|
const getSelectorFromElement = element => {
|
|
|
|
const selector = getSelector(element)
|
|
|
|
|
|
|
|
if (selector) {
|
2019-02-23 00:37:55 +02:00
|
|
|
return document.querySelector(selector) ? selector : null
|
|
|
|
}
|
2019-07-23 21:15:00 +02:00
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
const getElementFromSelector = element => {
|
|
|
|
const selector = getSelector(element)
|
|
|
|
|
|
|
|
return selector ? document.querySelector(selector) : null
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 13:20:34 +02:00
|
|
|
const getTransitionDurationFromElement = element => {
|
2019-02-23 00:37:55 +02:00
|
|
|
if (!element) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get transition-duration of the element
|
2020-12-02 06:45:15 +02:00
|
|
|
let { transitionDuration, transitionDelay } = window.getComputedStyle(element)
|
2019-02-23 00:37:55 +02:00
|
|
|
|
2020-05-02 16:49:33 +03:00
|
|
|
const floatTransitionDuration = Number.parseFloat(transitionDuration)
|
|
|
|
const floatTransitionDelay = Number.parseFloat(transitionDelay)
|
2019-02-23 00:37:55 +02:00
|
|
|
|
|
|
|
// Return 0 if element or transition duration is not found
|
|
|
|
if (!floatTransitionDuration && !floatTransitionDelay) {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
// If multiple durations are defined, take the first
|
|
|
|
transitionDuration = transitionDuration.split(',')[0]
|
|
|
|
transitionDelay = transitionDelay.split(',')[0]
|
|
|
|
|
2020-05-02 16:49:33 +03:00
|
|
|
return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 13:20:34 +02:00
|
|
|
const triggerTransitionEnd = element => {
|
2020-03-09 14:34:07 +01:00
|
|
|
element.dispatchEvent(new Event(TRANSITION_END))
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 18:17:20 +03:00
|
|
|
const isElement = obj => {
|
|
|
|
if (!obj || typeof obj !== 'object') {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof obj.jquery !== 'undefined') {
|
|
|
|
obj = obj[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
return typeof obj.nodeType !== 'undefined'
|
|
|
|
}
|
|
|
|
|
|
|
|
const getElement = obj => {
|
|
|
|
if (isElement(obj)) { // it's a jQuery object or a node element
|
|
|
|
return obj.jquery ? obj[0] : obj
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof obj === 'string' && obj.length > 0) {
|
2021-07-14 09:08:10 +03:00
|
|
|
return document.querySelector(obj)
|
2021-05-13 18:17:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
2019-02-23 00:37:55 +02:00
|
|
|
|
|
|
|
const typeCheckConfig = (componentName, config, configTypes) => {
|
2020-06-10 18:40:52 +03:00
|
|
|
Object.keys(configTypes).forEach(property => {
|
|
|
|
const expectedTypes = configTypes[property]
|
|
|
|
const value = config[property]
|
2021-01-14 01:43:30 +05:30
|
|
|
const valueType = value && isElement(value) ? 'element' : toType(value)
|
2020-06-10 18:40:52 +03:00
|
|
|
|
|
|
|
if (!new RegExp(expectedTypes).test(valueType)) {
|
2021-01-14 01:43:30 +05:30
|
|
|
throw new TypeError(
|
2021-03-30 11:27:05 +05:30
|
|
|
`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`
|
2021-01-14 01:43:30 +05:30
|
|
|
)
|
2020-06-10 18:40:52 +03:00
|
|
|
}
|
|
|
|
})
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 13:20:34 +02:00
|
|
|
const isVisible = element => {
|
2021-05-20 09:50:53 -04:00
|
|
|
if (!isElement(element) || element.getClientRects().length === 0) {
|
2019-02-23 00:37:55 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-05-20 09:50:53 -04:00
|
|
|
return getComputedStyle(element).getPropertyValue('visibility') === 'visible'
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|
|
|
|
|
2021-03-16 18:35:03 +02:00
|
|
|
const isDisabled = element => {
|
|
|
|
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element.classList.contains('disabled')) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof element.disabled !== 'undefined') {
|
|
|
|
return element.disabled
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:44:15 +02:00
|
|
|
return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false'
|
2021-03-16 18:35:03 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 13:20:34 +02:00
|
|
|
const findShadowRoot = element => {
|
2019-02-23 00:37:55 +02:00
|
|
|
if (!document.documentElement.attachShadow) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can find the shadow root otherwise it'll return the document
|
|
|
|
if (typeof element.getRootNode === 'function') {
|
|
|
|
const root = element.getRootNode()
|
|
|
|
return root instanceof ShadowRoot ? root : null
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element instanceof ShadowRoot) {
|
|
|
|
return element
|
|
|
|
}
|
|
|
|
|
|
|
|
// when we don't find a shadow root
|
|
|
|
if (!element.parentNode) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return findShadowRoot(element.parentNode)
|
|
|
|
}
|
|
|
|
|
2021-03-27 21:38:45 +05:30
|
|
|
const noop = () => {}
|
2019-02-23 00:37:55 +02:00
|
|
|
|
2021-07-20 17:20:43 +03:00
|
|
|
/**
|
|
|
|
* Trick to restart an element's animation
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} element
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
|
|
|
|
*/
|
|
|
|
const reflow = element => {
|
|
|
|
// eslint-disable-next-line no-unused-expressions
|
|
|
|
element.offsetHeight
|
|
|
|
}
|
2019-02-23 00:37:55 +02:00
|
|
|
|
2019-08-02 15:51:05 +02:00
|
|
|
const getjQuery = () => {
|
|
|
|
const { jQuery } = window
|
|
|
|
|
2020-07-22 22:33:11 +03:00
|
|
|
if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
|
2019-08-02 15:51:05 +02:00
|
|
|
return jQuery
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-06-22 19:19:55 +02:00
|
|
|
const DOMContentLoadedCallbacks = []
|
|
|
|
|
2020-11-01 14:32:36 +01:00
|
|
|
const onDOMContentLoaded = callback => {
|
|
|
|
if (document.readyState === 'loading') {
|
2021-06-22 19:19:55 +02:00
|
|
|
// add listener on the first call when the document is in loading state
|
|
|
|
if (!DOMContentLoadedCallbacks.length) {
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
DOMContentLoadedCallbacks.forEach(callback => callback())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
DOMContentLoadedCallbacks.push(callback)
|
2020-11-01 14:32:36 +01:00
|
|
|
} else {
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 10:14:05 +02:00
|
|
|
const isRTL = () => document.documentElement.dir === 'rtl'
|
2020-06-26 17:06:20 +03:00
|
|
|
|
2021-05-11 10:49:30 +03:00
|
|
|
const defineJQueryPlugin = plugin => {
|
2020-12-08 07:16:50 +01:00
|
|
|
onDOMContentLoaded(() => {
|
|
|
|
const $ = getjQuery()
|
|
|
|
/* istanbul ignore if */
|
|
|
|
if ($) {
|
2021-05-11 10:49:30 +03:00
|
|
|
const name = plugin.NAME
|
2020-12-08 07:16:50 +01:00
|
|
|
const JQUERY_NO_CONFLICT = $.fn[name]
|
|
|
|
$.fn[name] = plugin.jQueryInterface
|
|
|
|
$.fn[name].Constructor = plugin
|
|
|
|
$.fn[name].noConflict = () => {
|
|
|
|
$.fn[name] = JQUERY_NO_CONFLICT
|
|
|
|
return plugin.jQueryInterface
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 23:28:50 +03:00
|
|
|
const execute = callback => {
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 13:44:16 +02:00
|
|
|
const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
|
|
|
|
if (!waitForTransition) {
|
|
|
|
execute(callback)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const durationPadding = 5
|
|
|
|
const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding
|
|
|
|
|
|
|
|
let called = false
|
|
|
|
|
|
|
|
const handler = ({ target }) => {
|
|
|
|
if (target !== transitionElement) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
called = true
|
|
|
|
transitionElement.removeEventListener(TRANSITION_END, handler)
|
|
|
|
execute(callback)
|
|
|
|
}
|
|
|
|
|
|
|
|
transitionElement.addEventListener(TRANSITION_END, handler)
|
|
|
|
setTimeout(() => {
|
|
|
|
if (!called) {
|
|
|
|
triggerTransitionEnd(transitionElement)
|
|
|
|
}
|
|
|
|
}, emulatedDuration)
|
|
|
|
}
|
|
|
|
|
2021-05-19 01:23:52 +03:00
|
|
|
/**
|
|
|
|
* Return the previous/next element of a list.
|
|
|
|
*
|
|
|
|
* @param {array} list The list of elements
|
|
|
|
* @param activeElement The active element
|
|
|
|
* @param shouldGetNext Choose to get next or previous element
|
|
|
|
* @param isCycleAllowed
|
|
|
|
* @return {Element|elem} The proper element
|
|
|
|
*/
|
|
|
|
const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
|
|
|
|
let index = list.indexOf(activeElement)
|
|
|
|
|
2021-05-22 09:58:52 +02:00
|
|
|
// if the element does not exist in the list return an element depending on the direction and if cycle is allowed
|
2021-05-19 01:23:52 +03:00
|
|
|
if (index === -1) {
|
2021-05-22 09:58:52 +02:00
|
|
|
return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0]
|
2021-05-19 01:23:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const listLength = list.length
|
|
|
|
|
|
|
|
index += shouldGetNext ? 1 : -1
|
|
|
|
|
|
|
|
if (isCycleAllowed) {
|
|
|
|
index = (index + listLength) % listLength
|
|
|
|
}
|
|
|
|
|
|
|
|
return list[Math.max(0, Math.min(index, listLength - 1))]
|
|
|
|
}
|
|
|
|
|
2019-02-23 00:37:55 +02:00
|
|
|
export {
|
2021-05-13 18:17:20 +03:00
|
|
|
getElement,
|
2019-02-23 00:37:55 +02:00
|
|
|
getUID,
|
|
|
|
getSelectorFromElement,
|
2019-07-23 21:15:00 +02:00
|
|
|
getElementFromSelector,
|
2019-02-23 00:37:55 +02:00
|
|
|
getTransitionDurationFromElement,
|
|
|
|
triggerTransitionEnd,
|
|
|
|
isElement,
|
|
|
|
typeCheckConfig,
|
|
|
|
isVisible,
|
2021-03-16 18:35:03 +02:00
|
|
|
isDisabled,
|
2019-02-23 00:37:55 +02:00
|
|
|
findShadowRoot,
|
|
|
|
noop,
|
2021-05-19 01:23:52 +03:00
|
|
|
getNextActiveElement,
|
2020-11-01 14:32:36 +01:00
|
|
|
reflow,
|
|
|
|
getjQuery,
|
2020-06-26 17:06:20 +03:00
|
|
|
onDOMContentLoaded,
|
2020-12-08 07:16:50 +01:00
|
|
|
isRTL,
|
2021-04-14 23:28:50 +03:00
|
|
|
defineJQueryPlugin,
|
2021-06-03 13:44:16 +02:00
|
|
|
execute,
|
|
|
|
executeAfterTransition
|
2019-02-23 00:37:55 +02:00
|
|
|
}
|