f9f9a406d60b71cfc92369aa2f5f7192b6c912f5.svn-base 6.2 KB

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