Layout von Websiten mit Bootstrap und Foundation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

alert.js 5.4KB

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