From f3b4308cb59bf4b21ff186f8479c82239446d139 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 7 Jun 2021 12:56:27 +0200 Subject: upgrade to bootstrap 5.0.1 and first batch of fixes --- vendor/twbs/bootstrap/js/dist/tooltip.js | 1085 ++++++++++++++++-------------- 1 file changed, 591 insertions(+), 494 deletions(-) (limited to 'vendor/twbs/bootstrap/js/dist/tooltip.js') diff --git a/vendor/twbs/bootstrap/js/dist/tooltip.js b/vendor/twbs/bootstrap/js/dist/tooltip.js index ae6ec8ed7..91a235d86 100644 --- a/vendor/twbs/bootstrap/js/dist/tooltip.js +++ b/vendor/twbs/bootstrap/js/dist/tooltip.js @@ -1,63 +1,223 @@ /*! - * Bootstrap tooltip.js v4.6.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('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/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 }; } - var $__default = /*#__PURE__*/_interopDefaultLegacy($); - var Popper__default = /*#__PURE__*/_interopDefaultLegacy(Popper); - var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util); - - 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); + function _interopNamespace(e) { + if (e && e.__esModule) return e; + var n = Object.create(null); + if (e) { + Object.keys(e).forEach(function (k) { + if (k !== 'default') { + var d = Object.getOwnPropertyDescriptor(e, k); + Object.defineProperty(n, k, d.get ? d : { + enumerable: true, + get: function () { + return e[k]; + } + }); + } + }); } + n['default'] = e; + return Object.freeze(n); } - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } + 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); - function _extends() { - _extends = Object.assign || function (target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i]; + /** + * -------------------------------------------------------------------------- + * Bootstrap (v5.0.1): util/index.js + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) + * -------------------------------------------------------------------------- + */ - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } + const MAX_UID = 1000000; + + const toType = obj => { + if (obj === null || obj === undefined) { + return `${obj}`; + } + + return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase(); + }; + /** + * -------------------------------------------------------------------------- + * Public Util Api + * -------------------------------------------------------------------------- + */ + + + 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 SelectorEngine__default['default'].findOne(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 onDOMContentLoaded = callback => { + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', 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.0.1): 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 uriAttrs = 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 + */ + + const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|$))/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 + */ + + 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(); + + if (allowedAttributeList.includes(attrName)) { + if (uriAttrs.has(attrName)) { + return Boolean(SAFE_URL_PATTERN.test(attr.nodeValue) || DATA_URL_PATTERN.test(attr.nodeValue)); + } + + return true; + } + + const regExp = allowedAttributeList.filter(attrRegex => attrRegex 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)) { + 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 +250,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 +259,51 @@ 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 allowlistKeys = Object.keys(allowList); + 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 el = elements[i]; + const elName = el.nodeName.toLowerCase(); - if (whitelistKeys.indexOf(el.nodeName.toLowerCase()) === -1) { + if (!allowlistKeys.includes(elName)) { el.parentNode.removeChild(el); - return "continue"; + continue; } - var attributeList = [].slice.call(el.attributes); - var whitelistedAttributes = [].concat(whiteList['*'] || [], whiteList[elName] || []); - attributeList.forEach(function (attr) { - if (!allowedAttribute(attr, whitelistedAttributes)) { + const attributeList = [].concat(...el.attributes); + const allowedAttributes = [].concat(allowList['*'] || [], allowList[elName] || []); + attributeList.forEach(attr => { + if (!allowedAttribute(attr, allowedAttributes)) { el.removeAttribute(attr.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.0.1): 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 BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g'); + const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']); + const DefaultType = { animation: 'boolean', template: 'string', title: '(string|element|function)', @@ -193,76 +312,77 @@ 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: '', + template: '', 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 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 +390,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; + } - // Public - _proto.enable = function enable() { + static get Event() { + return Event; + } + + 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 +442,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 +450,372 @@ 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(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler); - if (this.tip) { - $__default['default'](this.tip).remove(); + if (this.tip && this.tip.parentNode) { + 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.element = null; - this.config = null; - this.tip = null; - }; - - _proto.show = function show() { - var _this = this; + super.dispose(); + } - if ($__default['default'](this.element).css('display') === 'none') { + show() { + if (this._element.style.display === 'none') { throw new Error('Please use show on visible elements'); } - var showEvent = $__default['default'].Event(this.constructor.Event.SHOW); + if (!(this.isWithContent() && this._isEnabled)) { + return; + } - 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); + 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.isDefaultPrevented() || !isInTheDom) { - return; - } + if (showEvent.defaultPrevented || !isInTheDom) { + return; + } - 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; + this.setContent(); - var attachment = this._getAttachment(placement); + if (this._config.animation) { + tip.classList.add(CLASS_NAME_FADE); + } - this.addAttachmentClass(attachment); + const placement = typeof this._config.placement === 'function' ? this._config.placement.call(this, tip, this._element) : this._config.placement; - var container = this._getContainer(); + const attachment = this._getAttachment(placement); - $__default['default'](tip).data(this.constructor.DATA_KEY, this); + this._addAttachmentClass(attachment); - if (!$__default['default'].contains(this.element.ownerDocument.documentElement, this.tip)) { - $__default['default'](tip).appendTo(container); - } + const { + container + } = this._config; + Data__default['default'].set(tip, this.constructor.DATA_KEY, this); - $__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._element.ownerDocument.documentElement.contains(this.tip)) { + container.appendChild(tip); + EventHandler__default['default'].trigger(this._element, this.constructor.Event.INSERTED); + } - if ('ontouchstart' in document.documentElement) { - $__default['default'](document.body).children().on('mouseover', null, $__default['default'].noop); - } + if (this._popper) { + this._popper.update(); + } else { + this._popper = Popper__namespace.createPopper(this._element, tip, this._getPopperConfig(attachment)); + } - var complete = function complete() { - if (_this.config.animation) { - _this._fixTransition(); - } + tip.classList.add(CLASS_NAME_SHOW); + const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : 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); + }); + } + + const complete = () => { + const prevHoverState = this._hoverState; + this._hoverState = null; + EventHandler__default['default'].trigger(this._element, this.constructor.Event.SHOWN); + + if (prevHoverState === HOVER_STATE_OUT) { + this._leave(null, this); } + }; + + const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE); + + this._queueCallback(complete, this.tip, isAnimated); + } + + hide() { + if (!this._popper) { + return; } - }; - _proto.hide = function hide(callback) { - var _this2 = this; + const tip = this.getTipElement(); - var tip = this.getTipElement(); - var hideEvent = $__default['default'].Event(this.constructor.Event.HIDE); + const complete = () => { + if (this._isWithActiveTrigger()) { + return; + } - var complete = function complete() { - if (_this2._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { + if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { tip.parentNode.removeChild(tip); } - _this2._cleanTipClass(); + this._cleanTipClass(); - _this2.element.removeAttribute('aria-describedby'); + this._element.removeAttribute('aria-describedby'); - $__default['default'](_this2.element).trigger(_this2.constructor.Event.HIDDEN); + EventHandler__default['default'].trigger(this._element, this.constructor.Event.HIDDEN); - if (_this2._popper !== null) { - _this2._popper.destroy(); - } + if (this._popper) { + this._popper.destroy(); - if (callback) { - callback(); + this._popper = null; } }; - $__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; + this.tip = element.children[0]; 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() { + 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); + } + + 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.appendChild(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; } - }; + } - _proto.getTitle = function getTitle() { - var title = this.element.getAttribute('data-original-title'); + getTitle() { + 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; - } // Private - ; + } - _proto._getPopperConfig = function _getPopperConfig(attachment) { - var _this3 = this; + updateAttachment(attachment) { + if (attachment === 'right') { + return 'end'; + } - 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); - }; + if (attachment === 'left') { + return 'start'; + } - _proto._getOffset = function _getOffset() { - var _this4 = this; + return attachment; + } // Private - var offset = {}; - 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; + _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 offset; - }; + return context; + } + + _getOffset() { + const { + offset + } = this._config; - _proto._getContainer = function _getContainer() { - if (this.config.container === false) { - return document.body; + if (typeof offset === 'string') { + return offset.split(',').map(val => Number.parseInt(val, 10)); } - if (Util__default['default'].isElement(this.config.container)) { - return $__default['default'](this.config.container); + if (typeof offset === 'function') { + return popperData => offset(popperData, this._element); } - return $__default['default'](document).find(this.config.container); - }; + return offset; + } - _proto._getAttachment = function _getAttachment(placement) { + _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) + }; + } + + _addAttachmentClass(attachment) { + this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`); + } + + _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(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', 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'); - _proto._enter = function _enter(event, context) { - var dataKey = this.constructor.DATA_KEY; - context = context || $__default['default'](event.currentTarget).data(dataKey); + if (title || originalTitleType !== 'string') { + this._element.setAttribute('data-bs-original-title', title || ''); - if (!context) { - context = new this.constructor(event.currentTarget, this._getDelegateConfig()); - $__default['default'](event.currentTarget).data(dataKey, context); + if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) { + this._element.setAttribute('aria-label', title); + } + + 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 +823,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 +849,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,68 +899,60 @@ 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]; + if (this._config) { + for (const key in this._config) { + if (this.constructor.Default[key] !== this._config[key]) { + config[key] = this._config[key]; } } } 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 tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX); - 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)); - }; + } - _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; + this.tip = state.elements.popper; + + this._cleanTipClass(); + + this._addAttachmentClass(this._getAttachment(state.placement)); } // Static - ; - Tooltip._jQueryInterface = function _jQueryInterface(config) { + + static jQueryInterface(config) { return this.each(function () { - var $element = $__default['default'](this); - var data = $element.data(DATA_KEY); + let data = Data__default['default'].get(this, DATA_KEY); - var _config = typeof config === 'object' && config; + const _config = typeof config === 'object' && config; if (!data && /dispose|hide/.test(config)) { return; @@ -819,72 +960,28 @@ if (!data) { data = new Tooltip(this, _config); - $element.data(DATA_KEY, data); } 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; -- cgit v1.2.3