aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/alert.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-06-07 12:56:27 +0200
committerMario <mario@mariovavti.com>2021-06-07 12:56:27 +0200
commitf3b4308cb59bf4b21ff186f8479c82239446d139 (patch)
tree0dcbdcffcfe0dd678958cbcc34f41cb1c470c69b /vendor/twbs/bootstrap/js/src/alert.js
parent67322c12643ced03bec0be70667f8b1c45de752f (diff)
downloadvolse-hubzilla-f3b4308cb59bf4b21ff186f8479c82239446d139.tar.gz
volse-hubzilla-f3b4308cb59bf4b21ff186f8479c82239446d139.tar.bz2
volse-hubzilla-f3b4308cb59bf4b21ff186f8479c82239446d139.zip
upgrade to bootstrap 5.0.1 and first batch of fixes
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/alert.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/alert.js101
1 files changed, 30 insertions, 71 deletions
diff --git a/vendor/twbs/bootstrap/js/src/alert.js b/vendor/twbs/bootstrap/js/src/alert.js
index afd7736c7..87cc7e731 100644
--- a/vendor/twbs/bootstrap/js/src/alert.js
+++ b/vendor/twbs/bootstrap/js/src/alert.js
@@ -1,12 +1,17 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.6.0): alert.js
+ * Bootstrap (v5.0.1): 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 Data from './dom/data'
+import EventHandler from './dom/event-handler'
+import BaseComponent from './base-component'
/**
* ------------------------------------------------------------------------
@@ -15,13 +20,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,95 +40,59 @@ 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()
+ if (element.parentNode) {
+ element.parentNode.removeChild(element)
+ }
+
+ 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)
+ let data = Data.get(this, DATA_KEY)
if (!data) {
data = new Alert(this)
- $element.data(DATA_KEY, data)
}
if (config === 'close') {
@@ -134,7 +101,7 @@ class Alert {
})
}
- static _handleDismiss(alertInstance) {
+ static handleDismiss(alertInstance) {
return function (event) {
if (event) {
event.preventDefault()
@@ -151,23 +118,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