mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-25 04:51:39 +02:00
216
js/dist/tooltip.js
vendored
216
js/dist/tooltip.js
vendored
@@ -1,13 +1,13 @@
|
||||
/*!
|
||||
* Bootstrap tooltip.js v5.0.0 (https://getbootstrap.com/)
|
||||
* Bootstrap tooltip.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)
|
||||
*/
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js'), require('./base-component.js')) :
|
||||
typeof define === 'function' && define.amd ? define(['@popperjs/core', './dom/data', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global.Popper, global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base));
|
||||
}(this, (function (Popper, Data, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/selector-engine.js'), require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
|
||||
typeof define === 'function' && define.amd ? define(['@popperjs/core', './dom/selector-engine', './dom/data', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global.Popper, global.SelectorEngine, global.Data, global.EventHandler, global.Manipulator, global.Base));
|
||||
}(this, (function (Popper, SelectorEngine, Data, EventHandler, Manipulator, BaseComponent) { 'use strict';
|
||||
|
||||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
||||
|
||||
@@ -32,21 +32,20 @@
|
||||
}
|
||||
|
||||
var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
|
||||
var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
||||
var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
|
||||
var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
||||
var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
|
||||
var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
||||
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.0): util/index.js
|
||||
* Bootstrap (v5.0.1): util/index.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
const MAX_UID = 1000000;
|
||||
const MILLISECONDS_MULTIPLIER = 1000;
|
||||
const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
||||
|
||||
const toType = obj => {
|
||||
if (obj === null || obj === undefined) {
|
||||
@@ -70,51 +69,29 @@
|
||||
return prefix;
|
||||
};
|
||||
|
||||
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 getElement = obj => {
|
||||
if (isElement(obj)) {
|
||||
// it's a jQuery object or a node element
|
||||
return obj.jquery ? obj[0] : obj;
|
||||
}
|
||||
|
||||
if (typeof obj === 'string' && obj.length > 0) {
|
||||
return SelectorEngine__default['default'].findOne(obj);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const typeCheckConfig = (componentName, config, configTypes) => {
|
||||
@@ -176,12 +153,13 @@
|
||||
|
||||
const isRTL = () => document.documentElement.dir === 'rtl';
|
||||
|
||||
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;
|
||||
@@ -196,7 +174,7 @@
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.0): util/sanitizer.js
|
||||
* Bootstrap (v5.0.1): util/sanitizer.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -309,7 +287,7 @@
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.0): tooltip.js
|
||||
* Bootstrap (v5.0.1): tooltip.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -370,7 +348,7 @@
|
||||
allowList: DefaultAllowlist,
|
||||
popperConfig: null
|
||||
};
|
||||
const Event$1 = {
|
||||
const Event = {
|
||||
HIDE: `hide${EVENT_KEY}`,
|
||||
HIDDEN: `hidden${EVENT_KEY}`,
|
||||
SHOW: `show${EVENT_KEY}`,
|
||||
@@ -412,7 +390,7 @@
|
||||
this._activeTrigger = {};
|
||||
this._popper = null; // Protected
|
||||
|
||||
this.config = this._getConfig(config);
|
||||
this._config = this._getConfig(config);
|
||||
this.tip = null;
|
||||
|
||||
this._setListeners();
|
||||
@@ -427,16 +405,8 @@
|
||||
return NAME;
|
||||
}
|
||||
|
||||
static get DATA_KEY() {
|
||||
return DATA_KEY;
|
||||
}
|
||||
|
||||
static get Event() {
|
||||
return Event$1;
|
||||
}
|
||||
|
||||
static get EVENT_KEY() {
|
||||
return EVENT_KEY;
|
||||
return Event;
|
||||
}
|
||||
|
||||
static get DefaultType() {
|
||||
@@ -490,18 +460,10 @@
|
||||
this.tip.parentNode.removeChild(this.tip);
|
||||
}
|
||||
|
||||
this._isEnabled = null;
|
||||
this._timeout = null;
|
||||
this._hoverState = null;
|
||||
this._activeTrigger = null;
|
||||
|
||||
if (this._popper) {
|
||||
this._popper.destroy();
|
||||
}
|
||||
|
||||
this._popper = null;
|
||||
this.config = null;
|
||||
this.tip = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -530,18 +492,19 @@
|
||||
|
||||
this.setContent();
|
||||
|
||||
if (this.config.animation) {
|
||||
if (this._config.animation) {
|
||||
tip.classList.add(CLASS_NAME_FADE);
|
||||
}
|
||||
|
||||
const placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this._element) : this.config.placement;
|
||||
const placement = typeof this._config.placement === 'function' ? this._config.placement.call(this, tip, this._element) : this._config.placement;
|
||||
|
||||
const attachment = this._getAttachment(placement);
|
||||
|
||||
this._addAttachmentClass(attachment);
|
||||
|
||||
const container = this._getContainer();
|
||||
|
||||
const {
|
||||
container
|
||||
} = this._config;
|
||||
Data__default['default'].set(tip, this.constructor.DATA_KEY, this);
|
||||
|
||||
if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
|
||||
@@ -556,7 +519,7 @@
|
||||
}
|
||||
|
||||
tip.classList.add(CLASS_NAME_SHOW);
|
||||
const customClass = typeof this.config.customClass === 'function' ? this.config.customClass() : this.config.customClass;
|
||||
const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : this._config.customClass;
|
||||
|
||||
if (customClass) {
|
||||
tip.classList.add(...customClass.split(' '));
|
||||
@@ -582,13 +545,9 @@
|
||||
}
|
||||
};
|
||||
|
||||
if (this.tip.classList.contains(CLASS_NAME_FADE)) {
|
||||
const transitionDuration = getTransitionDurationFromElement(this.tip);
|
||||
EventHandler__default['default'].one(this.tip, 'transitionend', complete);
|
||||
emulateTransitionEnd(this.tip, transitionDuration);
|
||||
} else {
|
||||
complete();
|
||||
}
|
||||
const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE);
|
||||
|
||||
this._queueCallback(complete, this.tip, isAnimated);
|
||||
}
|
||||
|
||||
hide() {
|
||||
@@ -636,14 +595,9 @@
|
||||
this._activeTrigger[TRIGGER_CLICK] = false;
|
||||
this._activeTrigger[TRIGGER_FOCUS] = false;
|
||||
this._activeTrigger[TRIGGER_HOVER] = false;
|
||||
const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE);
|
||||
|
||||
if (this.tip.classList.contains(CLASS_NAME_FADE)) {
|
||||
const transitionDuration = getTransitionDurationFromElement(tip);
|
||||
EventHandler__default['default'].one(tip, 'transitionend', complete);
|
||||
emulateTransitionEnd(tip, transitionDuration);
|
||||
} else {
|
||||
complete();
|
||||
}
|
||||
this._queueCallback(complete, this.tip, isAnimated);
|
||||
|
||||
this._hoverState = '';
|
||||
}
|
||||
@@ -665,7 +619,7 @@
|
||||
}
|
||||
|
||||
const element = document.createElement('div');
|
||||
element.innerHTML = this.config.template;
|
||||
element.innerHTML = this._config.template;
|
||||
this.tip = element.children[0];
|
||||
return this.tip;
|
||||
}
|
||||
@@ -681,13 +635,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof content === 'object' && isElement(content)) {
|
||||
if (content.jquery) {
|
||||
content = content[0];
|
||||
} // content is a DOM node or a jQuery
|
||||
if (isElement(content)) {
|
||||
content = getElement(content); // content is a DOM node or a jQuery
|
||||
|
||||
|
||||
if (this.config.html) {
|
||||
if (this._config.html) {
|
||||
if (content.parentNode !== element) {
|
||||
element.innerHTML = '';
|
||||
element.appendChild(content);
|
||||
@@ -699,9 +650,9 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.config.html) {
|
||||
if (this.config.sanitize) {
|
||||
content = sanitizeHtml(content, this.config.allowList, this.config.sanitizeFn);
|
||||
if (this._config.html) {
|
||||
if (this._config.sanitize) {
|
||||
content = sanitizeHtml(content, this._config.allowList, this._config.sanitizeFn);
|
||||
}
|
||||
|
||||
element.innerHTML = content;
|
||||
@@ -714,7 +665,7 @@
|
||||
let title = this._element.getAttribute('data-bs-original-title');
|
||||
|
||||
if (!title) {
|
||||
title = typeof this.config.title === 'function' ? this.config.title.call(this._element) : this.config.title;
|
||||
title = typeof this._config.title === 'function' ? this._config.title.call(this._element) : this._config.title;
|
||||
}
|
||||
|
||||
return title;
|
||||
@@ -748,7 +699,7 @@
|
||||
_getOffset() {
|
||||
const {
|
||||
offset
|
||||
} = this.config;
|
||||
} = this._config;
|
||||
|
||||
if (typeof offset === 'string') {
|
||||
return offset.split(',').map(val => Number.parseInt(val, 10));
|
||||
@@ -767,7 +718,7 @@
|
||||
modifiers: [{
|
||||
name: 'flip',
|
||||
options: {
|
||||
fallbackPlacements: this.config.fallbackPlacements
|
||||
fallbackPlacements: this._config.fallbackPlacements
|
||||
}
|
||||
}, {
|
||||
name: 'offset',
|
||||
@@ -777,7 +728,7 @@
|
||||
}, {
|
||||
name: 'preventOverflow',
|
||||
options: {
|
||||
boundary: this.config.boundary
|
||||
boundary: this._config.boundary
|
||||
}
|
||||
}, {
|
||||
name: 'arrow',
|
||||
@@ -797,7 +748,7 @@
|
||||
}
|
||||
};
|
||||
return { ...defaultBsPopperConfig,
|
||||
...(typeof this.config.popperConfig === 'function' ? this.config.popperConfig(defaultBsPopperConfig) : this.config.popperConfig)
|
||||
...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -805,32 +756,21 @@
|
||||
this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`);
|
||||
}
|
||||
|
||||
_getContainer() {
|
||||
if (this.config.container === false) {
|
||||
return document.body;
|
||||
}
|
||||
|
||||
if (isElement(this.config.container)) {
|
||||
return this.config.container;
|
||||
}
|
||||
|
||||
return SelectorEngine__default['default'].findOne(this.config.container);
|
||||
}
|
||||
|
||||
_getAttachment(placement) {
|
||||
return AttachmentMap[placement.toUpperCase()];
|
||||
}
|
||||
|
||||
_setListeners() {
|
||||
const triggers = this.config.trigger.split(' ');
|
||||
const triggers = this._config.trigger.split(' ');
|
||||
|
||||
triggers.forEach(trigger => {
|
||||
if (trigger === 'click') {
|
||||
EventHandler__default['default'].on(this._element, this.constructor.Event.CLICK, this.config.selector, event => this.toggle(event));
|
||||
EventHandler__default['default'].on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event));
|
||||
} else if (trigger !== TRIGGER_MANUAL) {
|
||||
const eventIn = trigger === TRIGGER_HOVER ? this.constructor.Event.MOUSEENTER : this.constructor.Event.FOCUSIN;
|
||||
const eventOut = trigger === TRIGGER_HOVER ? this.constructor.Event.MOUSELEAVE : this.constructor.Event.FOCUSOUT;
|
||||
EventHandler__default['default'].on(this._element, eventIn, this.config.selector, event => this._enter(event));
|
||||
EventHandler__default['default'].on(this._element, eventOut, this.config.selector, event => this._leave(event));
|
||||
EventHandler__default['default'].on(this._element, eventIn, this._config.selector, event => this._enter(event));
|
||||
EventHandler__default['default'].on(this._element, eventOut, this._config.selector, event => this._leave(event));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -842,8 +782,8 @@
|
||||
|
||||
EventHandler__default['default'].on(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler);
|
||||
|
||||
if (this.config.selector) {
|
||||
this.config = { ...this.config,
|
||||
if (this._config.selector) {
|
||||
this._config = { ...this._config,
|
||||
trigger: 'manual',
|
||||
selector: ''
|
||||
};
|
||||
@@ -883,7 +823,7 @@
|
||||
clearTimeout(context._timeout);
|
||||
context._hoverState = HOVER_STATE_SHOW;
|
||||
|
||||
if (!context.config.delay || !context.config.delay.show) {
|
||||
if (!context._config.delay || !context._config.delay.show) {
|
||||
context.show();
|
||||
return;
|
||||
}
|
||||
@@ -892,7 +832,7 @@
|
||||
if (context._hoverState === HOVER_STATE_SHOW) {
|
||||
context.show();
|
||||
}
|
||||
}, context.config.delay.show);
|
||||
}, context._config.delay.show);
|
||||
}
|
||||
|
||||
_leave(event, context) {
|
||||
@@ -909,7 +849,7 @@
|
||||
clearTimeout(context._timeout);
|
||||
context._hoverState = HOVER_STATE_OUT;
|
||||
|
||||
if (!context.config.delay || !context.config.delay.hide) {
|
||||
if (!context._config.delay || !context._config.delay.hide) {
|
||||
context.hide();
|
||||
return;
|
||||
}
|
||||
@@ -918,7 +858,7 @@
|
||||
if (context._hoverState === HOVER_STATE_OUT) {
|
||||
context.hide();
|
||||
}
|
||||
}, context.config.delay.hide);
|
||||
}, context._config.delay.hide);
|
||||
}
|
||||
|
||||
_isWithActiveTrigger() {
|
||||
@@ -938,15 +878,11 @@
|
||||
delete dataAttributes[dataAttr];
|
||||
}
|
||||
});
|
||||
|
||||
if (config && typeof config.container === 'object' && config.container.jquery) {
|
||||
config.container = config.container[0];
|
||||
}
|
||||
|
||||
config = { ...this.constructor.Default,
|
||||
...dataAttributes,
|
||||
...(typeof config === 'object' && config ? config : {})
|
||||
};
|
||||
config.container = config.container === false ? document.body : getElement(config.container);
|
||||
|
||||
if (typeof config.delay === 'number') {
|
||||
config.delay = {
|
||||
@@ -975,10 +911,10 @@
|
||||
_getDelegateConfig() {
|
||||
const config = {};
|
||||
|
||||
if (this.config) {
|
||||
for (const key in this.config) {
|
||||
if (this.constructor.Default[key] !== this.config[key]) {
|
||||
config[key] = this.config[key];
|
||||
if (this._config) {
|
||||
for (const key in this._config) {
|
||||
if (this.constructor.Default[key] !== this._config[key]) {
|
||||
config[key] = this._config[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1045,7 +981,7 @@
|
||||
*/
|
||||
|
||||
|
||||
defineJQueryPlugin(NAME, Tooltip);
|
||||
defineJQueryPlugin(Tooltip);
|
||||
|
||||
return Tooltip;
|
||||
|
||||
|
Reference in New Issue
Block a user