aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/alert.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-09-08 07:43:40 +0000
committerMario <mario@mariovavti.com>2021-09-08 07:43:40 +0000
commit4c5f0a05c75cc66113f589a3ffe6df351abb1273 (patch)
tree15148d08a99f8375992e554a90e6d4333286a7cc /vendor/twbs/bootstrap/js/src/alert.js
parent952407363e245d41986cfb90e4ccf509bddc7322 (diff)
parent977a55eb8423745e4d88257b704d3e36f7337b9f (diff)
downloadvolse-hubzilla-6.2.tar.gz
volse-hubzilla-6.2.tar.bz2
volse-hubzilla-6.2.zip
Merge branch '6.2RC'6.2
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/alert.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/alert.js102
1 files changed, 27 insertions, 75 deletions
diff --git a/vendor/twbs/bootstrap/js/src/alert.js b/vendor/twbs/bootstrap/js/src/alert.js
index afd7736c7..75dbec71b 100644
--- a/vendor/twbs/bootstrap/js/src/alert.js
+++ b/vendor/twbs/bootstrap/js/src/alert.js
@@ -1,12 +1,16 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.6.0): alert.js
+ * Bootstrap (v5.0.2): alert.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
-import $ from 'jquery'
-import Util from './util'
+import {
+ defineJQueryPlugin,
+ getElementFromSelector
+} from './util/index'
+import EventHandler from './dom/event-handler'
+import BaseComponent from './base-component'
/**
* ------------------------------------------------------------------------
@@ -15,13 +19,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 SELECTOR_DISMISS = '[data-bs-dismiss="alert"]'
const EVENT_CLOSE = `close${EVENT_KEY}`
const EVENT_CLOSED = `closed${EVENT_KEY}`
@@ -37,96 +39,54 @@ 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 rootElement = element ? this._getRootElement(element) : this._element
const customEvent = this._triggerCloseEvent(rootElement)
- if (customEvent.isDefaultPrevented()) {
+ if (customEvent === null || customEvent.defaultPrevented) {
return
}
this._removeElement(rootElement)
}
- dispose() {
- $.removeData(this._element, DATA_KEY)
- this._element = null
- }
-
// 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
+ return getElementFromSelector(element) || element.closest(`.${CLASS_NAME_ALERT}`)
}
_triggerCloseEvent(element) {
- const closeEvent = $.Event(EVENT_CLOSE)
-
- $(element).trigger(closeEvent)
- return closeEvent
+ return EventHandler.trigger(element, EVENT_CLOSE)
}
_removeElement(element) {
- $(element).removeClass(CLASS_NAME_SHOW)
-
- if (!$(element).hasClass(CLASS_NAME_FADE)) {
- this._destroyElement(element)
- return
- }
+ element.classList.remove(CLASS_NAME_SHOW)
- const transitionDuration = Util.getTransitionDurationFromElement(element)
-
- $(element)
- .one(Util.TRANSITION_END, event => this._destroyElement(element, event))
- .emulateTransitionEnd(transitionDuration)
+ const isAnimated = element.classList.contains(CLASS_NAME_FADE)
+ this._queueCallback(() => this._destroyElement(element), element, isAnimated)
}
_destroyElement(element) {
- $(element)
- .detach()
- .trigger(EVENT_CLOSED)
- .remove()
+ element.remove()
+
+ EventHandler.trigger(element, EVENT_CLOSED)
}
// 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)
@@ -134,7 +94,7 @@ class Alert {
})
}
- static _handleDismiss(alertInstance) {
+ static handleDismiss(alertInstance) {
return function (event) {
if (event) {
event.preventDefault()
@@ -151,23 +111,15 @@ class Alert {
* ------------------------------------------------------------------------
*/
-$(document).on(
- EVENT_CLICK_DATA_API,
- SELECTOR_DISMISS,
- Alert._handleDismiss(new Alert())
-)
+EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert()))
/**
* ------------------------------------------------------------------------
* 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