source: trip-planner-front/node_modules/bootstrap/js/dist/toast.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 12.3 KB
Line 
1/*!
2 * Bootstrap toast.js v5.1.3 (https://getbootstrap.com/)
3 * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5 */
6(function (global, factory) {
7 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
8 typeof define === 'function' && define.amd ? define(['./dom/event-handler', './dom/manipulator', './base-component'], factory) :
9 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Toast = factory(global.EventHandler, global.Manipulator, global.Base));
10})(this, (function (EventHandler, Manipulator, BaseComponent) { 'use strict';
11
12 const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
13
14 const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
15 const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
16 const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
17
18 /**
19 * --------------------------------------------------------------------------
20 * Bootstrap (v5.1.3): util/index.js
21 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
22 * --------------------------------------------------------------------------
23 */
24
25 const toType = obj => {
26 if (obj === null || obj === undefined) {
27 return `${obj}`;
28 }
29
30 return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
31 };
32
33 const getSelector = element => {
34 let selector = element.getAttribute('data-bs-target');
35
36 if (!selector || selector === '#') {
37 let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
38 // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
39 // `document.querySelector` will rightfully complain it is invalid.
40 // See https://github.com/twbs/bootstrap/issues/32273
41
42 if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
43 return null;
44 } // Just in case some CMS puts out a full URL with the anchor appended
45
46
47 if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
48 hrefAttr = `#${hrefAttr.split('#')[1]}`;
49 }
50
51 selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
52 }
53
54 return selector;
55 };
56
57 const getElementFromSelector = element => {
58 const selector = getSelector(element);
59 return selector ? document.querySelector(selector) : null;
60 };
61
62 const isElement = obj => {
63 if (!obj || typeof obj !== 'object') {
64 return false;
65 }
66
67 if (typeof obj.jquery !== 'undefined') {
68 obj = obj[0];
69 }
70
71 return typeof obj.nodeType !== 'undefined';
72 };
73
74 const typeCheckConfig = (componentName, config, configTypes) => {
75 Object.keys(configTypes).forEach(property => {
76 const expectedTypes = configTypes[property];
77 const value = config[property];
78 const valueType = value && isElement(value) ? 'element' : toType(value);
79
80 if (!new RegExp(expectedTypes).test(valueType)) {
81 throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
82 }
83 });
84 };
85
86 const isDisabled = element => {
87 if (!element || element.nodeType !== Node.ELEMENT_NODE) {
88 return true;
89 }
90
91 if (element.classList.contains('disabled')) {
92 return true;
93 }
94
95 if (typeof element.disabled !== 'undefined') {
96 return element.disabled;
97 }
98
99 return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
100 };
101 /**
102 * Trick to restart an element's animation
103 *
104 * @param {HTMLElement} element
105 * @return void
106 *
107 * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
108 */
109
110
111 const reflow = element => {
112 // eslint-disable-next-line no-unused-expressions
113 element.offsetHeight;
114 };
115
116 const getjQuery = () => {
117 const {
118 jQuery
119 } = window;
120
121 if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
122 return jQuery;
123 }
124
125 return null;
126 };
127
128 const DOMContentLoadedCallbacks = [];
129
130 const onDOMContentLoaded = callback => {
131 if (document.readyState === 'loading') {
132 // add listener on the first call when the document is in loading state
133 if (!DOMContentLoadedCallbacks.length) {
134 document.addEventListener('DOMContentLoaded', () => {
135 DOMContentLoadedCallbacks.forEach(callback => callback());
136 });
137 }
138
139 DOMContentLoadedCallbacks.push(callback);
140 } else {
141 callback();
142 }
143 };
144
145 const defineJQueryPlugin = plugin => {
146 onDOMContentLoaded(() => {
147 const $ = getjQuery();
148 /* istanbul ignore if */
149
150 if ($) {
151 const name = plugin.NAME;
152 const JQUERY_NO_CONFLICT = $.fn[name];
153 $.fn[name] = plugin.jQueryInterface;
154 $.fn[name].Constructor = plugin;
155
156 $.fn[name].noConflict = () => {
157 $.fn[name] = JQUERY_NO_CONFLICT;
158 return plugin.jQueryInterface;
159 };
160 }
161 });
162 };
163
164 /**
165 * --------------------------------------------------------------------------
166 * Bootstrap (v5.1.3): util/component-functions.js
167 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
168 * --------------------------------------------------------------------------
169 */
170
171 const enableDismissTrigger = (component, method = 'hide') => {
172 const clickEvent = `click.dismiss${component.EVENT_KEY}`;
173 const name = component.NAME;
174 EventHandler__default.default.on(document, clickEvent, `[data-bs-dismiss="${name}"]`, function (event) {
175 if (['A', 'AREA'].includes(this.tagName)) {
176 event.preventDefault();
177 }
178
179 if (isDisabled(this)) {
180 return;
181 }
182
183 const target = getElementFromSelector(this) || this.closest(`.${name}`);
184 const instance = component.getOrCreateInstance(target); // Method argument is left, for Alert and only, as it doesn't implement the 'hide' method
185
186 instance[method]();
187 });
188 };
189
190 /**
191 * --------------------------------------------------------------------------
192 * Bootstrap (v5.1.3): toast.js
193 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
194 * --------------------------------------------------------------------------
195 */
196 /**
197 * ------------------------------------------------------------------------
198 * Constants
199 * ------------------------------------------------------------------------
200 */
201
202 const NAME = 'toast';
203 const DATA_KEY = 'bs.toast';
204 const EVENT_KEY = `.${DATA_KEY}`;
205 const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`;
206 const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`;
207 const EVENT_FOCUSIN = `focusin${EVENT_KEY}`;
208 const EVENT_FOCUSOUT = `focusout${EVENT_KEY}`;
209 const EVENT_HIDE = `hide${EVENT_KEY}`;
210 const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
211 const EVENT_SHOW = `show${EVENT_KEY}`;
212 const EVENT_SHOWN = `shown${EVENT_KEY}`;
213 const CLASS_NAME_FADE = 'fade';
214 const CLASS_NAME_HIDE = 'hide'; // @deprecated - kept here only for backwards compatibility
215
216 const CLASS_NAME_SHOW = 'show';
217 const CLASS_NAME_SHOWING = 'showing';
218 const DefaultType = {
219 animation: 'boolean',
220 autohide: 'boolean',
221 delay: 'number'
222 };
223 const Default = {
224 animation: true,
225 autohide: true,
226 delay: 5000
227 };
228 /**
229 * ------------------------------------------------------------------------
230 * Class Definition
231 * ------------------------------------------------------------------------
232 */
233
234 class Toast extends BaseComponent__default.default {
235 constructor(element, config) {
236 super(element);
237 this._config = this._getConfig(config);
238 this._timeout = null;
239 this._hasMouseInteraction = false;
240 this._hasKeyboardInteraction = false;
241
242 this._setListeners();
243 } // Getters
244
245
246 static get DefaultType() {
247 return DefaultType;
248 }
249
250 static get Default() {
251 return Default;
252 }
253
254 static get NAME() {
255 return NAME;
256 } // Public
257
258
259 show() {
260 const showEvent = EventHandler__default.default.trigger(this._element, EVENT_SHOW);
261
262 if (showEvent.defaultPrevented) {
263 return;
264 }
265
266 this._clearTimeout();
267
268 if (this._config.animation) {
269 this._element.classList.add(CLASS_NAME_FADE);
270 }
271
272 const complete = () => {
273 this._element.classList.remove(CLASS_NAME_SHOWING);
274
275 EventHandler__default.default.trigger(this._element, EVENT_SHOWN);
276
277 this._maybeScheduleHide();
278 };
279
280 this._element.classList.remove(CLASS_NAME_HIDE); // @deprecated
281
282
283 reflow(this._element);
284
285 this._element.classList.add(CLASS_NAME_SHOW);
286
287 this._element.classList.add(CLASS_NAME_SHOWING);
288
289 this._queueCallback(complete, this._element, this._config.animation);
290 }
291
292 hide() {
293 if (!this._element.classList.contains(CLASS_NAME_SHOW)) {
294 return;
295 }
296
297 const hideEvent = EventHandler__default.default.trigger(this._element, EVENT_HIDE);
298
299 if (hideEvent.defaultPrevented) {
300 return;
301 }
302
303 const complete = () => {
304 this._element.classList.add(CLASS_NAME_HIDE); // @deprecated
305
306
307 this._element.classList.remove(CLASS_NAME_SHOWING);
308
309 this._element.classList.remove(CLASS_NAME_SHOW);
310
311 EventHandler__default.default.trigger(this._element, EVENT_HIDDEN);
312 };
313
314 this._element.classList.add(CLASS_NAME_SHOWING);
315
316 this._queueCallback(complete, this._element, this._config.animation);
317 }
318
319 dispose() {
320 this._clearTimeout();
321
322 if (this._element.classList.contains(CLASS_NAME_SHOW)) {
323 this._element.classList.remove(CLASS_NAME_SHOW);
324 }
325
326 super.dispose();
327 } // Private
328
329
330 _getConfig(config) {
331 config = { ...Default,
332 ...Manipulator__default.default.getDataAttributes(this._element),
333 ...(typeof config === 'object' && config ? config : {})
334 };
335 typeCheckConfig(NAME, config, this.constructor.DefaultType);
336 return config;
337 }
338
339 _maybeScheduleHide() {
340 if (!this._config.autohide) {
341 return;
342 }
343
344 if (this._hasMouseInteraction || this._hasKeyboardInteraction) {
345 return;
346 }
347
348 this._timeout = setTimeout(() => {
349 this.hide();
350 }, this._config.delay);
351 }
352
353 _onInteraction(event, isInteracting) {
354 switch (event.type) {
355 case 'mouseover':
356 case 'mouseout':
357 this._hasMouseInteraction = isInteracting;
358 break;
359
360 case 'focusin':
361 case 'focusout':
362 this._hasKeyboardInteraction = isInteracting;
363 break;
364 }
365
366 if (isInteracting) {
367 this._clearTimeout();
368
369 return;
370 }
371
372 const nextElement = event.relatedTarget;
373
374 if (this._element === nextElement || this._element.contains(nextElement)) {
375 return;
376 }
377
378 this._maybeScheduleHide();
379 }
380
381 _setListeners() {
382 EventHandler__default.default.on(this._element, EVENT_MOUSEOVER, event => this._onInteraction(event, true));
383 EventHandler__default.default.on(this._element, EVENT_MOUSEOUT, event => this._onInteraction(event, false));
384 EventHandler__default.default.on(this._element, EVENT_FOCUSIN, event => this._onInteraction(event, true));
385 EventHandler__default.default.on(this._element, EVENT_FOCUSOUT, event => this._onInteraction(event, false));
386 }
387
388 _clearTimeout() {
389 clearTimeout(this._timeout);
390 this._timeout = null;
391 } // Static
392
393
394 static jQueryInterface(config) {
395 return this.each(function () {
396 const data = Toast.getOrCreateInstance(this, config);
397
398 if (typeof config === 'string') {
399 if (typeof data[config] === 'undefined') {
400 throw new TypeError(`No method named "${config}"`);
401 }
402
403 data[config](this);
404 }
405 });
406 }
407
408 }
409
410 enableDismissTrigger(Toast);
411 /**
412 * ------------------------------------------------------------------------
413 * jQuery
414 * ------------------------------------------------------------------------
415 * add .Toast to jQuery only if jQuery is present
416 */
417
418 defineJQueryPlugin(Toast);
419
420 return Toast;
421
422}));
423//# sourceMappingURL=toast.js.map
Note: See TracBrowser for help on using the repository browser.