aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/tooltip.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/tooltip.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/tooltip.js226
1 files changed, 122 insertions, 104 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/tooltip.js b/vendor/twbs/bootstrap/js/dist/tooltip.js
index 5a4ac0208..751c02ced 100644
--- a/vendor/twbs/bootstrap/js/dist/tooltip.js
+++ b/vendor/twbs/bootstrap/js/dist/tooltip.js
@@ -1,50 +1,47 @@
/*!
- * Bootstrap tooltip.js v5.0.2 (https://getbootstrap.com/)
+ * Bootstrap tooltip.js v5.1.2 (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/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';
+ 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';
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
+ const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
function _interopNamespace(e) {
if (e && e.__esModule) return e;
- var n = Object.create(null);
+ const n = Object.create(null);
if (e) {
- Object.keys(e).forEach(function (k) {
+ for (const k in e) {
if (k !== 'default') {
- var d = Object.getOwnPropertyDescriptor(e, k);
+ const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
- get: function () {
- return e[k];
- }
+ get: () => e[k]
});
}
- });
+ }
}
- n['default'] = e;
+ n.default = e;
return Object.freeze(n);
}
- 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 BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
+ const Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
+ const Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
+ const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
+ const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
+ const SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
+ const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.2): util/index.js
+ * Bootstrap (v5.1.2): util/index.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
-
const MAX_UID = 1000000;
const toType = obj => {
@@ -88,7 +85,7 @@
}
if (typeof obj === 'string' && obj.length > 0) {
- return SelectorEngine__default['default'].findOne(obj);
+ return document.querySelector(obj);
}
return null;
@@ -183,42 +180,42 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.2): util/sanitizer.js
+ * Bootstrap (v5.1.2): util/sanitizer.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
- const uriAttrs = new Set(['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href']);
+ const uriAttributes = new Set(['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href']);
const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i;
/**
* A pattern that recognizes a commonly useful subset of URLs that are safe.
*
- * Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
+ * Shoutout to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts
*/
- const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/i;
+ const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^#&/:?]*(?:[#/?]|$))/i;
/**
* A pattern that matches safe data URLs. Only matches image, video and audio types.
*
- * Shoutout to Angular 7 https://github.com/angular/angular/blob/7.2.4/packages/core/src/sanitization/url_sanitizer.ts
+ * Shoutout to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts
*/
const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i;
- const allowedAttribute = (attr, allowedAttributeList) => {
- const attrName = attr.nodeName.toLowerCase();
+ const allowedAttribute = (attribute, allowedAttributeList) => {
+ const attributeName = attribute.nodeName.toLowerCase();
- if (allowedAttributeList.includes(attrName)) {
- if (uriAttrs.has(attrName)) {
- return Boolean(SAFE_URL_PATTERN.test(attr.nodeValue) || DATA_URL_PATTERN.test(attr.nodeValue));
+ if (allowedAttributeList.includes(attributeName)) {
+ if (uriAttributes.has(attributeName)) {
+ return Boolean(SAFE_URL_PATTERN.test(attribute.nodeValue) || DATA_URL_PATTERN.test(attribute.nodeValue));
}
return true;
}
- const regExp = allowedAttributeList.filter(attrRegex => attrRegex instanceof RegExp); // Check if a regular expression validates the attribute.
+ const regExp = allowedAttributeList.filter(attributeRegex => attributeRegex instanceof RegExp); // Check if a regular expression validates the attribute.
for (let i = 0, len = regExp.length; i < len; i++) {
- if (regExp[i].test(attrName)) {
+ if (regExp[i].test(attributeName)) {
return true;
}
}
@@ -270,23 +267,22 @@
const domParser = new window.DOMParser();
const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html');
- const allowlistKeys = Object.keys(allowList);
const elements = [].concat(...createdDocument.body.querySelectorAll('*'));
for (let i = 0, len = elements.length; i < len; i++) {
- const el = elements[i];
- const elName = el.nodeName.toLowerCase();
+ const element = elements[i];
+ const elementName = element.nodeName.toLowerCase();
- if (!allowlistKeys.includes(elName)) {
- el.remove();
+ if (!Object.keys(allowList).includes(elementName)) {
+ element.remove();
continue;
}
- const attributeList = [].concat(...el.attributes);
- const allowedAttributes = [].concat(allowList['*'] || [], allowList[elName] || []);
- attributeList.forEach(attr => {
- if (!allowedAttribute(attr, allowedAttributes)) {
- el.removeAttribute(attr.nodeName);
+ const attributeList = [].concat(...element.attributes);
+ const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || []);
+ attributeList.forEach(attribute => {
+ if (!allowedAttribute(attribute, allowedAttributes)) {
+ element.removeAttribute(attribute.nodeName);
}
});
}
@@ -296,7 +292,7 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.2): tooltip.js
+ * Bootstrap (v5.1.2): tooltip.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -310,7 +306,6 @@
const DATA_KEY = 'bs.tooltip';
const EVENT_KEY = `.${DATA_KEY}`;
const CLASS_PREFIX = 'bs-tooltip';
- const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g');
const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']);
const DefaultType = {
animation: 'boolean',
@@ -375,6 +370,8 @@
const HOVER_STATE_SHOW = 'show';
const HOVER_STATE_OUT = 'out';
const SELECTOR_TOOLTIP_INNER = '.tooltip-inner';
+ const SELECTOR_MODAL = `.${CLASS_NAME_MODAL}`;
+ const EVENT_MODAL_HIDE = 'hide.bs.modal';
const TRIGGER_HOVER = 'hover';
const TRIGGER_FOCUS = 'focus';
const TRIGGER_CLICK = 'click';
@@ -385,7 +382,7 @@
* ------------------------------------------------------------------------
*/
- class Tooltip extends BaseComponent__default['default'] {
+ class Tooltip extends BaseComponent__default.default {
constructor(element, config) {
if (typeof Popper__namespace === 'undefined') {
throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)');
@@ -463,15 +460,13 @@
dispose() {
clearTimeout(this._timeout);
- EventHandler__default['default'].off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler);
+ EventHandler__default.default.off(this._element.closest(SELECTOR_MODAL), EVENT_MODAL_HIDE, this._hideModalHandler);
if (this.tip) {
this.tip.remove();
}
- if (this._popper) {
- this._popper.destroy();
- }
+ this._disposePopper();
super.dispose();
}
@@ -485,12 +480,21 @@
return;
}
- const showEvent = EventHandler__default['default'].trigger(this._element, this.constructor.Event.SHOW);
+ const showEvent = EventHandler__default.default.trigger(this._element, this.constructor.Event.SHOW);
const shadowRoot = findShadowRoot(this._element);
const isInTheDom = shadowRoot === null ? this._element.ownerDocument.documentElement.contains(this._element) : shadowRoot.contains(this._element);
if (showEvent.defaultPrevented || !isInTheDom) {
return;
+ } // A trick to recreate a tooltip in case a new title is given by using the NOT documented `data-bs-original-title`
+ // This will be removed later in favor of a `setContent` method
+
+
+ if (this.constructor.NAME === 'tooltip' && this.tip && this.getTitle() !== this.tip.querySelector(SELECTOR_TOOLTIP_INNER).innerHTML) {
+ this._disposePopper();
+
+ this.tip.remove();
+ this.tip = null;
}
const tip = this.getTipElement();
@@ -499,8 +503,6 @@
this._element.setAttribute('aria-describedby', tipId);
- this.setContent();
-
if (this._config.animation) {
tip.classList.add(CLASS_NAME_FADE);
}
@@ -514,11 +516,11 @@
const {
container
} = this._config;
- Data__default['default'].set(tip, this.constructor.DATA_KEY, this);
+ Data__default.default.set(tip, this.constructor.DATA_KEY, this);
if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
- container.appendChild(tip);
- EventHandler__default['default'].trigger(this._element, this.constructor.Event.INSERTED);
+ container.append(tip);
+ EventHandler__default.default.trigger(this._element, this.constructor.Event.INSERTED);
}
if (this._popper) {
@@ -528,7 +530,8 @@
}
tip.classList.add(CLASS_NAME_SHOW);
- const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : this._config.customClass;
+
+ const customClass = this._resolvePossibleFunction(this._config.customClass);
if (customClass) {
tip.classList.add(...customClass.split(' '));
@@ -540,14 +543,14 @@
if ('ontouchstart' in document.documentElement) {
[].concat(...document.body.children).forEach(element => {
- EventHandler__default['default'].on(element, 'mouseover', noop);
+ EventHandler__default.default.on(element, 'mouseover', noop);
});
}
const complete = () => {
const prevHoverState = this._hoverState;
this._hoverState = null;
- EventHandler__default['default'].trigger(this._element, this.constructor.Event.SHOWN);
+ EventHandler__default.default.trigger(this._element, this.constructor.Event.SHOWN);
if (prevHoverState === HOVER_STATE_OUT) {
this._leave(null, this);
@@ -579,16 +582,12 @@
this._element.removeAttribute('aria-describedby');
- EventHandler__default['default'].trigger(this._element, this.constructor.Event.HIDDEN);
-
- if (this._popper) {
- this._popper.destroy();
+ EventHandler__default.default.trigger(this._element, this.constructor.Event.HIDDEN);
- this._popper = null;
- }
+ this._disposePopper();
};
- const hideEvent = EventHandler__default['default'].trigger(this._element, this.constructor.Event.HIDE);
+ const hideEvent = EventHandler__default.default.trigger(this._element, this.constructor.Event.HIDE);
if (hideEvent.defaultPrevented) {
return;
@@ -598,7 +597,7 @@
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
- [].concat(...document.body.children).forEach(element => EventHandler__default['default'].off(element, 'mouseover', noop));
+ [].concat(...document.body.children).forEach(element => EventHandler__default.default.off(element, 'mouseover', noop));
}
this._activeTrigger[TRIGGER_CLICK] = false;
@@ -629,14 +628,27 @@
const element = document.createElement('div');
element.innerHTML = this._config.template;
- this.tip = element.children[0];
+ const tip = element.children[0];
+ this.setContent(tip);
+ tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW);
+ this.tip = tip;
return this.tip;
}
- setContent() {
- const tip = this.getTipElement();
- this.setElementContent(SelectorEngine__default['default'].findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle());
- tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW);
+ setContent(tip) {
+ this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TOOLTIP_INNER);
+ }
+
+ _sanitizeAndSetContent(template, content, selector) {
+ const templateElement = SelectorEngine__default.default.findOne(selector, template);
+
+ if (!content && templateElement) {
+ templateElement.remove();
+ return;
+ } // we use append for html objects to maintain js events
+
+
+ this.setElementContent(templateElement, content);
}
setElementContent(element, content) {
@@ -650,7 +662,7 @@
if (this._config.html) {
if (content.parentNode !== element) {
element.innerHTML = '';
- element.appendChild(content);
+ element.append(content);
}
} else {
element.textContent = content.textContent;
@@ -671,13 +683,9 @@
}
getTitle() {
- let title = this._element.getAttribute('data-bs-original-title');
+ const title = this._element.getAttribute('data-bs-original-title') || this._config.title;
- if (!title) {
- title = typeof this._config.title === 'function' ? this._config.title.call(this._element) : this._config.title;
- }
-
- return title;
+ return this._resolvePossibleFunction(title);
}
updateAttachment(attachment) {
@@ -694,15 +702,7 @@
_initializeOnDelegatedTarget(event, context) {
- const dataKey = this.constructor.DATA_KEY;
- context = context || Data__default['default'].get(event.delegateTarget, dataKey);
-
- if (!context) {
- context = new this.constructor(event.delegateTarget, this._getDelegateConfig());
- Data__default['default'].set(event.delegateTarget, dataKey, context);
- }
-
- return context;
+ return context || this.constructor.getOrCreateInstance(event.delegateTarget, this._getDelegateConfig());
}
_getOffset() {
@@ -721,6 +721,10 @@
return offset;
}
+ _resolvePossibleFunction(content) {
+ return typeof content === 'function' ? content.call(this._element) : content;
+ }
+
_getPopperConfig(attachment) {
const defaultBsPopperConfig = {
placement: attachment,
@@ -762,7 +766,7 @@
}
_addAttachmentClass(attachment) {
- this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`);
+ this.getTipElement().classList.add(`${this._getBasicClassPrefix()}-${this.updateAttachment(attachment)}`);
}
_getAttachment(placement) {
@@ -774,12 +778,12 @@
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));
}
});
@@ -789,7 +793,7 @@
}
};
- EventHandler__default['default'].on(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler);
+ EventHandler__default.default.on(this._element.closest(SELECTOR_MODAL), EVENT_MODAL_HIDE, this._hideModalHandler);
if (this._config.selector) {
this._config = { ...this._config,
@@ -881,7 +885,7 @@
}
_getConfig(config) {
- const dataAttributes = Manipulator__default['default'].getDataAttributes(this._element);
+ const dataAttributes = Manipulator__default.default.getDataAttributes(this._element);
Object.keys(dataAttributes).forEach(dataAttr => {
if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
delete dataAttributes[dataAttr];
@@ -920,26 +924,32 @@
_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];
- }
+ for (const key in this._config) {
+ if (this.constructor.Default[key] !== this._config[key]) {
+ config[key] = this._config[key];
}
- }
+ } // In the future can be replaced with:
+ // const keysWithDifferentValues = Object.entries(this._config).filter(entry => this.constructor.Default[entry[0]] !== this._config[entry[0]])
+ // `Object.fromEntries(keysWithDifferentValues)`
+
return config;
}
_cleanTipClass() {
const tip = this.getTipElement();
- const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX);
+ const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g');
+ const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex);
if (tabClass !== null && tabClass.length > 0) {
tabClass.map(token => token.trim()).forEach(tClass => tip.classList.remove(tClass));
}
}
+ _getBasicClassPrefix() {
+ return CLASS_PREFIX;
+ }
+
_handlePopperPlacementChange(popperData) {
const {
state
@@ -954,6 +964,14 @@
this._cleanTipClass();
this._addAttachmentClass(this._getAttachment(state.placement));
+ }
+
+ _disposePopper() {
+ if (this._popper) {
+ this._popper.destroy();
+
+ this._popper = null;
+ }
} // Static
@@ -984,5 +1002,5 @@
return Tooltip;
-})));
+}));
//# sourceMappingURL=tooltip.js.map