1441 |
ariadna |
1 |
/**
|
|
|
2 |
* --------------------------------------------------------------------------
|
|
|
3 |
* Bootstrap util/component-functions.js
|
|
|
4 |
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
|
5 |
* --------------------------------------------------------------------------
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
import EventHandler from '../dom/event-handler'
|
|
|
9 |
import SelectorEngine from '../dom/selector-engine'
|
|
|
10 |
import { isDisabled } from './index'
|
|
|
11 |
|
|
|
12 |
const enableDismissTrigger = (component, method = 'hide') => {
|
|
|
13 |
const clickEvent = `click.dismiss${component.EVENT_KEY}`
|
|
|
14 |
const name = component.NAME
|
|
|
15 |
|
|
|
16 |
EventHandler.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) {
|
|
|
17 |
if (['A', 'AREA'].includes(this.tagName)) {
|
|
|
18 |
event.preventDefault()
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
if (isDisabled(this)) {
|
|
|
22 |
return
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
const target = SelectorEngine.getElementFromSelector(this) || this.closest(`.${name}`)
|
|
|
26 |
const instance = component.getOrCreateInstance(target)
|
|
|
27 |
|
|
|
28 |
// Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
|
|
|
29 |
instance[method]()
|
|
|
30 |
})
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
export {
|
|
|
34 |
enableDismissTrigger
|
|
|
35 |
}
|