5c2db79c4cfc18cf4f0573ba5e56530cbb6c6da5.svn-base 5.2 KB

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