aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/alert.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/alert.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/alert.js132
1 files changed, 29 insertions, 103 deletions
diff --git a/vendor/twbs/bootstrap/js/src/alert.js b/vendor/twbs/bootstrap/js/src/alert.js
index afd7736c7..192bea89f 100644
--- a/vendor/twbs/bootstrap/js/src/alert.js
+++ b/vendor/twbs/bootstrap/js/src/alert.js
@@ -1,12 +1,14 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.6.0): alert.js
+ * Bootstrap (v5.1.3): alert.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
-import $ from 'jquery'
-import Util from './util'
+import { defineJQueryPlugin } from './util/index'
+import EventHandler from './dom/event-handler'
+import BaseComponent from './base-component'
+import { enableDismissTrigger } from './util/component-functions'
/**
* ------------------------------------------------------------------------
@@ -15,19 +17,11 @@ import Util from './util'
*/
const NAME = 'alert'
-const VERSION = '4.6.0'
const DATA_KEY = 'bs.alert'
const EVENT_KEY = `.${DATA_KEY}`
-const DATA_API_KEY = '.data-api'
-const JQUERY_NO_CONFLICT = $.fn[NAME]
-
-const SELECTOR_DISMISS = '[data-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'
@@ -37,111 +31,51 @@ const CLASS_NAME_SHOW = 'show'
* ------------------------------------------------------------------------
*/
-class Alert {
- constructor(element) {
- this._element = element
- }
-
+class Alert extends BaseComponent {
// Getters
- static get VERSION() {
- return VERSION
+ static get NAME() {
+ return NAME
}
// Public
- close(element) {
- let rootElement = this._element
- if (element) {
- rootElement = this._getRootElement(element)
- }
-
- const customEvent = this._triggerCloseEvent(rootElement)
+ close() {
+ const closeEvent = EventHandler.trigger(this._element, EVENT_CLOSE)
- if (customEvent.isDefaultPrevented()) {
+ if (closeEvent.defaultPrevented) {
return
}
- this._removeElement(rootElement)
- }
+ this._element.classList.remove(CLASS_NAME_SHOW)
- dispose() {
- $.removeData(this._element, DATA_KEY)
- this._element = null
+ const isAnimated = this._element.classList.contains(CLASS_NAME_FADE)
+ this._queueCallback(() => this._destroyElement(), this._element, isAnimated)
}
// Private
-
- _getRootElement(element) {
- const selector = Util.getSelectorFromElement(element)
- let parent = false
-
- if (selector) {
- parent = document.querySelector(selector)
- }
-
- if (!parent) {
- parent = $(element).closest(`.${CLASS_NAME_ALERT}`)[0]
- }
-
- return parent
- }
-
- _triggerCloseEvent(element) {
- const closeEvent = $.Event(EVENT_CLOSE)
-
- $(element).trigger(closeEvent)
- return closeEvent
- }
-
- _removeElement(element) {
- $(element).removeClass(CLASS_NAME_SHOW)
-
- if (!$(element).hasClass(CLASS_NAME_FADE)) {
- this._destroyElement(element)
- return
- }
-
- const transitionDuration = Util.getTransitionDurationFromElement(element)
-
- $(element)
- .one(Util.TRANSITION_END, event => this._destroyElement(element, event))
- .emulateTransitionEnd(transitionDuration)
- }
-
- _destroyElement(element) {
- $(element)
- .detach()
- .trigger(EVENT_CLOSED)
- .remove()
+ _destroyElement() {
+ this._element.remove()
+ EventHandler.trigger(this._element, EVENT_CLOSED)
+ this.dispose()
}
// Static
- static _jQueryInterface(config) {
+ static jQueryInterface(config) {
return this.each(function () {
- const $element = $(this)
- let data = $element.data(DATA_KEY)
-
- if (!data) {
- data = new Alert(this)
- $element.data(DATA_KEY, data)
- }
+ const data = Alert.getOrCreateInstance(this)
- if (config === 'close') {
- data[config](this)
+ if (typeof config !== 'string') {
+ return
}
- })
- }
- static _handleDismiss(alertInstance) {
- return function (event) {
- if (event) {
- event.preventDefault()
+ if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
+ throw new TypeError(`No method named "${config}"`)
}
- alertInstance.close(this)
- }
+ data[config](this)
+ })
}
}
@@ -151,23 +85,15 @@ class Alert {
* ------------------------------------------------------------------------
*/
-$(document).on(
- EVENT_CLICK_DATA_API,
- SELECTOR_DISMISS,
- Alert._handleDismiss(new Alert())
-)
+enableDismissTrigger(Alert, 'close')
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
+ * add .Alert to jQuery only if jQuery is present
*/
-$.fn[NAME] = Alert._jQueryInterface
-$.fn[NAME].Constructor = Alert
-$.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Alert._jQueryInterface
-}
+defineJQueryPlugin(Alert)
export default Alert