alert.js 4.9 KB

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