diff options
| author | GeoSot <[email protected]> | 2021-07-28 17:39:32 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-28 17:39:32 +0300 |
| commit | 4bfd8a2cbcb10610b4078cefa45756b4a96301a0 (patch) | |
| tree | 2358a92299ff8fa105623932caacddbf8cd83a41 /js/src/alert.js | |
| parent | 047145e8086793e7c39747e70f5d74a8860c2e50 (diff) | |
| download | bootstrap-4bfd8a2cbcb10610b4078cefa45756b4a96301a0.tar.xz bootstrap-4bfd8a2cbcb10610b4078cefa45756b4a96301a0.zip | |
Use a streamlined way to trigger component dismiss (#34170)
* use a streamlined way to trigger component dismiss
* add documentation
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'js/src/alert.js')
| -rw-r--r-- | js/src/alert.js | 28 |
1 files changed, 3 insertions, 25 deletions
diff --git a/js/src/alert.js b/js/src/alert.js index 0bbe62af5..66c0bee0f 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -5,13 +5,10 @@ * -------------------------------------------------------------------------- */ -import { - defineJQueryPlugin, - getElementFromSelector, - isDisabled -} from './util/index' +import { defineJQueryPlugin } from './util/index' import EventHandler from './dom/event-handler' import BaseComponent from './base-component' +import { enableDismissTrigger } from './util/component-functions' /** * ------------------------------------------------------------------------ @@ -22,15 +19,9 @@ import BaseComponent from './base-component' const NAME = 'alert' const DATA_KEY = 'bs.alert' const EVENT_KEY = `.${DATA_KEY}` -const DATA_API_KEY = '.data-api' - -const SELECTOR_DISMISS = '[data-bs-dismiss="alert"]' const EVENT_CLOSE = `close${EVENT_KEY}` const EVENT_CLOSED = `closed${EVENT_KEY}` -const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}` - -const CLASS_NAME_ALERT = 'alert' const CLASS_NAME_FADE = 'fade' const CLASS_NAME_SHOW = 'show' @@ -94,20 +85,7 @@ class Alert extends BaseComponent { * ------------------------------------------------------------------------ */ -EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, function (event) { - if (['A', 'AREA'].includes(this.tagName)) { - event.preventDefault() - } - - if (isDisabled(this)) { - return - } - - const target = getElementFromSelector(this) || this.closest(`.${CLASS_NAME_ALERT}`) - const alert = Alert.getOrCreateInstance(target) - alert.close() -}) - +enableDismissTrigger(Alert, 'close') /** * ------------------------------------------------------------------------ * jQuery |
