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.

toast.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*!
  2. * Bootstrap toast.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.Toast = 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. function _defineProperty(obj, key, value) {
  28. if (key in obj) {
  29. Object.defineProperty(obj, key, {
  30. value: value,
  31. enumerable: true,
  32. configurable: true,
  33. writable: true
  34. });
  35. } else {
  36. obj[key] = value;
  37. }
  38. return obj;
  39. }
  40. function ownKeys(object, enumerableOnly) {
  41. var keys = Object.keys(object);
  42. if (Object.getOwnPropertySymbols) {
  43. var symbols = Object.getOwnPropertySymbols(object);
  44. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  45. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  46. });
  47. keys.push.apply(keys, symbols);
  48. }
  49. return keys;
  50. }
  51. function _objectSpread2(target) {
  52. for (var i = 1; i < arguments.length; i++) {
  53. var source = arguments[i] != null ? arguments[i] : {};
  54. if (i % 2) {
  55. ownKeys(Object(source), true).forEach(function (key) {
  56. _defineProperty(target, key, source[key]);
  57. });
  58. } else if (Object.getOwnPropertyDescriptors) {
  59. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  60. } else {
  61. ownKeys(Object(source)).forEach(function (key) {
  62. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  63. });
  64. }
  65. }
  66. return target;
  67. }
  68. /**
  69. * ------------------------------------------------------------------------
  70. * Constants
  71. * ------------------------------------------------------------------------
  72. */
  73. var NAME = 'toast';
  74. var VERSION = '4.5.0';
  75. var DATA_KEY = 'bs.toast';
  76. var EVENT_KEY = "." + DATA_KEY;
  77. var JQUERY_NO_CONFLICT = $.fn[NAME];
  78. var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY;
  79. var EVENT_HIDE = "hide" + EVENT_KEY;
  80. var EVENT_HIDDEN = "hidden" + EVENT_KEY;
  81. var EVENT_SHOW = "show" + EVENT_KEY;
  82. var EVENT_SHOWN = "shown" + EVENT_KEY;
  83. var CLASS_NAME_FADE = 'fade';
  84. var CLASS_NAME_HIDE = 'hide';
  85. var CLASS_NAME_SHOW = 'show';
  86. var CLASS_NAME_SHOWING = 'showing';
  87. var DefaultType = {
  88. animation: 'boolean',
  89. autohide: 'boolean',
  90. delay: 'number'
  91. };
  92. var Default = {
  93. animation: true,
  94. autohide: true,
  95. delay: 500
  96. };
  97. var SELECTOR_DATA_DISMISS = '[data-dismiss="toast"]';
  98. /**
  99. * ------------------------------------------------------------------------
  100. * Class Definition
  101. * ------------------------------------------------------------------------
  102. */
  103. var Toast = /*#__PURE__*/function () {
  104. function Toast(element, config) {
  105. this._element = element;
  106. this._config = this._getConfig(config);
  107. this._timeout = null;
  108. this._setListeners();
  109. } // Getters
  110. var _proto = Toast.prototype;
  111. // Public
  112. _proto.show = function show() {
  113. var _this = this;
  114. var showEvent = $.Event(EVENT_SHOW);
  115. $(this._element).trigger(showEvent);
  116. if (showEvent.isDefaultPrevented()) {
  117. return;
  118. }
  119. if (this._config.animation) {
  120. this._element.classList.add(CLASS_NAME_FADE);
  121. }
  122. var complete = function complete() {
  123. _this._element.classList.remove(CLASS_NAME_SHOWING);
  124. _this._element.classList.add(CLASS_NAME_SHOW);
  125. $(_this._element).trigger(EVENT_SHOWN);
  126. if (_this._config.autohide) {
  127. _this._timeout = setTimeout(function () {
  128. _this.hide();
  129. }, _this._config.delay);
  130. }
  131. };
  132. this._element.classList.remove(CLASS_NAME_HIDE);
  133. Util.reflow(this._element);
  134. this._element.classList.add(CLASS_NAME_SHOWING);
  135. if (this._config.animation) {
  136. var transitionDuration = Util.getTransitionDurationFromElement(this._element);
  137. $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  138. } else {
  139. complete();
  140. }
  141. };
  142. _proto.hide = function hide() {
  143. if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
  144. return;
  145. }
  146. var hideEvent = $.Event(EVENT_HIDE);
  147. $(this._element).trigger(hideEvent);
  148. if (hideEvent.isDefaultPrevented()) {
  149. return;
  150. }
  151. this._close();
  152. };
  153. _proto.dispose = function dispose() {
  154. clearTimeout(this._timeout);
  155. this._timeout = null;
  156. if (this._element.classList.contains(CLASS_NAME_SHOW)) {
  157. this._element.classList.remove(CLASS_NAME_SHOW);
  158. }
  159. $(this._element).off(EVENT_CLICK_DISMISS);
  160. $.removeData(this._element, DATA_KEY);
  161. this._element = null;
  162. this._config = null;
  163. } // Private
  164. ;
  165. _proto._getConfig = function _getConfig(config) {
  166. config = _objectSpread2(_objectSpread2(_objectSpread2({}, Default), $(this._element).data()), typeof config === 'object' && config ? config : {});
  167. Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
  168. return config;
  169. };
  170. _proto._setListeners = function _setListeners() {
  171. var _this2 = this;
  172. $(this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function () {
  173. return _this2.hide();
  174. });
  175. };
  176. _proto._close = function _close() {
  177. var _this3 = this;
  178. var complete = function complete() {
  179. _this3._element.classList.add(CLASS_NAME_HIDE);
  180. $(_this3._element).trigger(EVENT_HIDDEN);
  181. };
  182. this._element.classList.remove(CLASS_NAME_SHOW);
  183. if (this._config.animation) {
  184. var transitionDuration = Util.getTransitionDurationFromElement(this._element);
  185. $(this._element).one(Util.TRANSITION_END, complete).emulateTransitionEnd(transitionDuration);
  186. } else {
  187. complete();
  188. }
  189. } // Static
  190. ;
  191. Toast._jQueryInterface = function _jQueryInterface(config) {
  192. return this.each(function () {
  193. var $element = $(this);
  194. var data = $element.data(DATA_KEY);
  195. var _config = typeof config === 'object' && config;
  196. if (!data) {
  197. data = new Toast(this, _config);
  198. $element.data(DATA_KEY, data);
  199. }
  200. if (typeof config === 'string') {
  201. if (typeof data[config] === 'undefined') {
  202. throw new TypeError("No method named \"" + config + "\"");
  203. }
  204. data[config](this);
  205. }
  206. });
  207. };
  208. _createClass(Toast, null, [{
  209. key: "VERSION",
  210. get: function get() {
  211. return VERSION;
  212. }
  213. }, {
  214. key: "DefaultType",
  215. get: function get() {
  216. return DefaultType;
  217. }
  218. }, {
  219. key: "Default",
  220. get: function get() {
  221. return Default;
  222. }
  223. }]);
  224. return Toast;
  225. }();
  226. /**
  227. * ------------------------------------------------------------------------
  228. * jQuery
  229. * ------------------------------------------------------------------------
  230. */
  231. $.fn[NAME] = Toast._jQueryInterface;
  232. $.fn[NAME].Constructor = Toast;
  233. $.fn[NAME].noConflict = function () {
  234. $.fn[NAME] = JQUERY_NO_CONFLICT;
  235. return Toast._jQueryInterface;
  236. };
  237. return Toast;
  238. })));
  239. //# sourceMappingURL=toast.js.map