main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 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.js'
|
---|
| 9 | import SelectorEngine from '../dom/selector-engine.js'
|
---|
| 10 | import { isDisabled } from './index.js'
|
---|
| 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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.