mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 08:34:08 +02:00
148
js/dist/toast.js
vendored
148
js/dist/toast.js
vendored
@@ -1,5 +1,5 @@
|
||||
/*!
|
||||
* Bootstrap toast.js v5.0.0 (https://getbootstrap.com/)
|
||||
* Bootstrap toast.js v5.0.1 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/
|
||||
@@ -16,15 +16,6 @@
|
||||
var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
|
||||
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.0): util/index.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
const MILLISECONDS_MULTIPLIER = 1000;
|
||||
const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
||||
|
||||
const toType = obj => {
|
||||
if (obj === null || obj === undefined) {
|
||||
return `${obj}`;
|
||||
@@ -33,51 +24,16 @@
|
||||
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
|
||||
};
|
||||
|
||||
const getTransitionDurationFromElement = element => {
|
||||
if (!element) {
|
||||
return 0;
|
||||
} // Get transition-duration of the element
|
||||
|
||||
|
||||
let {
|
||||
transitionDuration,
|
||||
transitionDelay
|
||||
} = window.getComputedStyle(element);
|
||||
const floatTransitionDuration = Number.parseFloat(transitionDuration);
|
||||
const floatTransitionDelay = Number.parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
|
||||
|
||||
if (!floatTransitionDuration && !floatTransitionDelay) {
|
||||
return 0;
|
||||
} // If multiple durations are defined, take the first
|
||||
|
||||
|
||||
transitionDuration = transitionDuration.split(',')[0];
|
||||
transitionDelay = transitionDelay.split(',')[0];
|
||||
return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
|
||||
};
|
||||
|
||||
const triggerTransitionEnd = element => {
|
||||
element.dispatchEvent(new Event(TRANSITION_END));
|
||||
};
|
||||
|
||||
const isElement = obj => (obj[0] || obj).nodeType;
|
||||
|
||||
const emulateTransitionEnd = (element, duration) => {
|
||||
let called = false;
|
||||
const durationPadding = 5;
|
||||
const emulatedDuration = duration + durationPadding;
|
||||
|
||||
function listener() {
|
||||
called = true;
|
||||
element.removeEventListener(TRANSITION_END, listener);
|
||||
const isElement = obj => {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
element.addEventListener(TRANSITION_END, listener);
|
||||
setTimeout(() => {
|
||||
if (!called) {
|
||||
triggerTransitionEnd(element);
|
||||
}
|
||||
}, emulatedDuration);
|
||||
if (typeof obj.jquery !== 'undefined') {
|
||||
obj = obj[0];
|
||||
}
|
||||
|
||||
return typeof obj.nodeType !== 'undefined';
|
||||
};
|
||||
|
||||
const typeCheckConfig = (componentName, config, configTypes) => {
|
||||
@@ -114,12 +70,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
const defineJQueryPlugin = (name, plugin) => {
|
||||
const defineJQueryPlugin = plugin => {
|
||||
onDOMContentLoaded(() => {
|
||||
const $ = getjQuery();
|
||||
/* istanbul ignore if */
|
||||
|
||||
if ($) {
|
||||
const name = plugin.NAME;
|
||||
const JQUERY_NO_CONFLICT = $.fn[name];
|
||||
$.fn[name] = plugin.jQueryInterface;
|
||||
$.fn[name].Constructor = plugin;
|
||||
@@ -134,7 +91,7 @@
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.0): toast.js
|
||||
* Bootstrap (v5.0.1): toast.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -148,6 +105,10 @@
|
||||
const DATA_KEY = 'bs.toast';
|
||||
const EVENT_KEY = `.${DATA_KEY}`;
|
||||
const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`;
|
||||
const EVENT_MOUSEOVER = `mouseover${EVENT_KEY}`;
|
||||
const EVENT_MOUSEOUT = `mouseout${EVENT_KEY}`;
|
||||
const EVENT_FOCUSIN = `focusin${EVENT_KEY}`;
|
||||
const EVENT_FOCUSOUT = `focusout${EVENT_KEY}`;
|
||||
const EVENT_HIDE = `hide${EVENT_KEY}`;
|
||||
const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
|
||||
const EVENT_SHOW = `show${EVENT_KEY}`;
|
||||
@@ -178,6 +139,8 @@
|
||||
super(element);
|
||||
this._config = this._getConfig(config);
|
||||
this._timeout = null;
|
||||
this._hasMouseInteraction = false;
|
||||
this._hasKeyboardInteraction = false;
|
||||
|
||||
this._setListeners();
|
||||
} // Getters
|
||||
@@ -191,8 +154,8 @@
|
||||
return Default;
|
||||
}
|
||||
|
||||
static get DATA_KEY() {
|
||||
return DATA_KEY;
|
||||
static get NAME() {
|
||||
return NAME;
|
||||
} // Public
|
||||
|
||||
|
||||
@@ -216,11 +179,7 @@
|
||||
|
||||
EventHandler__default['default'].trigger(this._element, EVENT_SHOWN);
|
||||
|
||||
if (this._config.autohide) {
|
||||
this._timeout = setTimeout(() => {
|
||||
this.hide();
|
||||
}, this._config.delay);
|
||||
}
|
||||
this._maybeScheduleHide();
|
||||
};
|
||||
|
||||
this._element.classList.remove(CLASS_NAME_HIDE);
|
||||
@@ -229,13 +188,7 @@
|
||||
|
||||
this._element.classList.add(CLASS_NAME_SHOWING);
|
||||
|
||||
if (this._config.animation) {
|
||||
const transitionDuration = getTransitionDurationFromElement(this._element);
|
||||
EventHandler__default['default'].one(this._element, 'transitionend', complete);
|
||||
emulateTransitionEnd(this._element, transitionDuration);
|
||||
} else {
|
||||
complete();
|
||||
}
|
||||
this._queueCallback(complete, this._element, this._config.animation);
|
||||
}
|
||||
|
||||
hide() {
|
||||
@@ -257,13 +210,7 @@
|
||||
|
||||
this._element.classList.remove(CLASS_NAME_SHOW);
|
||||
|
||||
if (this._config.animation) {
|
||||
const transitionDuration = getTransitionDurationFromElement(this._element);
|
||||
EventHandler__default['default'].one(this._element, 'transitionend', complete);
|
||||
emulateTransitionEnd(this._element, transitionDuration);
|
||||
} else {
|
||||
complete();
|
||||
}
|
||||
this._queueCallback(complete, this._element, this._config.animation);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
@@ -274,7 +221,6 @@
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
this._config = null;
|
||||
} // Private
|
||||
|
||||
|
||||
@@ -287,8 +233,54 @@
|
||||
return config;
|
||||
}
|
||||
|
||||
_maybeScheduleHide() {
|
||||
if (!this._config.autohide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._hasMouseInteraction || this._hasKeyboardInteraction) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._timeout = setTimeout(() => {
|
||||
this.hide();
|
||||
}, this._config.delay);
|
||||
}
|
||||
|
||||
_onInteraction(event, isInteracting) {
|
||||
switch (event.type) {
|
||||
case 'mouseover':
|
||||
case 'mouseout':
|
||||
this._hasMouseInteraction = isInteracting;
|
||||
break;
|
||||
|
||||
case 'focusin':
|
||||
case 'focusout':
|
||||
this._hasKeyboardInteraction = isInteracting;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isInteracting) {
|
||||
this._clearTimeout();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const nextElement = event.relatedTarget;
|
||||
|
||||
if (this._element === nextElement || this._element.contains(nextElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._maybeScheduleHide();
|
||||
}
|
||||
|
||||
_setListeners() {
|
||||
EventHandler__default['default'].on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, () => this.hide());
|
||||
EventHandler__default['default'].on(this._element, EVENT_MOUSEOVER, event => this._onInteraction(event, true));
|
||||
EventHandler__default['default'].on(this._element, EVENT_MOUSEOUT, event => this._onInteraction(event, false));
|
||||
EventHandler__default['default'].on(this._element, EVENT_FOCUSIN, event => this._onInteraction(event, true));
|
||||
EventHandler__default['default'].on(this._element, EVENT_FOCUSOUT, event => this._onInteraction(event, false));
|
||||
}
|
||||
|
||||
_clearTimeout() {
|
||||
@@ -326,7 +318,7 @@
|
||||
*/
|
||||
|
||||
|
||||
defineJQueryPlugin(NAME, Toast);
|
||||
defineJQueryPlugin(Toast);
|
||||
|
||||
return Toast;
|
||||
|
||||
|
Reference in New Issue
Block a user