alert.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
  3. typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
  4. (global.Alert = factory(global.jQuery,global.Util));
  5. }(this, (function ($,Util) { 'use strict';
  6. $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  7. Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util;
  8. function _defineProperties(target, props) {
  9. for (var i = 0; i < props.length; i++) {
  10. var descriptor = props[i];
  11. descriptor.enumerable = descriptor.enumerable || false;
  12. descriptor.configurable = true;
  13. if ("value" in descriptor) descriptor.writable = true;
  14. Object.defineProperty(target, descriptor.key, descriptor);
  15. }
  16. }
  17. function _createClass(Constructor, protoProps, staticProps) {
  18. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  19. if (staticProps) _defineProperties(Constructor, staticProps);
  20. return Constructor;
  21. }
  22. /**
  23. * --------------------------------------------------------------------------
  24. * Bootstrap (v4.1.3): alert.js
  25. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  26. * --------------------------------------------------------------------------
  27. */
  28. var Alert = function ($$$1) {
  29. /**
  30. * ------------------------------------------------------------------------
  31. * Constants
  32. * ------------------------------------------------------------------------
  33. */
  34. var NAME = 'alert';
  35. var VERSION = '4.1.3';
  36. var DATA_KEY = 'bs.alert';
  37. var EVENT_KEY = "." + DATA_KEY;
  38. var DATA_API_KEY = '.data-api';
  39. var JQUERY_NO_CONFLICT = $$$1.fn[NAME];
  40. var Selector = {
  41. DISMISS: '[data-dismiss="alert"]'
  42. };
  43. var Event = {
  44. CLOSE: "close" + EVENT_KEY,
  45. CLOSED: "closed" + EVENT_KEY,
  46. CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
  47. };
  48. var ClassName = {
  49. ALERT: 'alert',
  50. FADE: 'fade',
  51. SHOW: 'show'
  52. /**
  53. * ------------------------------------------------------------------------
  54. * Class Definition
  55. * ------------------------------------------------------------------------
  56. */
  57. };
  58. var Alert =
  59. /*#__PURE__*/
  60. function () {
  61. function Alert(element) {
  62. this._element = element;
  63. } // Getters
  64. var _proto = Alert.prototype;
  65. // Public
  66. _proto.close = function close(element) {
  67. var rootElement = this._element;
  68. if (element) {
  69. rootElement = this._getRootElement(element);
  70. }
  71. var customEvent = this._triggerCloseEvent(rootElement);
  72. if (customEvent.isDefaultPrevented()) {
  73. return;
  74. }
  75. this._removeElement(rootElement);
  76. };
  77. _proto.dispose = function dispose() {
  78. $$$1.removeData(this._element, DATA_KEY);
  79. this._element = null;
  80. }; // Private
  81. _proto._getRootElement = function _getRootElement(element) {
  82. var selector = Util.getSelectorFromElement(element);
  83. var parent = false;
  84. if (selector) {
  85. parent = document.querySelector(selector);
  86. }
  87. if (!parent) {
  88. parent = $$$1(element).closest("." + ClassName.ALERT)[0];
  89. }
  90. return parent;
  91. };
  92. _proto._triggerCloseEvent = function _triggerCloseEvent(element) {
  93. var closeEvent = $$$1.Event(Event.CLOSE);
  94. $$$1(element).trigger(closeEvent);
  95. return closeEvent;
  96. };
  97. _proto._removeElement = function _removeElement(element) {
  98. var _this = this;
  99. $$$1(element).removeClass(ClassName.SHOW);
  100. if (!$$$1(element).hasClass(ClassName.FADE)) {
  101. this._destroyElement(element);
  102. return;
  103. }
  104. var transitionDuration = Util.getTransitionDurationFromElement(element);
  105. $$$1(element).one(Util.TRANSITION_END, function (event) {
  106. return _this._destroyElement(element, event);
  107. }).emulateTransitionEnd(transitionDuration);
  108. };
  109. _proto._destroyElement = function _destroyElement(element) {
  110. $$$1(element).detach().trigger(Event.CLOSED).remove();
  111. }; // Static
  112. Alert._jQueryInterface = function _jQueryInterface(config) {
  113. return this.each(function () {
  114. var $element = $$$1(this);
  115. var data = $element.data(DATA_KEY);
  116. if (!data) {
  117. data = new Alert(this);
  118. $element.data(DATA_KEY, data);
  119. }
  120. if (config === 'close') {
  121. data[config](this);
  122. }
  123. });
  124. };
  125. Alert._handleDismiss = function _handleDismiss(alertInstance) {
  126. return function (event) {
  127. if (event) {
  128. event.preventDefault();
  129. }
  130. alertInstance.close(this);
  131. };
  132. };
  133. _createClass(Alert, null, [{
  134. key: "VERSION",
  135. get: function get() {
  136. return VERSION;
  137. }
  138. }]);
  139. return Alert;
  140. }();
  141. /**
  142. * ------------------------------------------------------------------------
  143. * Data Api implementation
  144. * ------------------------------------------------------------------------
  145. */
  146. $$$1(document).on(Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()));
  147. /**
  148. * ------------------------------------------------------------------------
  149. * jQuery
  150. * ------------------------------------------------------------------------
  151. */
  152. $$$1.fn[NAME] = Alert._jQueryInterface;
  153. $$$1.fn[NAME].Constructor = Alert;
  154. $$$1.fn[NAME].noConflict = function () {
  155. $$$1.fn[NAME] = JQUERY_NO_CONFLICT;
  156. return Alert._jQueryInterface;
  157. };
  158. return Alert;
  159. }($);
  160. return Alert;
  161. })));
  162. //# sourceMappingURL=alert.js.map