diff options
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/alert.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/dist/alert.js | 126 |
1 files changed, 78 insertions, 48 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/alert.js b/vendor/twbs/bootstrap/js/dist/alert.js index 5572ad9c3..1eeec55fe 100644 --- a/vendor/twbs/bootstrap/js/dist/alert.js +++ b/vendor/twbs/bootstrap/js/dist/alert.js @@ -1,18 +1,25 @@ /*! - * Bootstrap alert.js v5.0.2 (https://getbootstrap.com/) + * Bootstrap alert.js v5.1.2 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/selector-engine.js'), require('./dom/event-handler.js'), require('./base-component.js')) : - typeof define === 'function' && define.amd ? define(['./dom/selector-engine', './dom/event-handler', './base-component'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.SelectorEngine, global.EventHandler, global.Base)); -}(this, (function (SelectorEngine, EventHandler, BaseComponent) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./base-component.js')) : + typeof define === 'function' && define.amd ? define(['./dom/event-handler', './base-component'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.EventHandler, global.Base)); +})(this, (function (EventHandler, BaseComponent) { 'use strict'; - function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e }; - var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler); - var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent); + const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler); + const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent); + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.2): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ const getSelector = element => { let selector = element.getAttribute('data-bs-target'); @@ -43,6 +50,22 @@ return selector ? document.querySelector(selector) : null; }; + const isDisabled = element => { + if (!element || element.nodeType !== Node.ELEMENT_NODE) { + return true; + } + + if (element.classList.contains('disabled')) { + return true; + } + + if (typeof element.disabled !== 'undefined') { + return element.disabled; + } + + return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false'; + }; + const getjQuery = () => { const { jQuery @@ -93,7 +116,33 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.2): alert.js + * Bootstrap (v5.1.2): util/component-functions.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + + const enableDismissTrigger = (component, method = 'hide') => { + const clickEvent = `click.dismiss${component.EVENT_KEY}`; + const name = component.NAME; + EventHandler__default.default.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) { + if (['A', 'AREA'].includes(this.tagName)) { + event.preventDefault(); + } + + if (isDisabled(this)) { + return; + } + + const target = getElementFromSelector(this) || this.closest(`.${name}`); + const instance = component.getOrCreateInstance(target); // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method + + instance[method](); + }); + }; + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.2): alert.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -106,12 +155,8 @@ const NAME = 'alert'; const DATA_KEY = 'bs.alert'; const EVENT_KEY = `.${DATA_KEY}`; - const DATA_API_KEY = '.data-api'; - const SELECTOR_DISMISS = '[data-bs-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'; /** @@ -120,44 +165,33 @@ * ------------------------------------------------------------------------ */ - class Alert extends BaseComponent__default['default'] { + class Alert extends BaseComponent__default.default { // Getters static get NAME() { return NAME; } // Public - close(element) { - const rootElement = element ? this._getRootElement(element) : this._element; - - const customEvent = this._triggerCloseEvent(rootElement); + close() { + const closeEvent = EventHandler__default.default.trigger(this._element, EVENT_CLOSE); - if (customEvent === null || customEvent.defaultPrevented) { + if (closeEvent.defaultPrevented) { return; } - this._removeElement(rootElement); - } // Private + this._element.classList.remove(CLASS_NAME_SHOW); + const isAnimated = this._element.classList.contains(CLASS_NAME_FADE); - _getRootElement(element) { - return getElementFromSelector(element) || element.closest(`.${CLASS_NAME_ALERT}`); - } + this._queueCallback(() => this._destroyElement(), this._element, isAnimated); + } // Private - _triggerCloseEvent(element) { - return EventHandler__default['default'].trigger(element, EVENT_CLOSE); - } - _removeElement(element) { - element.classList.remove(CLASS_NAME_SHOW); - const isAnimated = element.classList.contains(CLASS_NAME_FADE); + _destroyElement() { + this._element.remove(); - this._queueCallback(() => this._destroyElement(element), element, isAnimated); - } - - _destroyElement(element) { - element.remove(); - EventHandler__default['default'].trigger(element, EVENT_CLOSED); + EventHandler__default.default.trigger(this._element, EVENT_CLOSED); + this.dispose(); } // Static @@ -165,20 +199,16 @@ return this.each(function () { 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); + }); } } @@ -189,7 +219,7 @@ */ - EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert.handleDismiss(new Alert())); + enableDismissTrigger(Alert, 'close'); /** * ------------------------------------------------------------------------ * jQuery @@ -201,5 +231,5 @@ return Alert; -}))); +})); //# sourceMappingURL=alert.js.map |