diff options
author | mjfriaza <mjfriaza@disroot.org> | 2022-05-17 13:44:06 +0200 |
---|---|---|
committer | mjfriaza <mjfriaza@disroot.org> | 2022-05-17 13:44:06 +0200 |
commit | a75c61d71efebf43713026200aa0f513bd7eef09 (patch) | |
tree | 909048adeaa329813e2530d43626ed3bd711bc25 /vendor/twbs/bootstrap/js/dist/tooltip.js | |
parent | 481ecee9e87342ca7a1217395085e95d1a3b61ea (diff) | |
parent | 0d0f73fb67bbfcc53058cefded85ac36f951c7a7 (diff) | |
download | volse-hubzilla-a75c61d71efebf43713026200aa0f513bd7eef09.tar.gz volse-hubzilla-a75c61d71efebf43713026200aa0f513bd7eef09.tar.bz2 volse-hubzilla-a75c61d71efebf43713026200aa0f513bd7eef09.zip |
Merge remote-tracking branch 'upstream/dev' into dev
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/tooltip.js')
-rw-r--r-- | vendor/twbs/bootstrap/js/dist/tooltip.js | 1138 |
1 files changed, 626 insertions, 512 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/tooltip.js b/vendor/twbs/bootstrap/js/dist/tooltip.js index ae6ec8ed7..883c8dbb0 100644 --- a/vendor/twbs/bootstrap/js/dist/tooltip.js +++ b/vendor/twbs/bootstrap/js/dist/tooltip.js @@ -1,63 +1,229 @@ /*! - * Bootstrap tooltip.js v4.6.0 (https://getbootstrap.com/) + * Bootstrap tooltip.js v5.1.3 (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('jquery'), require('popper.js'), require('./util.js')) : - typeof define === 'function' && define.amd ? define(['jquery', 'popper.js', './util'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global.jQuery, global.Popper, global.Util)); -}(this, (function ($, Popper, Util) { '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'; + + const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e }; + + function _interopNamespace(e) { + if (e && e.__esModule) return e; + const n = Object.create(null); + if (e) { + for (const k in e) { + if (k !== 'default') { + const d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: () => e[k] + }); + } + } + } + n.default = e; + return Object.freeze(n); + } - function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + 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); - var $__default = /*#__PURE__*/_interopDefaultLegacy($); - var Popper__default = /*#__PURE__*/_interopDefaultLegacy(Popper); - var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util); + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + const MAX_UID = 1000000; - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); + const toType = obj => { + if (obj === null || obj === undefined) { + return `${obj}`; } - } - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } + return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase(); + }; + /** + * -------------------------------------------------------------------------- + * Public Util Api + * -------------------------------------------------------------------------- + */ - function _extends() { - _extends = Object.assign || function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } + const getUID = prefix => { + do { + prefix += Math.floor(Math.random() * MAX_UID); + } while (document.getElementById(prefix)); + + return prefix; + }; + + const isElement = obj => { + if (!obj || typeof obj !== 'object') { + return false; + } + + 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 document.querySelector(obj); + } + + return null; + }; + + const typeCheckConfig = (componentName, config, configTypes) => { + Object.keys(configTypes).forEach(property => { + const expectedTypes = configTypes[property]; + const value = config[property]; + const valueType = value && isElement(value) ? 'element' : toType(value); + + if (!new RegExp(expectedTypes).test(valueType)) { + throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`); } + }); + }; - return target; - }; + const findShadowRoot = element => { + if (!document.documentElement.attachShadow) { + return null; + } // Can find the shadow root otherwise it'll return the document - return _extends.apply(this, arguments); - } + + if (typeof element.getRootNode === 'function') { + const root = element.getRootNode(); + return root instanceof ShadowRoot ? root : null; + } + + if (element instanceof ShadowRoot) { + return element; + } // when we don't find a shadow root + + + if (!element.parentNode) { + return null; + } + + return findShadowRoot(element.parentNode); + }; + + const noop = () => {}; + + const getjQuery = () => { + const { + jQuery + } = window; + + if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) { + return jQuery; + } + + return null; + }; + + const DOMContentLoadedCallbacks = []; + + const onDOMContentLoaded = callback => { + if (document.readyState === 'loading') { + // add listener on the first call when the document is in loading state + if (!DOMContentLoadedCallbacks.length) { + document.addEventListener('DOMContentLoaded', () => { + DOMContentLoadedCallbacks.forEach(callback => callback()); + }); + } + + DOMContentLoadedCallbacks.push(callback); + } else { + callback(); + } + }; + + const isRTL = () => document.documentElement.dir === 'rtl'; + + 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; + + $.fn[name].noConflict = () => { + $.fn[name] = JQUERY_NO_CONFLICT; + return plugin.jQueryInterface; + }; + } + }); + }; /** * -------------------------------------------------------------------------- - * Bootstrap (v4.6.0): tools/sanitizer.js + * Bootstrap (v5.1.3): util/sanitizer.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ - var uriAttrs = ['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href']; - var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i; - var DefaultWhitelist = { + 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 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|sms):|[^#&/:?]*(?:[#/?]|$))/i; + /** + * A pattern that matches safe data URLs. Only matches image, video and audio types. + * + * 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 = (attribute, allowedAttributeList) => { + const attributeName = attribute.nodeName.toLowerCase(); + + 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(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(attributeName)) { + return true; + } + } + + return false; + }; + + const DefaultAllowlist = { // Global attributes allowed on any supplied element below. '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN], a: ['target', 'href', 'title', 'rel'], @@ -90,47 +256,8 @@ u: [], ul: [] }; - /** - * 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 - */ - - var SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/gi; - /** - * 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 - */ - - var 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; - - function allowedAttribute(attr, allowedAttributeList) { - var attrName = attr.nodeName.toLowerCase(); - - if (allowedAttributeList.indexOf(attrName) !== -1) { - if (uriAttrs.indexOf(attrName) !== -1) { - return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN)); - } - - return true; - } - - var regExp = allowedAttributeList.filter(function (attrRegex) { - return attrRegex instanceof RegExp; - }); // Check if a regular expression validates the attribute. - - for (var i = 0, len = regExp.length; i < len; i++) { - if (attrName.match(regExp[i])) { - return true; - } - } - - return false; - } - - function sanitizeHtml(unsafeHtml, whiteList, sanitizeFn) { - if (unsafeHtml.length === 0) { + function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) { + if (!unsafeHtml.length) { return unsafeHtml; } @@ -138,53 +265,49 @@ return sanitizeFn(unsafeHtml); } - var domParser = new window.DOMParser(); - var createdDocument = domParser.parseFromString(unsafeHtml, 'text/html'); - var whitelistKeys = Object.keys(whiteList); - var elements = [].slice.call(createdDocument.body.querySelectorAll('*')); + const domParser = new window.DOMParser(); + const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html'); + const elements = [].concat(...createdDocument.body.querySelectorAll('*')); - var _loop = function _loop(i, len) { - var el = elements[i]; - var elName = el.nodeName.toLowerCase(); + for (let i = 0, len = elements.length; i < len; i++) { + const element = elements[i]; + const elementName = element.nodeName.toLowerCase(); - if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) { - el.parentNode.removeChild(el); - return "continue"; + if (!Object.keys(allowList).includes(elementName)) { + element.remove(); + continue; } - var attributeList = [].slice.call(el.attributes); - var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []); - attributeList.forEach(function (attr) { - if (!allowedAttribute(attr, whitelistedAttributes)) { - 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); } }); - }; - - for (var i = 0, len = elements.length; i < len; i++) { - var _ret = _loop(i); - - if (_ret === "continue") continue; } return createdDocument.body.innerHTML; } /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.1.3): tooltip.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ + /** * ------------------------------------------------------------------------ * Constants * ------------------------------------------------------------------------ */ - var NAME = 'tooltip'; - var VERSION = '4.6.0'; - var DATA_KEY = 'bs.tooltip'; - var EVENT_KEY = "." + DATA_KEY; - var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME]; - var CLASS_PREFIX = 'bs-tooltip'; - var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g'); - var DISALLOWED_ATTRIBUTES = ['sanitize', 'whiteList', 'sanitizeFn']; - var DefaultType = { + const NAME = 'tooltip'; + const DATA_KEY = 'bs.tooltip'; + const EVENT_KEY = `.${DATA_KEY}`; + const CLASS_PREFIX = 'bs-tooltip'; + const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']); + const DefaultType = { animation: 'boolean', template: 'string', title: '(string|element|function)', @@ -193,76 +316,79 @@ html: 'boolean', selector: '(string|boolean)', placement: '(string|function)', - offset: '(number|string|function)', + offset: '(array|string|function)', container: '(string|element|boolean)', - fallbackPlacement: '(string|array)', + fallbackPlacements: 'array', boundary: '(string|element)', customClass: '(string|function)', sanitize: 'boolean', sanitizeFn: '(null|function)', - whiteList: 'object', - popperConfig: '(null|object)' + allowList: 'object', + popperConfig: '(null|object|function)' }; - var AttachmentMap = { + const AttachmentMap = { AUTO: 'auto', TOP: 'top', - RIGHT: 'right', + RIGHT: isRTL() ? 'left' : 'right', BOTTOM: 'bottom', - LEFT: 'left' + LEFT: isRTL() ? 'right' : 'left' }; - var Default = { + const Default = { animation: true, - template: '<div class="tooltip" role="tooltip">' + '<div class="arrow"></div>' + '<div class="tooltip-inner"></div></div>', + template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div>' + '</div>', trigger: 'hover focus', title: '', delay: 0, html: false, selector: false, placement: 'top', - offset: 0, + offset: [0, 0], container: false, - fallbackPlacement: 'flip', - boundary: 'scrollParent', + fallbackPlacements: ['top', 'right', 'bottom', 'left'], + boundary: 'clippingParents', customClass: '', sanitize: true, sanitizeFn: null, - whiteList: DefaultWhitelist, + allowList: DefaultAllowlist, popperConfig: null }; - var HOVER_STATE_SHOW = 'show'; - var HOVER_STATE_OUT = 'out'; - var Event = { - HIDE: "hide" + EVENT_KEY, - HIDDEN: "hidden" + EVENT_KEY, - SHOW: "show" + EVENT_KEY, - SHOWN: "shown" + EVENT_KEY, - INSERTED: "inserted" + EVENT_KEY, - CLICK: "click" + EVENT_KEY, - FOCUSIN: "focusin" + EVENT_KEY, - FOCUSOUT: "focusout" + EVENT_KEY, - MOUSEENTER: "mouseenter" + EVENT_KEY, - MOUSELEAVE: "mouseleave" + EVENT_KEY + const Event = { + HIDE: `hide${EVENT_KEY}`, + HIDDEN: `hidden${EVENT_KEY}`, + SHOW: `show${EVENT_KEY}`, + SHOWN: `shown${EVENT_KEY}`, + INSERTED: `inserted${EVENT_KEY}`, + CLICK: `click${EVENT_KEY}`, + FOCUSIN: `focusin${EVENT_KEY}`, + FOCUSOUT: `focusout${EVENT_KEY}`, + MOUSEENTER: `mouseenter${EVENT_KEY}`, + MOUSELEAVE: `mouseleave${EVENT_KEY}` }; - var CLASS_NAME_FADE = 'fade'; - var CLASS_NAME_SHOW = 'show'; - var SELECTOR_TOOLTIP_INNER = '.tooltip-inner'; - var SELECTOR_ARROW = '.arrow'; - var TRIGGER_HOVER = 'hover'; - var TRIGGER_FOCUS = 'focus'; - var TRIGGER_CLICK = 'click'; - var TRIGGER_MANUAL = 'manual'; + const CLASS_NAME_FADE = 'fade'; + const CLASS_NAME_MODAL = 'modal'; + const CLASS_NAME_SHOW = 'show'; + 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'; + const TRIGGER_MANUAL = 'manual'; /** * ------------------------------------------------------------------------ * Class Definition * ------------------------------------------------------------------------ */ - var Tooltip = /*#__PURE__*/function () { - function Tooltip(element, config) { - if (typeof Popper__default['default'] === 'undefined') { + 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)'); - } // private + } + super(element); // private this._isEnabled = true; this._timeout = 0; @@ -270,42 +396,49 @@ this._activeTrigger = {}; this._popper = null; // Protected - this.element = element; - this.config = this._getConfig(config); + this._config = this._getConfig(config); this.tip = null; this._setListeners(); } // Getters - var _proto = Tooltip.prototype; + static get Default() { + return Default; + } + + static get NAME() { + return NAME; + } + + static get Event() { + return Event; + } - // Public - _proto.enable = function enable() { + static get DefaultType() { + return DefaultType; + } // Public + + + enable() { this._isEnabled = true; - }; + } - _proto.disable = function disable() { + disable() { this._isEnabled = false; - }; + } - _proto.toggleEnabled = function toggleEnabled() { + toggleEnabled() { this._isEnabled = !this._isEnabled; - }; + } - _proto.toggle = function toggle(event) { + toggle(event) { if (!this._isEnabled) { return; } if (event) { - var dataKey = this.constructor.DATA_KEY; - var context = $__default['default'](event.currentTarget).data(dataKey); - - if (!context) { - context = new this.constructor(event.currentTarget, this._getDelegateConfig()); - $__default['default'](event.currentTarget).data(dataKey, context); - } + const context = this._initializeOnDelegatedTarget(event); context._activeTrigger.click = !context._activeTrigger.click; @@ -315,7 +448,7 @@ context._leave(null, context); } } else { - if ($__default['default'](this.getTipElement()).hasClass(CLASS_NAME_SHOW)) { + if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) { this._leave(null, this); return; @@ -323,348 +456,379 @@ this._enter(null, this); } - }; + } - _proto.dispose = function dispose() { + dispose() { clearTimeout(this._timeout); - $__default['default'].removeData(this.element, this.constructor.DATA_KEY); - $__default['default'](this.element).off(this.constructor.EVENT_KEY); - $__default['default'](this.element).closest('.modal').off('hide.bs.modal', this._hideModalHandler); + EventHandler__default.default.off(this._element.closest(SELECTOR_MODAL), EVENT_MODAL_HIDE, this._hideModalHandler); if (this.tip) { - $__default['default'](this.tip).remove(); + this.tip.remove(); } - this._isEnabled = null; - this._timeout = null; - this._hoverState = null; - this._activeTrigger = null; + this._disposePopper(); - if (this._popper) { - this._popper.destroy(); + super.dispose(); + } + + show() { + if (this._element.style.display === 'none') { + throw new Error('Please use show on visible elements'); } - this._popper = null; - this.element = null; - this.config = null; - this.tip = null; - }; + if (!(this.isWithContent() && this._isEnabled)) { + return; + } - _proto.show = function show() { - var _this = this; + 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 ($__default['default'](this.element).css('display') === 'none') { - throw new Error('Please use show on visible elements'); - } + 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 - var showEvent = $__default['default'].Event(this.constructor.Event.SHOW); - if (this.isWithContent() && this._isEnabled) { - $__default['default'](this.element).trigger(showEvent); - var shadowRoot = Util__default['default'].findShadowRoot(this.element); - var isInTheDom = $__default['default'].contains(shadowRoot !== null ? shadowRoot : this.element.ownerDocument.documentElement, this.element); + if (this.constructor.NAME === 'tooltip' && this.tip && this.getTitle() !== this.tip.querySelector(SELECTOR_TOOLTIP_INNER).innerHTML) { + this._disposePopper(); - if (showEvent.isDefaultPrevented() || !isInTheDom) { - return; - } + this.tip.remove(); + this.tip = null; + } - var tip = this.getTipElement(); - var tipId = Util__default['default'].getUID(this.constructor.NAME); - tip.setAttribute('id', tipId); - this.element.setAttribute('aria-describedby', tipId); - this.setContent(); + const tip = this.getTipElement(); + const tipId = getUID(this.constructor.NAME); + tip.setAttribute('id', tipId); - if (this.config.animation) { - $__default['default'](tip).addClass(CLASS_NAME_FADE); - } + this._element.setAttribute('aria-describedby', tipId); - var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement; + if (this._config.animation) { + tip.classList.add(CLASS_NAME_FADE); + } - var attachment = this._getAttachment(placement); + const placement = typeof this._config.placement === 'function' ? this._config.placement.call(this, tip, this._element) : this._config.placement; - this.addAttachmentClass(attachment); + const attachment = this._getAttachment(placement); - var container = this._getContainer(); + this._addAttachmentClass(attachment); - $__default['default'](tip).data(this.constructor.DATA_KEY, this); + const { + container + } = this._config; + Data__default.default.set(tip, this.constructor.DATA_KEY, this); - if (!$__default['default'].contains(this.element.ownerDocument.documentElement, this.tip)) { - $__default['default'](tip).appendTo(container); - } + if (!this._element.ownerDocument.documentElement.contains(this.tip)) { + container.append(tip); + EventHandler__default.default.trigger(this._element, this.constructor.Event.INSERTED); + } - $__default['default'](this.element).trigger(this.constructor.Event.INSERTED); - this._popper = new Popper__default['default'](this.element, tip, this._getPopperConfig(attachment)); - $__default['default'](tip).addClass(CLASS_NAME_SHOW); - $__default['default'](tip).addClass(this.config.customClass); // If this is a touch-enabled device we add extra - // empty mouseover listeners to the body's immediate children; - // only needed because of broken event delegation on iOS - // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html + if (this._popper) { + this._popper.update(); + } else { + this._popper = Popper__namespace.createPopper(this._element, tip, this._getPopperConfig(attachment)); + } - if ('ontouchstart' in document.documentElement) { - $__default['default'](document.body).children().on('mouseover', null, $__default['default'].noop); - } + tip.classList.add(CLASS_NAME_SHOW); - var complete = function complete() { - if (_this.config.animation) { - _this._fixTransition(); - } + const customClass = this._resolvePossibleFunction(this._config.customClass); - var prevHoverState = _this._hoverState; - _this._hoverState = null; - $__default['default'](_this.element).trigger(_this.constructor.Event.SHOWN); + if (customClass) { + tip.classList.add(...customClass.split(' ')); + } // If this is a touch-enabled device we add extra + // empty mouseover listeners to the body's immediate children; + // only needed because of broken event delegation on iOS + // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html - if (prevHoverState === HOVER_STATE_OUT) { - _this._leave(null, _this); - } - }; - if ($__default['default'](this.tip).hasClass(CLASS_NAME_FADE)) { - var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this.tip); - $__default['default'](this.tip).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); - } else { - complete(); - } + if ('ontouchstart' in document.documentElement) { + [].concat(...document.body.children).forEach(element => { + EventHandler__default.default.on(element, 'mouseover', noop); + }); } - }; - _proto.hide = function hide(callback) { - var _this2 = this; + const complete = () => { + const prevHoverState = this._hoverState; + this._hoverState = null; + EventHandler__default.default.trigger(this._element, this.constructor.Event.SHOWN); - var tip = this.getTipElement(); - var hideEvent = $__default['default'].Event(this.constructor.Event.HIDE); - - var complete = function complete() { - if (_this2._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { - tip.parentNode.removeChild(tip); + if (prevHoverState === HOVER_STATE_OUT) { + this._leave(null, this); } + }; - _this2._cleanTipClass(); + const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE); - _this2.element.removeAttribute('aria-describedby'); + this._queueCallback(complete, this.tip, isAnimated); + } - $__default['default'](_this2.element).trigger(_this2.constructor.Event.HIDDEN); + hide() { + if (!this._popper) { + return; + } - if (_this2._popper !== null) { - _this2._popper.destroy(); + const tip = this.getTipElement(); + + const complete = () => { + if (this._isWithActiveTrigger()) { + return; } - if (callback) { - callback(); + if (this._hoverState !== HOVER_STATE_SHOW) { + tip.remove(); } + + this._cleanTipClass(); + + this._element.removeAttribute('aria-describedby'); + + EventHandler__default.default.trigger(this._element, this.constructor.Event.HIDDEN); + + this._disposePopper(); }; - $__default['default'](this.element).trigger(hideEvent); + const hideEvent = EventHandler__default.default.trigger(this._element, this.constructor.Event.HIDE); - if (hideEvent.isDefaultPrevented()) { + if (hideEvent.defaultPrevented) { return; } - $__default['default'](tip).removeClass(CLASS_NAME_SHOW); // If this is a touch-enabled device we remove the extra + tip.classList.remove(CLASS_NAME_SHOW); // If this is a touch-enabled device we remove the extra // empty mouseover listeners we added for iOS support if ('ontouchstart' in document.documentElement) { - $__default['default'](document.body).children().off('mouseover', null, $__default['default'].noop); + [].concat(...document.body.children).forEach(element => EventHandler__default.default.off(element, 'mouseover', noop)); } 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 ($__default['default'](this.tip).hasClass(CLASS_NAME_FADE)) { - var transitionDuration = Util__default['default'].getTransitionDurationFromElement(tip); - $__default['default'](tip).one(Util__default['default'].TRANSITION_END, complete).emulateTransitionEnd(transitionDuration); - } else { - complete(); - } + this._queueCallback(complete, this.tip, isAnimated); this._hoverState = ''; - }; + } - _proto.update = function update() { + update() { if (this._popper !== null) { - this._popper.scheduleUpdate(); + this._popper.update(); } } // Protected - ; - _proto.isWithContent = function isWithContent() { + + isWithContent() { return Boolean(this.getTitle()); - }; + } - _proto.addAttachmentClass = function addAttachmentClass(attachment) { - $__default['default'](this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment); - }; + getTipElement() { + if (this.tip) { + return this.tip; + } - _proto.getTipElement = function getTipElement() { - this.tip = this.tip || $__default['default'](this.config.template)[0]; + const element = document.createElement('div'); + element.innerHTML = this._config.template; + const tip = element.children[0]; + this.setContent(tip); + tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW); + this.tip = tip; return this.tip; - }; - - _proto.setContent = function setContent() { - var tip = this.getTipElement(); - this.setElementContent($__default['default'](tip.querySelectorAll(SELECTOR_TOOLTIP_INNER)), this.getTitle()); - $__default['default'](tip).removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW); - }; - - _proto.setElementContent = function setElementContent($element, content) { - if (typeof content === 'object' && (content.nodeType || content.jquery)) { - // Content is a DOM node or a jQuery - if (this.config.html) { - if (!$__default['default'](content).parent().is($element)) { - $element.empty().append(content); + } + + 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) { + if (element === null) { + return; + } + + if (isElement(content)) { + content = getElement(content); // content is a DOM node or a jQuery + + if (this._config.html) { + if (content.parentNode !== element) { + element.innerHTML = ''; + element.append(content); } } else { - $element.text($__default['default'](content).text()); + element.textContent = content.textContent; } return; } - if (this.config.html) { - if (this.config.sanitize) { - content = sanitizeHtml(content, this.config.whiteList, this.config.sanitizeFn); + if (this._config.html) { + if (this._config.sanitize) { + content = sanitizeHtml(content, this._config.allowList, this._config.sanitizeFn); } - $element.html(content); + element.innerHTML = content; } else { - $element.text(content); + element.textContent = content; } - }; + } + + getTitle() { + const title = this._element.getAttribute('data-bs-original-title') || this._config.title; + + return this._resolvePossibleFunction(title); + } - _proto.getTitle = function getTitle() { - var title = this.element.getAttribute('data-original-title'); + updateAttachment(attachment) { + if (attachment === 'right') { + return 'end'; + } - if (!title) { - title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title; + if (attachment === 'left') { + return 'start'; } - return title; + return attachment; } // Private - ; - _proto._getPopperConfig = function _getPopperConfig(attachment) { - var _this3 = this; - var defaultBsConfig = { - placement: attachment, - modifiers: { - offset: this._getOffset(), - flip: { - behavior: this.config.fallbackPlacement - }, - arrow: { - element: SELECTOR_ARROW - }, - preventOverflow: { - boundariesElement: this.config.boundary - } - }, - onCreate: function onCreate(data) { - if (data.originalPlacement !== data.placement) { - _this3._handlePopperPlacementChange(data); - } - }, - onUpdate: function onUpdate(data) { - return _this3._handlePopperPlacementChange(data); - } - }; - return _extends({}, defaultBsConfig, this.config.popperConfig); - }; + _initializeOnDelegatedTarget(event, context) { + return context || this.constructor.getOrCreateInstance(event.delegateTarget, this._getDelegateConfig()); + } - _proto._getOffset = function _getOffset() { - var _this4 = this; + _getOffset() { + const { + offset + } = this._config; - var offset = {}; + if (typeof offset === 'string') { + return offset.split(',').map(val => Number.parseInt(val, 10)); + } - if (typeof this.config.offset === 'function') { - offset.fn = function (data) { - data.offsets = _extends({}, data.offsets, _this4.config.offset(data.offsets, _this4.element) || {}); - return data; - }; - } else { - offset.offset = this.config.offset; + if (typeof offset === 'function') { + return popperData => offset(popperData, this._element); } return offset; - }; + } - _proto._getContainer = function _getContainer() { - if (this.config.container === false) { - return document.body; - } + _resolvePossibleFunction(content) { + return typeof content === 'function' ? content.call(this._element) : content; + } - if (Util__default['default'].isElement(this.config.container)) { - return $__default['default'](this.config.container); - } + _getPopperConfig(attachment) { + const defaultBsPopperConfig = { + placement: attachment, + modifiers: [{ + name: 'flip', + options: { + fallbackPlacements: this._config.fallbackPlacements + } + }, { + name: 'offset', + options: { + offset: this._getOffset() + } + }, { + name: 'preventOverflow', + options: { + boundary: this._config.boundary + } + }, { + name: 'arrow', + options: { + element: `.${this.constructor.NAME}-arrow` + } + }, { + name: 'onChange', + enabled: true, + phase: 'afterWrite', + fn: data => this._handlePopperPlacementChange(data) + }], + onFirstUpdate: data => { + if (data.options.placement !== data.placement) { + this._handlePopperPlacementChange(data); + } + } + }; + return { ...defaultBsPopperConfig, + ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig) + }; + } - return $__default['default'](document).find(this.config.container); - }; + _addAttachmentClass(attachment) { + this.getTipElement().classList.add(`${this._getBasicClassPrefix()}-${this.updateAttachment(attachment)}`); + } - _proto._getAttachment = function _getAttachment(placement) { + _getAttachment(placement) { return AttachmentMap[placement.toUpperCase()]; - }; + } - _proto._setListeners = function _setListeners() { - var _this5 = this; + _setListeners() { + const triggers = this._config.trigger.split(' '); - var triggers = this.config.trigger.split(' '); - triggers.forEach(function (trigger) { + triggers.forEach(trigger => { if (trigger === 'click') { - $__default['default'](_this5.element).on(_this5.constructor.Event.CLICK, _this5.config.selector, function (event) { - return _this5.toggle(event); - }); + EventHandler__default.default.on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event)); } else if (trigger !== TRIGGER_MANUAL) { - var eventIn = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSEENTER : _this5.constructor.Event.FOCUSIN; - var eventOut = trigger === TRIGGER_HOVER ? _this5.constructor.Event.MOUSELEAVE : _this5.constructor.Event.FOCUSOUT; - $__default['default'](_this5.element).on(eventIn, _this5.config.selector, function (event) { - return _this5._enter(event); - }).on(eventOut, _this5.config.selector, function (event) { - return _this5._leave(event); - }); + 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)); } }); - this._hideModalHandler = function () { - if (_this5.element) { - _this5.hide(); + this._hideModalHandler = () => { + if (this._element) { + this.hide(); } }; - $__default['default'](this.element).closest('.modal').on('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 = _extends({}, this.config, { + if (this._config.selector) { + this._config = { ...this._config, trigger: 'manual', selector: '' - }); + }; } else { this._fixTitle(); } - }; + } - _proto._fixTitle = function _fixTitle() { - var titleType = typeof this.element.getAttribute('data-original-title'); + _fixTitle() { + const title = this._element.getAttribute('title'); - if (this.element.getAttribute('title') || titleType !== 'string') { - this.element.setAttribute('data-original-title', this.element.getAttribute('title') || ''); - this.element.setAttribute('title', ''); - } - }; + const originalTitleType = typeof this._element.getAttribute('data-bs-original-title'); + + if (title || originalTitleType !== 'string') { + this._element.setAttribute('data-bs-original-title', title || ''); - _proto._enter = function _enter(event, context) { - var dataKey = this.constructor.DATA_KEY; - context = context || $__default['default'](event.currentTarget).data(dataKey); + if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) { + this._element.setAttribute('aria-label', title); + } - if (!context) { - context = new this.constructor(event.currentTarget, this._getDelegateConfig()); - $__default['default'](event.currentTarget).data(dataKey, context); + this._element.setAttribute('title', ''); } + } + + _enter(event, context) { + context = this._initializeOnDelegatedTarget(event, context); if (event) { context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true; } - if ($__default['default'](context.getTipElement()).hasClass(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) { + if (context.getTipElement().classList.contains(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) { context._hoverState = HOVER_STATE_SHOW; return; } @@ -672,29 +836,23 @@ 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; } - context._timeout = setTimeout(function () { + context._timeout = setTimeout(() => { if (context._hoverState === HOVER_STATE_SHOW) { context.show(); } - }, context.config.delay.show); - }; - - _proto._leave = function _leave(event, context) { - var dataKey = this.constructor.DATA_KEY; - context = context || $__default['default'](event.currentTarget).data(dataKey); + }, context._config.delay.show); + } - if (!context) { - context = new this.constructor(event.currentTarget, this._getDelegateConfig()); - $__default['default'](event.currentTarget).data(dataKey, context); - } + _leave(event, context) { + context = this._initializeOnDelegatedTarget(event, context); if (event) { - context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = false; + context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = context._element.contains(event.relatedTarget); } if (context._isWithActiveTrigger()) { @@ -704,36 +862,40 @@ 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; } - context._timeout = setTimeout(function () { + context._timeout = setTimeout(() => { if (context._hoverState === HOVER_STATE_OUT) { context.hide(); } - }, context.config.delay.hide); - }; + }, context._config.delay.hide); + } - _proto._isWithActiveTrigger = function _isWithActiveTrigger() { - for (var trigger in this._activeTrigger) { + _isWithActiveTrigger() { + for (const trigger in this._activeTrigger) { if (this._activeTrigger[trigger]) { return true; } } return false; - }; + } - _proto._getConfig = function _getConfig(config) { - var dataAttributes = $__default['default'](this.element).data(); - Object.keys(dataAttributes).forEach(function (dataAttr) { - if (DISALLOWED_ATTRIBUTES.indexOf(dataAttr) !== -1) { + _getConfig(config) { + const dataAttributes = Manipulator__default.default.getDataAttributes(this._element); + Object.keys(dataAttributes).forEach(dataAttr => { + if (DISALLOWED_ATTRIBUTES.has(dataAttr)) { delete dataAttributes[dataAttr]; } }); - config = _extends({}, this.constructor.Default, dataAttributes, typeof config === 'object' && config ? config : {}); + 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 = { @@ -750,143 +912,95 @@ config.content = config.content.toString(); } - Util__default['default'].typeCheckConfig(NAME, config, this.constructor.DefaultType); + typeCheckConfig(NAME, config, this.constructor.DefaultType); if (config.sanitize) { - config.template = sanitizeHtml(config.template, config.whiteList, config.sanitizeFn); + config.template = sanitizeHtml(config.template, config.allowList, config.sanitizeFn); } return config; - }; + } - _proto._getDelegateConfig = function _getDelegateConfig() { - var config = {}; + _getDelegateConfig() { + const config = {}; - if (this.config) { - for (var 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; - }; + } - _proto._cleanTipClass = function _cleanTipClass() { - var $tip = $__default['default'](this.getTipElement()); - var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX); + _cleanTipClass() { + const tip = this.getTipElement(); + const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g'); + const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex); - if (tabClass !== null && tabClass.length) { - $tip.removeClass(tabClass.join('')); + if (tabClass !== null && tabClass.length > 0) { + tabClass.map(token => token.trim()).forEach(tClass => tip.classList.remove(tClass)); } - }; - - _proto._handlePopperPlacementChange = function _handlePopperPlacementChange(popperData) { - this.tip = popperData.instance.popper; - - this._cleanTipClass(); + } - this.addAttachmentClass(this._getAttachment(popperData.placement)); - }; + _getBasicClassPrefix() { + return CLASS_PREFIX; + } - _proto._fixTransition = function _fixTransition() { - var tip = this.getTipElement(); - var initConfigAnimation = this.config.animation; + _handlePopperPlacementChange(popperData) { + const { + state + } = popperData; - if (tip.getAttribute('x-placement') !== null) { + if (!state) { return; } - $__default['default'](tip).removeClass(CLASS_NAME_FADE); - this.config.animation = false; - this.hide(); - this.show(); - this.config.animation = initConfigAnimation; - } // Static - ; + this.tip = state.elements.popper; - Tooltip._jQueryInterface = function _jQueryInterface(config) { - return this.each(function () { - var $element = $__default['default'](this); - var data = $element.data(DATA_KEY); + this._cleanTipClass(); - var _config = typeof config === 'object' && config; + this._addAttachmentClass(this._getAttachment(state.placement)); + } - if (!data && /dispose|hide/.test(config)) { - return; - } + _disposePopper() { + if (this._popper) { + this._popper.destroy(); - if (!data) { - data = new Tooltip(this, _config); - $element.data(DATA_KEY, data); - } + this._popper = null; + } + } // Static + + + static jQueryInterface(config) { + return this.each(function () { + const data = Tooltip.getOrCreateInstance(this, config); if (typeof config === 'string') { if (typeof data[config] === 'undefined') { - throw new TypeError("No method named \"" + config + "\""); + throw new TypeError(`No method named "${config}"`); } data[config](); } }); - }; - - _createClass(Tooltip, null, [{ - key: "VERSION", - get: function get() { - return VERSION; - } - }, { - key: "Default", - get: function get() { - return Default; - } - }, { - key: "NAME", - get: function get() { - return NAME; - } - }, { - key: "DATA_KEY", - get: function get() { - return DATA_KEY; - } - }, { - key: "Event", - get: function get() { - return Event; - } - }, { - key: "EVENT_KEY", - get: function get() { - return EVENT_KEY; - } - }, { - key: "DefaultType", - get: function get() { - return DefaultType; - } - }]); - - return Tooltip; - }(); + } + + } /** * ------------------------------------------------------------------------ * jQuery * ------------------------------------------------------------------------ + * add .Tooltip to jQuery only if jQuery is present */ - $__default['default'].fn[NAME] = Tooltip._jQueryInterface; - $__default['default'].fn[NAME].Constructor = Tooltip; - - $__default['default'].fn[NAME].noConflict = function () { - $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT; - return Tooltip._jQueryInterface; - }; + defineJQueryPlugin(Tooltip); return Tooltip; -}))); +})); //# sourceMappingURL=tooltip.js.map |