alert.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*!
  2. * Bootstrap alert.js v4.5.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2020 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('jquery'), require('./util.js')) :
  8. typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.jQuery, global.Util));
  10. }(this, (function ($, Util) { 'use strict';
  11. $ = $ && Object.prototype.hasOwnProperty.call($, 'default') ? $['default'] : $;
  12. Util = Util && Object.prototype.hasOwnProperty.call(Util, 'default') ? Util['default'] : Util;
  13. 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); } }
  14. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  15. /**
  16. * ------------------------------------------------------------------------
  17. * Constants
  18. * ------------------------------------------------------------------------
  19. */
  20. var NAME = 'alert';
  21. var VERSION = '4.5.2';
  22. var DATA_KEY = 'bs.alert';
  23. var EVENT_KEY = "." + DATA_KEY;
  24. var DATA_API_KEY = '.data-api';
  25. var JQUERY_NO_CONFLICT = $.fn[NAME];
  26. var SELECTOR_DISMISS = '[data-dismiss="alert"]';
  27. var EVENT_CLOSE = "close" + EVENT_KEY;
  28. var EVENT_CLOSED = "closed" + EVENT_KEY;
  29. var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
  30. var CLASS_NAME_ALERT = 'alert';
  31. var CLASS_NAME_FADE = 'fade';
  32. var CLASS_NAME_SHOW = 'show';
  33. /**
  34. * ------------------------------------------------------------------------
  35. * Class Definition
  36. * ------------------------------------------------------------------------
  37. */
  38. var Alert = /*#__PURE__*/function () {
  39. function Alert(element) {
  40. this._element = element;
  41. } // Getters
  42. var _proto = Alert.prototype;
  43. // Public
  44. _proto.close = function close(element) {
  45. var rootElement = this._element;
  46. if (element) {
  47. rootElement = this._getRootElement(element);
  48. }
  49. var customEvent = this._triggerCloseEvent(rootElement);
  50. if (customEvent.isDefaultPrevented()) {
  51. return;
  52. }
  53. this._removeElement(rootElement);
  54. };
  55. _proto.dispose = function dispose() {
  56. $.removeData(this._element, DATA_KEY);
  57. this._element = null;
  58. } // Private
  59. ;
  60. _proto._getRootElement = function _getRootElement(element) {
  61. var selector = Util.getSelectorFromElement(element);
  62. var parent = false;
  63. if (selector) {
  64. parent = document.querySelector(selector);
  65. }
  66. if (!parent) {
  67. parent = $(element).closest("." + CLASS_NAME_ALERT)[0];
  68. }
  69. return parent;
  70. };
  71. _proto._triggerCloseEvent = function _triggerCloseEvent(element) {
  72. var closeEvent = $.Event(EVENT_CLOSE);
  73. $(element).trigger(closeEvent);
  74. return closeEvent;
  75. };
  76. _proto._removeElement = function _removeElement(element) {
  77. var _this = this;
  78. $(element).removeClass(CLASS_NAME_SHOW);
  79. if (!$(element).hasClass(CLASS_NAME_FADE)) {
  80. this._destroyElement(element);
  81. return;
  82. }
  83. var transitionDuration = Util.getTransitionDurationFromElement(element);
  84. $(element).one(Util.TRANSITION_END, function (event) {
  85. return _this._destroyElement(element, event);
  86. }).emulateTransitionEnd(transitionDuration);
  87. };
  88. _proto._destroyElement = function _destroyElement(element) {
  89. $(element).detach().trigger(EVENT_CLOSED).remove();
  90. } // Static
  91. ;
  92. Alert._jQueryInterface = function _jQueryInterface(config) {
  93. return this.each(function () {
  94. var $element = $(this);
  95. var data = $element.data(DATA_KEY);
  96. if (!data) {
  97. data = new Alert(this);
  98. $element.data(DATA_KEY, data);
  99. }
  100. if (config === 'close') {
  101. data[config](this);
  102. }
  103. });
  104. };
  105. Alert._handleDismiss = function _handleDismiss(alertInstance) {
  106. return function (event) {
  107. if (event) {
  108. event.preventDefault();
  109. }
  110. alertInstance.close(this);
  111. };
  112. };
  113. _createClass(Alert, null, [{
  114. key: "VERSION",
  115. get: function get() {
  116. return VERSION;
  117. }
  118. }]);
  119. return Alert;
  120. }();
  121. /**
  122. * ------------------------------------------------------------------------
  123. * Data Api implementation
  124. * ------------------------------------------------------------------------
  125. */
  126. $(document).on(EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert._handleDismiss(new Alert()));
  127. /**
  128. * ------------------------------------------------------------------------
  129. * jQuery
  130. * ------------------------------------------------------------------------
  131. */
  132. $.fn[NAME] = Alert._jQueryInterface;
  133. $.fn[NAME].Constructor = Alert;
  134. $.fn[NAME].noConflict = function () {
  135. $.fn[NAME] = JQUERY_NO_CONFLICT;
  136. return Alert._jQueryInterface;
  137. };
  138. return Alert;
  139. })));
  140. //# sourceMappingURL=alert.js.map