aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/alert.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-07-29 09:31:47 +0000
committerMario <mario@mariovavti.com>2021-07-29 09:31:47 +0000
commitcb57c4ea188b982119f515f043a72f037f943025 (patch)
tree11144c1107f16047ed37f543fc34859d0c649e08 /vendor/twbs/bootstrap/js/src/alert.js
parentc6133d2558ce29e44342fa7be8bb65e0059aea02 (diff)
parentb7ffec6fbe77eff3c550a922f50bd79321b293ed (diff)
downloadvolse-hubzilla-cb57c4ea188b982119f515f043a72f037f943025.tar.gz
volse-hubzilla-cb57c4ea188b982119f515f043a72f037f943025.tar.bz2
volse-hubzilla-cb57c4ea188b982119f515f043a72f037f943025.zip
Merge branch 'bs5' into 'dev'
Update to bootstrap 5 and implement next generation app menu (work in progress) See merge request hubzilla/core!1980
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