You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
7.3 KiB

  1. /*!
  2. * Bootstrap alert.js v5.1.3 (https://getbootstrap.com/)
  3. * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./base-component.js')) :
  8. typeof define === 'function' && define.amd ? define(['./dom/event-handler', './base-component'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.EventHandler, global.Base));
  10. })(this, (function (EventHandler, BaseComponent) { 'use strict';
  11. const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
  12. const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
  13. const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
  14. /**
  15. * --------------------------------------------------------------------------
  16. * Bootstrap (v5.1.3): util/index.js
  17. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  18. * --------------------------------------------------------------------------
  19. */
  20. const getSelector = element => {
  21. let selector = element.getAttribute('data-bs-target');
  22. if (!selector || selector === '#') {
  23. let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
  24. // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
  25. // `document.querySelector` will rightfully complain it is invalid.
  26. // See https://github.com/twbs/bootstrap/issues/32273
  27. if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
  28. return null;
  29. } // Just in case some CMS puts out a full URL with the anchor appended
  30. if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
  31. hrefAttr = `#${hrefAttr.split('#')[1]}`;
  32. }
  33. selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
  34. }
  35. return selector;
  36. };
  37. const getElementFromSelector = element => {
  38. const selector = getSelector(element);
  39. return selector ? document.querySelector(selector) : null;
  40. };
  41. const isDisabled = element => {
  42. if (!element || element.nodeType !== Node.ELEMENT_NODE) {
  43. return true;
  44. }
  45. if (element.classList.contains('disabled')) {
  46. return true;
  47. }
  48. if (typeof element.disabled !== 'undefined') {
  49. return element.disabled;
  50. }
  51. return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
  52. };
  53. const getjQuery = () => {
  54. const {
  55. jQuery
  56. } = window;
  57. if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
  58. return jQuery;
  59. }
  60. return null;
  61. };
  62. const DOMContentLoadedCallbacks = [];
  63. const onDOMContentLoaded = callback => {
  64. if (document.readyState === 'loading') {
  65. // add listener on the first call when the document is in loading state
  66. if (!DOMContentLoadedCallbacks.length) {
  67. document.addEventListener('DOMContentLoaded', () => {
  68. DOMContentLoadedCallbacks.forEach(callback => callback());
  69. });
  70. }
  71. DOMContentLoadedCallbacks.push(callback);
  72. } else {
  73. callback();
  74. }
  75. };
  76. const defineJQueryPlugin = plugin => {
  77. onDOMContentLoaded(() => {
  78. const $ = getjQuery();
  79. /* istanbul ignore if */
  80. if ($) {
  81. const name = plugin.NAME;
  82. const JQUERY_NO_CONFLICT = $.fn[name];
  83. $.fn[name] = plugin.jQueryInterface;
  84. $.fn[name].Constructor = plugin;
  85. $.fn[name].noConflict = () => {
  86. $.fn[name] = JQUERY_NO_CONFLICT;
  87. return plugin.jQueryInterface;
  88. };
  89. }
  90. });
  91. };
  92. /**
  93. * --------------------------------------------------------------------------
  94. * Bootstrap (v5.1.3): util/component-functions.js
  95. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  96. * --------------------------------------------------------------------------
  97. */
  98. const enableDismissTrigger = (component, method = 'hide') => {
  99. const clickEvent = `click.dismiss${component.EVENT_KEY}`;
  100. const name = component.NAME;
  101. EventHandler__default.default.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) {
  102. if (['A', 'AREA'].includes(this.tagName)) {
  103. event.preventDefault();
  104. }
  105. if (isDisabled(this)) {
  106. return;
  107. }
  108. const target = getElementFromSelector(this) || this.closest(`.${name}`);
  109. const instance = component.getOrCreateInstance(target); // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
  110. instance[method]();
  111. });
  112. };
  113. /**
  114. * --------------------------------------------------------------------------
  115. * Bootstrap (v5.1.3): alert.js
  116. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  117. * --------------------------------------------------------------------------
  118. */
  119. /**
  120. * ------------------------------------------------------------------------
  121. * Constants
  122. * ------------------------------------------------------------------------
  123. */
  124. const NAME = 'alert';
  125. const DATA_KEY = 'bs.alert';
  126. const EVENT_KEY = `.${DATA_KEY}`;
  127. const EVENT_CLOSE = `close${EVENT_KEY}`;
  128. const EVENT_CLOSED = `closed${EVENT_KEY}`;
  129. const CLASS_NAME_FADE = 'fade';
  130. const CLASS_NAME_SHOW = 'show';
  131. /**
  132. * ------------------------------------------------------------------------
  133. * Class Definition
  134. * ------------------------------------------------------------------------
  135. */
  136. class Alert extends BaseComponent__default.default {
  137. // Getters
  138. static get NAME() {
  139. return NAME;
  140. } // Public
  141. close() {
  142. const closeEvent = EventHandler__default.default.trigger(this._element, EVENT_CLOSE);
  143. if (closeEvent.defaultPrevented) {
  144. return;
  145. }
  146. this._element.classList.remove(CLASS_NAME_SHOW);
  147. const isAnimated = this._element.classList.contains(CLASS_NAME_FADE);
  148. this._queueCallback(() => this._destroyElement(), this._element, isAnimated);
  149. } // Private
  150. _destroyElement() {
  151. this._element.remove();
  152. EventHandler__default.default.trigger(this._element, EVENT_CLOSED);
  153. this.dispose();
  154. } // Static
  155. static jQueryInterface(config) {
  156. return this.each(function () {
  157. const data = Alert.getOrCreateInstance(this);
  158. if (typeof config !== 'string') {
  159. return;
  160. }
  161. if (data[config] === undefined || config.startsWith('_') || config === 'constructor') {
  162. throw new TypeError(`No method named "${config}"`);
  163. }
  164. data[config](this);
  165. });
  166. }
  167. }
  168. /**
  169. * ------------------------------------------------------------------------
  170. * Data Api implementation
  171. * ------------------------------------------------------------------------
  172. */
  173. enableDismissTrigger(Alert, 'close');
  174. /**
  175. * ------------------------------------------------------------------------
  176. * jQuery
  177. * ------------------------------------------------------------------------
  178. * add .Alert to jQuery only if jQuery is present
  179. */
  180. defineJQueryPlugin(Alert);
  181. return Alert;
  182. }));
  183. //# sourceMappingURL=alert.js.map