diff options
Diffstat (limited to 'js/src/alert.js')
| -rw-r--r-- | js/src/alert.js | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/js/src/alert.js b/js/src/alert.js index f1f612232..a25c44ec3 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -1,14 +1,12 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-alpha3): alert.js + * Bootstrap (v5.0.0-beta3): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ import { - getjQuery, - onDOMContentLoaded, - TRANSITION_END, + defineJQueryPlugin, emulateTransitionEnd, getElementFromSelector, getTransitionDurationFromElement @@ -34,9 +32,9 @@ const EVENT_CLOSE = `close${EVENT_KEY}` const EVENT_CLOSED = `closed${EVENT_KEY}` const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}` -const CLASSNAME_ALERT = 'alert' -const CLASSNAME_FADE = 'fade' -const CLASSNAME_SHOW = 'show' +const CLASS_NAME_ALERT = 'alert' +const CLASS_NAME_FADE = 'fade' +const CLASS_NAME_SHOW = 'show' /** * ------------------------------------------------------------------------ @@ -67,7 +65,7 @@ class Alert extends BaseComponent { // Private _getRootElement(element) { - return getElementFromSelector(element) || element.closest(`.${CLASSNAME_ALERT}`) + return getElementFromSelector(element) || element.closest(`.${CLASS_NAME_ALERT}`) } _triggerCloseEvent(element) { @@ -75,16 +73,16 @@ class Alert extends BaseComponent { } _removeElement(element) { - element.classList.remove(CLASSNAME_SHOW) + element.classList.remove(CLASS_NAME_SHOW) - if (!element.classList.contains(CLASSNAME_FADE)) { + if (!element.classList.contains(CLASS_NAME_FADE)) { this._destroyElement(element) return } const transitionDuration = getTransitionDurationFromElement(element) - EventHandler.one(element, TRANSITION_END, () => this._destroyElement(element)) + EventHandler.one(element, 'transitionend', () => this._destroyElement(element)) emulateTransitionEnd(element, transitionDuration) } @@ -100,7 +98,7 @@ class Alert extends BaseComponent { static jQueryInterface(config) { return this.each(function () { - let data = Data.getData(this, DATA_KEY) + let data = Data.get(this, DATA_KEY) if (!data) { data = new Alert(this) @@ -128,6 +126,7 @@ class Alert extends BaseComponent { * Data Api implementation * ------------------------------------------------------------------------ */ + EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert())) /** @@ -137,18 +136,6 @@ EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDi * add .Alert to jQuery only if jQuery is present */ -onDOMContentLoaded(() => { - const $ = getjQuery() - /* istanbul ignore if */ - if ($) { - const JQUERY_NO_CONFLICT = $.fn[NAME] - $.fn[NAME] = Alert.jQueryInterface - $.fn[NAME].Constructor = Alert - $.fn[NAME].noConflict = () => { - $.fn[NAME] = JQUERY_NO_CONFLICT - return Alert.jQueryInterface - } - } -}) +defineJQueryPlugin(NAME, Alert) export default Alert |
