diff options
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/alert.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/dist/alert.js | 303 |
1 files changed, 173 insertions, 130 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/alert.js b/vendor/twbs/bootstrap/js/dist/alert.js index 2f5d80f12..3f73b68d2 100644 --- a/vendor/twbs/bootstrap/js/dist/alert.js +++ b/vendor/twbs/bootstrap/js/dist/alert.js @@ -1,169 +1,217 @@ /*! - * Bootstrap alert.js v4.6.0 (https://getbootstrap.com/) + * Bootstrap alert.js v5.1.3 (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('jquery'), require('./util.js')) : - typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.jQuery, global.Util)); -}(this, (function ($, Util) { 'use strict'; - - function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } - - var $__default = /*#__PURE__*/_interopDefaultLegacy($); - var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util); - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } + 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 _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } + const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e }; - /** - * ------------------------------------------------------------------------ - * Constants - * ------------------------------------------------------------------------ - */ + const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler); + const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent); - var NAME = 'alert'; - var VERSION = '4.6.0'; - var DATA_KEY = 'bs.alert'; - var EVENT_KEY = "." + DATA_KEY; - var DATA_API_KEY = '.data-api'; - var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME]; - var SELECTOR_DISMISS = '[data-dismiss="alert"]'; - var EVENT_CLOSE = "close" + EVENT_KEY; - var EVENT_CLOSED = "closed" + EVENT_KEY; - var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY; - var CLASS_NAME_ALERT = 'alert'; - var CLASS_NAME_FADE = 'fade'; - var CLASS_NAME_SHOW = 'show'; /** - * ------------------------------------------------------------------------ - * Class Definition - * ------------------------------------------------------------------------ + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- */ - var Alert = /*#__PURE__*/function () { - function Alert(element) { - this._element = element; - } // Getters + const getSelector = element => { + let selector = element.getAttribute('data-bs-target'); + if (!selector || selector === '#') { + let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes, + // so everything starting with `#` or `.`. If a "real" URL is used as the selector, + // `document.querySelector` will rightfully complain it is invalid. + // See https://github.com/twbs/bootstrap/issues/32273 - var _proto = Alert.prototype; + if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) { + return null; + } // Just in case some CMS puts out a full URL with the anchor appended - // Public - _proto.close = function close(element) { - var rootElement = this._element; - if (element) { - rootElement = this._getRootElement(element); + if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) { + hrefAttr = `#${hrefAttr.split('#')[1]}`; } - var customEvent = this._triggerCloseEvent(rootElement); + selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null; + } - if (customEvent.isDefaultPrevented()) { - return; + return selector; + }; + + const getElementFromSelector = element => { + const selector = getSelector(element); + 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 + } = window; + + if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) { + return jQuery; + } + + return null; + }; + + const DOMContentLoadedCallbacks = []; + + const onDOMContentLoaded = callback => { + if (document.readyState === 'loading') { + // add listener on the first call when the document is in loading state + if (!DOMContentLoadedCallbacks.length) { + document.addEventListener('DOMContentLoaded', () => { + DOMContentLoadedCallbacks.forEach(callback => callback()); + }); } - this._removeElement(rootElement); - }; + DOMContentLoadedCallbacks.push(callback); + } else { + callback(); + } + }; - _proto.dispose = function dispose() { - $__default['default'].removeData(this._element, DATA_KEY); - this._element = null; - } // Private - ; + const defineJQueryPlugin = plugin => { + onDOMContentLoaded(() => { + const $ = getjQuery(); + /* istanbul ignore if */ + + if ($) { + const name = plugin.NAME; + const JQUERY_NO_CONFLICT = $.fn[name]; + $.fn[name] = plugin.jQueryInterface; + $.fn[name].Constructor = plugin; + + $.fn[name].noConflict = () => { + $.fn[name] = JQUERY_NO_CONFLICT; + return plugin.jQueryInterface; + }; + } + }); + }; - _proto._getRootElement = function _getRootElement(element) { - var selector = Util__default['default'].getSelectorFromElement(element); - var parent = false; + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): util/component-functions.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ - if (selector) { - parent = document.querySelector(selector); + 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 (!parent) { - parent = $__default['default'](element).closest("." + CLASS_NAME_ALERT)[0]; + if (isDisabled(this)) { + return; } - return parent; - }; + 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 - _proto._triggerCloseEvent = function _triggerCloseEvent(element) { - var closeEvent = $__default['default'].Event(EVENT_CLOSE); - $__default['default'](element).trigger(closeEvent); - return closeEvent; - }; + instance[method](); + }); + }; + + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): alert.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + /** + * ------------------------------------------------------------------------ + * Constants + * ------------------------------------------------------------------------ + */ - _proto._removeElement = function _removeElement(element) { - var _this = this; + const NAME = 'alert'; + const DATA_KEY = 'bs.alert'; + const EVENT_KEY = `.${DATA_KEY}`; + const EVENT_CLOSE = `close${EVENT_KEY}`; + const EVENT_CLOSED = `closed${EVENT_KEY}`; + const CLASS_NAME_FADE = 'fade'; + const CLASS_NAME_SHOW = 'show'; + /** + * ------------------------------------------------------------------------ + * Class Definition + * ------------------------------------------------------------------------ + */ - $__default['default'](element).removeClass(CLASS_NAME_SHOW); + class Alert extends BaseComponent__default.default { + // Getters + static get NAME() { + return NAME; + } // Public - if (!$__default['default'](element).hasClass(CLASS_NAME_FADE)) { - this._destroyElement(element); + close() { + const closeEvent = EventHandler__default.default.trigger(this._element, EVENT_CLOSE); + + if (closeEvent.defaultPrevented) { return; } - var transitionDuration = Util__default['default'].getTransitionDurationFromElement(element); - $__default['default'](element).one(Util__default['default'].TRANSITION_END, function (event) { - return _this._destroyElement(element, event); - }).emulateTransitionEnd(transitionDuration); - }; + this._element.classList.remove(CLASS_NAME_SHOW); + + const isAnimated = this._element.classList.contains(CLASS_NAME_FADE); + + this._queueCallback(() => this._destroyElement(), this._element, isAnimated); + } // Private + - _proto._destroyElement = function _destroyElement(element) { - $__default['default'](element).detach().trigger(EVENT_CLOSED).remove(); + _destroyElement() { + this._element.remove(); + + EventHandler__default.default.trigger(this._element, EVENT_CLOSED); + this.dispose(); } // Static - ; - Alert._jQueryInterface = function _jQueryInterface(config) { + + static jQueryInterface(config) { return this.each(function () { - var $element = $__default['default'](this); - var data = $element.data(DATA_KEY); + const data = Alert.getOrCreateInstance(this); - if (!data) { - data = new Alert(this); - $element.data(DATA_KEY, data); + if (typeof config !== 'string') { + return; } - if (config === 'close') { - data[config](this); + if (data[config] === undefined || config.startsWith('_') || config === 'constructor') { + throw new TypeError(`No method named "${config}"`); } - }); - }; - Alert._handleDismiss = function _handleDismiss(alertInstance) { - return function (event) { - if (event) { - event.preventDefault(); - } - - alertInstance.close(this); - }; - }; - - _createClass(Alert, null, [{ - key: "VERSION", - get: function get() { - return VERSION; - } - }]); + data[config](this); + }); + } - return Alert; - }(); + } /** * ------------------------------------------------------------------------ * Data Api implementation @@ -171,22 +219,17 @@ */ - $__default['default'](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 */ - $__default['default'].fn[NAME] = Alert._jQueryInterface; - $__default['default'].fn[NAME].Constructor = Alert; - - $__default['default'].fn[NAME].noConflict = function () { - $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT; - return Alert._jQueryInterface; - }; + defineJQueryPlugin(Alert); return Alert; -}))); +})); //# sourceMappingURL=alert.js.map |