diff options
| author | XhmikosR <[email protected]> | 2021-09-07 21:49:51 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-07 21:49:51 +0300 |
| commit | 65413de3131294cbf7bc8bff94914cc8062149c6 (patch) | |
| tree | d606f927ef9d5e505245b0fce29366979d219f83 /js/src/util/component-functions.js | |
| parent | 72e79d0e3997c3a850263880240f26684b9784f7 (diff) | |
| parent | 0d81d3cbc14dfcdca8a868e3f25189a4f1ab273c (diff) | |
| download | bootstrap-docs-offcanvas-navbar.tar.xz bootstrap-docs-offcanvas-navbar.zip | |
Merge branch 'main' into docs-offcanvas-navbardocs-offcanvas-navbar
Diffstat (limited to 'js/src/util/component-functions.js')
| -rw-r--r-- | js/src/util/component-functions.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/js/src/util/component-functions.js b/js/src/util/component-functions.js new file mode 100644 index 000000000..ff9d87ee6 --- /dev/null +++ b/js/src/util/component-functions.js @@ -0,0 +1,34 @@ +/** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.1): util/component-functions.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + +import EventHandler from '../dom/event-handler' +import { getElementFromSelector, isDisabled } from './index' + +const enableDismissTrigger = (component, method = 'hide') => { + const clickEvent = `click.dismiss${component.EVENT_KEY}` + const name = component.NAME + + EventHandler.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) { + if (['A', 'AREA'].includes(this.tagName)) { + event.preventDefault() + } + + if (isDisabled(this)) { + return + } + + const target = getElementFromSelector(this) || this.closest(`.${name}`) + const instance = component.getOrCreateInstance(target) + + // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method + instance[method]() + }) +} + +export { + enableDismissTrigger +} |
