0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-12 00:08:59 +01:00
Bootstrap/js/dist/tooltip.js

666 lines
19 KiB
JavaScript
Raw Normal View History

2018-11-13 07:41:12 +01:00
/*!
2022-05-13 08:07:23 +02:00
* Bootstrap tooltip.js v5.2.0-beta1 (https://getbootstrap.com/)
* Copyright 2011-2022 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
2020-06-16 20:50:01 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2018-11-13 07:41:12 +01:00
*/
2018-07-24 02:51:14 +02:00
(function (global, factory) {
2022-05-13 08:07:23 +02:00
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./util/index'), require('./util/sanitizer'), require('./dom/event-handler'), require('./dom/manipulator'), require('./base-component'), require('./util/template-factory')) :
typeof define === 'function' && define.amd ? define(['@popperjs/core', './util/index', './util/sanitizer', './dom/event-handler', './dom/manipulator', './base-component', './util/template-factory'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Tooltip = factory(global["@popperjs/core"], global.Index, global.Sanitizer, global.EventHandler, global.Manipulator, global.BaseComponent, global.TemplateFactory));
})(this, (function (Popper, index, sanitizer, EventHandler, Manipulator, BaseComponent, TemplateFactory) { 'use strict';
2019-03-01 17:31:34 +01:00
2021-10-05 17:50:18 +02:00
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
2020-09-14 17:12:06 +02:00
2020-12-07 16:50:24 +01:00
function _interopNamespace(e) {
if (e && e.__esModule) return e;
2022-05-13 08:07:23 +02:00
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
2020-12-07 16:50:24 +01:00
if (e) {
2021-10-05 17:50:18 +02:00
for (const k in e) {
2020-12-07 16:50:24 +01:00
if (k !== 'default') {
2021-10-05 17:50:18 +02:00
const d = Object.getOwnPropertyDescriptor(e, k);
2020-12-07 16:50:24 +01:00
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
2021-10-05 17:50:18 +02:00
get: () => e[k]
2020-12-07 16:50:24 +01:00
});
}
2021-10-05 17:50:18 +02:00
}
2020-12-07 16:50:24 +01:00
}
2021-10-05 17:50:18 +02:00
n.default = e;
2020-12-07 16:50:24 +01:00
return Object.freeze(n);
}
2021-10-05 17:50:18 +02:00
const Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
const Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
const BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
2022-05-13 08:07:23 +02:00
const TemplateFactory__default = /*#__PURE__*/_interopDefaultLegacy(TemplateFactory);
2019-02-13 17:01:40 +01:00
/**
* --------------------------------------------------------------------------
2022-05-13 08:07:23 +02:00
* Bootstrap (v5.2.0-beta1): tooltip.js
2020-06-16 20:50:01 +02:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2019-03-01 17:31:34 +01:00
* --------------------------------------------------------------------------
*/
/**
2020-12-03 15:18:59 +01:00
* Constants
*/
2021-03-23 17:26:54 +01:00
const NAME = 'tooltip';
const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn']);
2022-05-13 08:07:23 +02:00
const CLASS_NAME_FADE = 'fade';
const CLASS_NAME_MODAL = 'modal';
const CLASS_NAME_SHOW = 'show';
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';
const EVENT_HIDE = 'hide';
const EVENT_HIDDEN = 'hidden';
const EVENT_SHOW = 'show';
const EVENT_SHOWN = 'shown';
const EVENT_INSERTED = 'inserted';
const EVENT_CLICK = 'click';
const EVENT_FOCUSIN = 'focusin';
const EVENT_FOCUSOUT = 'focusout';
const EVENT_MOUSEENTER = 'mouseenter';
const EVENT_MOUSELEAVE = 'mouseleave';
2021-03-23 17:26:54 +01:00
const AttachmentMap = {
2018-11-13 07:41:12 +01:00
AUTO: 'auto',
TOP: 'top',
2022-05-13 08:07:23 +02:00
RIGHT: index.isRTL() ? 'left' : 'right',
2018-11-13 07:41:12 +01:00
BOTTOM: 'bottom',
2022-05-13 08:07:23 +02:00
LEFT: index.isRTL() ? 'right' : 'left'
2018-11-13 07:41:12 +01:00
};
2021-03-23 17:26:54 +01:00
const Default = {
2018-11-13 07:41:12 +01:00
animation: true,
2020-12-03 15:18:59 +01:00
template: '<div class="tooltip" role="tooltip">' + '<div class="tooltip-arrow"></div>' + '<div class="tooltip-inner"></div>' + '</div>',
2018-11-13 07:41:12 +01:00
trigger: 'hover focus',
title: '',
delay: 0,
html: false,
selector: false,
placement: 'top',
offset: [0, 0],
2018-11-13 07:41:12 +01:00
container: false,
fallbackPlacements: ['top', 'right', 'bottom', 'left'],
2020-12-07 16:50:24 +01:00
boundary: 'clippingParents',
2020-12-03 15:18:59 +01:00
customClass: '',
2019-02-13 17:01:40 +01:00
sanitize: true,
sanitizeFn: null,
2022-05-13 08:07:23 +02:00
allowList: sanitizer.DefaultAllowlist,
2019-08-27 15:03:21 +02:00
popperConfig: null
2018-11-13 07:41:12 +01:00
};
2022-05-13 08:07:23 +02:00
const DefaultType = {
animation: 'boolean',
template: 'string',
title: '(string|element|function)',
trigger: 'string',
delay: '(number|object)',
html: 'boolean',
selector: '(string|boolean)',
placement: '(string|function)',
offset: '(array|string|function)',
container: '(string|element|boolean)',
fallbackPlacements: 'array',
boundary: '(string|element)',
customClass: '(string|function)',
sanitize: 'boolean',
sanitizeFn: '(null|function)',
allowList: 'object',
popperConfig: '(null|object|function)'
2018-11-13 07:41:12 +01:00
};
2019-10-08 08:39:10 +02:00
/**
2022-05-13 08:07:23 +02:00
* Class definition
2019-10-08 08:39:10 +02:00
*/
2018-11-13 07:41:12 +01:00
2021-10-05 17:50:18 +02:00
class Tooltip extends BaseComponent__default.default {
2021-03-23 17:26:54 +01:00
constructor(element, config) {
2020-12-07 16:50:24 +01:00
if (typeof Popper__namespace === 'undefined') {
2020-11-23 14:17:16 +01:00
throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)');
2020-12-03 15:18:59 +01:00
}
2017-10-30 00:19:14 +01:00
2022-05-13 08:07:23 +02:00
super(element, config); // Private
2021-03-23 17:26:54 +01:00
this._isEnabled = true;
this._timeout = 0;
2022-05-13 08:07:23 +02:00
this._isHovered = false;
2021-03-23 17:26:54 +01:00
this._activeTrigger = {};
2022-05-13 08:07:23 +02:00
this._popper = null;
this._templateFactory = null; // Protected
2021-03-23 17:26:54 +01:00
this.tip = null;
2019-03-01 17:31:34 +01:00
2021-03-23 17:26:54 +01:00
this._setListeners();
2018-11-13 07:41:12 +01:00
} // Getters
2015-08-13 06:12:03 +02:00
2021-03-23 17:26:54 +01:00
static get Default() {
return Default;
}
static get DefaultType() {
return DefaultType;
2022-05-13 08:07:23 +02:00
}
static get NAME() {
return NAME;
2021-03-23 17:26:54 +01:00
} // Public
enable() {
2018-11-13 07:41:12 +01:00
this._isEnabled = true;
2021-03-23 17:26:54 +01:00
}
2021-03-23 17:26:54 +01:00
disable() {
2018-11-13 07:41:12 +01:00
this._isEnabled = false;
2021-03-23 17:26:54 +01:00
}
2021-03-23 17:26:54 +01:00
toggleEnabled() {
2018-11-13 07:41:12 +01:00
this._isEnabled = !this._isEnabled;
2021-03-23 17:26:54 +01:00
}
2017-09-30 23:28:03 +02:00
2021-03-23 17:26:54 +01:00
toggle(event) {
2018-11-13 07:41:12 +01:00
if (!this._isEnabled) {
return;
}
2015-08-19 05:28:28 +02:00
2018-11-13 07:41:12 +01:00
if (event) {
2021-03-23 17:26:54 +01:00
const context = this._initializeOnDelegatedTarget(event);
2015-05-12 23:28:11 +02:00
2018-11-13 07:41:12 +01:00
context._activeTrigger.click = !context._activeTrigger.click;
2015-05-12 23:28:11 +02:00
2018-11-13 07:41:12 +01:00
if (context._isWithActiveTrigger()) {
2022-05-13 08:07:23 +02:00
context._enter();
2016-10-10 02:26:51 +02:00
} else {
2022-05-13 08:07:23 +02:00
context._leave();
2018-11-13 07:41:12 +01:00
}
2022-05-13 08:07:23 +02:00
return;
}
if (this._isShown()) {
this._leave();
2022-05-13 08:07:23 +02:00
return;
2018-11-13 07:41:12 +01:00
}
2022-05-13 08:07:23 +02:00
this._enter();
2021-03-23 17:26:54 +01:00
}
2018-11-13 07:41:12 +01:00
2021-03-23 17:26:54 +01:00
dispose() {
2018-11-13 07:41:12 +01:00
clearTimeout(this._timeout);
2021-10-05 17:50:18 +02:00
EventHandler__default.default.off(this._element.closest(SELECTOR_MODAL), EVENT_MODAL_HIDE, this._hideModalHandler);
if (this.tip) {
this.tip.remove();
2018-11-13 07:41:12 +01:00
}
this._disposePopper();
2021-03-23 17:26:54 +01:00
super.dispose();
}
2020-12-03 15:18:59 +01:00
2021-03-23 17:26:54 +01:00
show() {
2020-12-03 15:18:59 +01:00
if (this._element.style.display === 'none') {
2018-11-13 07:41:12 +01:00
throw new Error('Please use show on visible elements');
}
2022-05-13 08:07:23 +02:00
if (!(this._isWithContent() && this._isEnabled)) {
return;
}
2022-05-13 08:07:23 +02:00
const showEvent = EventHandler__default.default.trigger(this._element, this.constructor.eventName(EVENT_SHOW));
const shadowRoot = index.findShadowRoot(this._element);
const isInTheDom = (shadowRoot || this._element.ownerDocument.documentElement).contains(this._element);
if (showEvent.defaultPrevented || !isInTheDom) {
return;
}
2016-11-27 04:17:23 +01:00
2022-05-13 08:07:23 +02:00
const tip = this._getTipElement();
2018-12-16 00:13:22 +01:00
2022-05-13 08:07:23 +02:00
this._element.setAttribute('aria-describedby', tip.getAttribute('id'));
2018-12-16 00:13:22 +01:00
const {
container
} = this._config;
2016-10-10 02:26:51 +02:00
if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
2021-08-04 17:41:51 +02:00
container.append(tip);
2022-05-13 08:07:23 +02:00
EventHandler__default.default.trigger(this._element, this.constructor.eventName(EVENT_INSERTED));
2021-03-23 17:26:54 +01:00
}
if (this._popper) {
this._popper.update();
} else {
2022-05-13 08:07:23 +02:00
this._createPopper(tip);
}
2020-12-03 15:18:59 +01:00
2022-05-13 08:07:23 +02:00
tip.classList.add(CLASS_NAME_SHOW); // 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
2020-12-03 15:18:59 +01:00
if ('ontouchstart' in document.documentElement) {
2022-05-13 08:07:23 +02:00
for (const element of [].concat(...document.body.children)) {
EventHandler__default.default.on(element, 'mouseover', index.noop);
}
}
2021-03-23 17:26:54 +01:00
const complete = () => {
2022-05-13 08:07:23 +02:00
const previousHoverState = this._isHovered;
this._isHovered = false;
EventHandler__default.default.trigger(this._element, this.constructor.eventName(EVENT_SHOWN));
2018-11-13 07:41:12 +01:00
2022-05-13 08:07:23 +02:00
if (previousHoverState) {
this._leave();
}
};
2022-05-13 08:07:23 +02:00
this._queueCallback(complete, this.tip, this._isAnimated());
2021-03-23 17:26:54 +01:00
}
2021-03-23 17:26:54 +01:00
hide() {
2022-05-13 08:07:23 +02:00
if (!this._isShown()) {
2020-09-29 17:33:00 +02:00
return;
}
2022-05-13 08:07:23 +02:00
const hideEvent = EventHandler__default.default.trigger(this._element, this.constructor.eventName(EVENT_HIDE));
2016-10-10 02:26:51 +02:00
2019-03-01 17:31:34 +01:00
if (hideEvent.defaultPrevented) {
2018-11-13 07:41:12 +01:00
return;
}
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
const tip = this._getTipElement();
2020-03-28 11:29:08 +01:00
tip.classList.remove(CLASS_NAME_SHOW); // If this is a touch-enabled device we remove the extra
2018-11-13 07:41:12 +01:00
// empty mouseover listeners we added for iOS support
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
if ('ontouchstart' in document.documentElement) {
2022-05-13 08:07:23 +02:00
for (const element of [].concat(...document.body.children)) {
EventHandler__default.default.off(element, 'mouseover', index.noop);
}
2018-11-13 07:41:12 +01:00
}
2017-09-30 23:28:03 +02:00
2020-03-28 11:29:08 +01:00
this._activeTrigger[TRIGGER_CLICK] = false;
this._activeTrigger[TRIGGER_FOCUS] = false;
this._activeTrigger[TRIGGER_HOVER] = false;
2022-05-13 08:07:23 +02:00
this._isHovered = false;
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
const complete = () => {
if (this._isWithActiveTrigger()) {
return;
}
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
if (!this._isHovered) {
tip.remove();
}
this._element.removeAttribute('aria-describedby');
EventHandler__default.default.trigger(this._element, this.constructor.eventName(EVENT_HIDDEN));
this._disposePopper();
};
this._queueCallback(complete, this.tip, this._isAnimated());
2021-03-23 17:26:54 +01:00
}
2017-09-30 23:28:03 +02:00
2021-03-23 17:26:54 +01:00
update() {
2022-05-13 08:07:23 +02:00
if (this._popper) {
2020-12-07 16:50:24 +01:00
this._popper.update();
2018-11-13 07:41:12 +01:00
}
2019-01-04 17:29:45 +01:00
} // Protected
2017-09-30 23:28:03 +02:00
2021-03-23 17:26:54 +01:00
2022-05-13 08:07:23 +02:00
_isWithContent() {
return Boolean(this._getTitle());
2021-03-23 17:26:54 +01:00
}
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
_getTipElement() {
if (!this.tip) {
this.tip = this._createTipElement(this._getContentForTemplate());
2019-03-01 17:31:34 +01:00
}
2018-11-13 07:41:12 +01:00
return this.tip;
2021-03-23 17:26:54 +01:00
}
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
_createTipElement(content) {
const tip = this._getTemplateFactory(content).toHtml(); // todo: remove this check on v6
2021-08-04 17:41:51 +02:00
2022-05-13 08:07:23 +02:00
if (!tip) {
return null;
}
2021-08-04 17:41:51 +02:00
2022-05-13 08:07:23 +02:00
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW); // todo: on v6 the following can be achieved with CSS only
2021-08-04 17:41:51 +02:00
2022-05-13 08:07:23 +02:00
tip.classList.add(`bs-${this.constructor.NAME}-auto`);
const tipId = index.getUID(this.constructor.NAME).toString();
tip.setAttribute('id', tipId);
2017-09-30 23:28:03 +02:00
2022-05-13 08:07:23 +02:00
if (this._isAnimated()) {
tip.classList.add(CLASS_NAME_FADE);
2019-03-01 17:31:34 +01:00
}
2022-05-13 08:07:23 +02:00
return tip;
}
2019-03-01 17:31:34 +01:00
2022-05-13 08:07:23 +02:00
setContent(content) {
let isShown = false;
2019-02-13 17:01:40 +01:00
2022-05-13 08:07:23 +02:00
if (this.tip) {
isShown = this._isShown();
this.tip.remove();
this.tip = null;
2019-02-13 17:01:40 +01:00
}
2022-05-13 08:07:23 +02:00
this._disposePopper();
2019-02-13 17:01:40 +01:00
2022-05-13 08:07:23 +02:00
this.tip = this._createTipElement(content);
if (isShown) {
this.show();
2018-11-13 07:41:12 +01:00
}
2021-03-23 17:26:54 +01:00
}
2022-05-13 08:07:23 +02:00
_getTemplateFactory(content) {
if (this._templateFactory) {
this._templateFactory.changeContent(content);
} else {
this._templateFactory = new TemplateFactory__default.default({ ...this._config,
// the `content` var has to be after `this._config`
// to override config.content in case of popover
content,
extraClass: this._resolvePossibleFunction(this._config.customClass)
});
}
return this._templateFactory;
}
2022-05-13 08:07:23 +02:00
_getContentForTemplate() {
return {
[SELECTOR_TOOLTIP_INNER]: this._getTitle()
};
2021-03-23 17:26:54 +01:00
}
2020-12-03 14:08:31 +01:00
2022-05-13 08:07:23 +02:00
_getTitle() {
return this._config.title;
} // Private
2020-12-03 14:08:31 +01:00
2022-05-13 08:07:23 +02:00
_initializeOnDelegatedTarget(event) {
return this.constructor.getOrCreateInstance(event.delegateTarget, this._getDelegateConfig());
}
2016-10-10 02:26:51 +02:00
2022-05-13 08:07:23 +02:00
_isAnimated() {
return this._config.animation || this.tip && this.tip.classList.contains(CLASS_NAME_FADE);
}
2021-03-23 17:26:54 +01:00
2022-05-13 08:07:23 +02:00
_isShown() {
return this.tip && this.tip.classList.contains(CLASS_NAME_SHOW);
}
_createPopper(tip) {
const placement = typeof this._config.placement === 'function' ? this._config.placement.call(this, tip, this._element) : this._config.placement;
const attachment = AttachmentMap[placement.toUpperCase()];
this._popper = Popper__namespace.createPopper(this._element, tip, this._getPopperConfig(attachment));
2021-03-23 17:26:54 +01:00
}
2019-08-27 15:03:21 +02:00
2021-03-23 17:26:54 +01:00
_getOffset() {
const {
offset
} = this._config;
2020-12-07 16:50:24 +01:00
if (typeof offset === 'string') {
2022-05-13 08:07:23 +02:00
return offset.split(',').map(value => Number.parseInt(value, 10));
2020-12-07 16:50:24 +01:00
}
if (typeof offset === 'function') {
2021-03-23 17:26:54 +01:00
return popperData => offset(popperData, this._element);
}
return offset;
2021-03-23 17:26:54 +01:00
}
2022-05-13 08:07:23 +02:00
_resolvePossibleFunction(arg) {
return typeof arg === 'function' ? arg.call(this._element) : arg;
2021-08-04 17:41:51 +02:00
}
2021-03-23 17:26:54 +01:00
_getPopperConfig(attachment) {
const defaultBsPopperConfig = {
2019-08-27 15:03:21 +02:00
placement: attachment,
modifiers: [{
name: 'flip',
options: {
fallbackPlacements: this._config.fallbackPlacements
}
}, {
name: 'offset',
options: {
offset: this._getOffset()
}
}, {
2020-12-07 16:50:24 +01:00
name: 'preventOverflow',
options: {
boundary: this._config.boundary
2020-12-07 16:50:24 +01:00
}
}, {
name: 'arrow',
options: {
2021-03-23 17:26:54 +01:00
element: `.${this.constructor.NAME}-arrow`
2019-08-27 15:03:21 +02:00
}
2020-12-07 16:50:24 +01:00
}, {
2022-05-13 08:07:23 +02:00
name: 'preSetPlacement',
2020-12-07 16:50:24 +01:00
enabled: true,
2022-05-13 08:07:23 +02:00
phase: 'beforeMain',
fn: data => {
// Pre-set Popper's placement attribute in order to read the arrow sizes properly.
// Otherwise, Popper mixes up the width and height dimensions since the initial arrow style is for top placement
this._getTipElement().setAttribute('data-popper-placement', data.state.placement);
2019-08-27 15:03:21 +02:00
}
2022-05-13 08:07:23 +02:00
}]
2019-08-27 15:03:21 +02:00
};
2021-03-23 17:26:54 +01:00
return { ...defaultBsPopperConfig,
...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
2021-03-23 17:26:54 +01:00
};
}
2019-08-27 15:03:21 +02:00
2021-03-23 17:26:54 +01:00
_setListeners() {
const triggers = this._config.trigger.split(' ');
2022-05-13 08:07:23 +02:00
for (const trigger of triggers) {
2018-11-13 07:41:12 +01:00
if (trigger === 'click') {
2022-05-13 08:07:23 +02:00
EventHandler__default.default.on(this._element, this.constructor.eventName(EVENT_CLICK), this._config.selector, event => this.toggle(event));
2020-03-28 11:29:08 +01:00
} else if (trigger !== TRIGGER_MANUAL) {
2022-05-13 08:07:23 +02:00
const eventIn = trigger === TRIGGER_HOVER ? this.constructor.eventName(EVENT_MOUSEENTER) : this.constructor.eventName(EVENT_FOCUSIN);
const eventOut = trigger === TRIGGER_HOVER ? this.constructor.eventName(EVENT_MOUSELEAVE) : this.constructor.eventName(EVENT_FOCUSOUT);
EventHandler__default.default.on(this._element, eventIn, this._config.selector, event => {
const context = this._initializeOnDelegatedTarget(event);
context._activeTrigger[event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER] = true;
context._enter();
});
EventHandler__default.default.on(this._element, eventOut, this._config.selector, event => {
const context = this._initializeOnDelegatedTarget(event);
context._activeTrigger[event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER] = context._element.contains(event.relatedTarget);
context._leave();
});
2017-09-06 06:05:12 +02:00
}
2022-05-13 08:07:23 +02:00
}
2019-07-12 23:56:26 +02:00
2021-03-23 17:26:54 +01:00
this._hideModalHandler = () => {
if (this._element) {
this.hide();
2018-11-13 07:41:12 +01:00
}
2019-07-12 23:56:26 +02:00
};
2021-10-05 17:50:18 +02:00
EventHandler__default.default.on(this._element.closest(SELECTOR_MODAL), EVENT_MODAL_HIDE, this._hideModalHandler);
2017-09-30 23:28:03 +02:00
if (this._config.selector) {
this._config = { ...this._config,
2018-11-13 07:41:12 +01:00
trigger: 'manual',
selector: ''
2021-03-23 17:26:54 +01:00
};
2018-11-13 07:41:12 +01:00
} else {
this._fixTitle();
}
2021-03-23 17:26:54 +01:00
}
2021-03-23 17:26:54 +01:00
_fixTitle() {
2022-05-13 08:07:23 +02:00
const title = this._config.originalTitle;
2022-05-13 08:07:23 +02:00
if (!title) {
return;
2018-11-13 07:41:12 +01:00
}
2022-05-13 08:07:23 +02:00
if (!this._element.getAttribute('aria-label') && !this._element.textContent) {
this._element.setAttribute('aria-label', title);
2018-11-13 07:41:12 +01:00
}
2022-05-13 08:07:23 +02:00
this._element.removeAttribute('title');
}
2016-10-10 02:26:51 +02:00
2022-05-13 08:07:23 +02:00
_enter() {
if (this._isShown() || this._isHovered) {
this._isHovered = true;
2018-11-13 07:41:12 +01:00
return;
}
2022-05-13 08:07:23 +02:00
this._isHovered = true;
this._setTimeout(() => {
if (this._isHovered) {
this.show();
}
2022-05-13 08:07:23 +02:00
}, this._config.delay.show);
2021-03-23 17:26:54 +01:00
}
2022-05-13 08:07:23 +02:00
_leave() {
if (this._isWithActiveTrigger()) {
2018-11-13 07:41:12 +01:00
return;
}
2022-05-13 08:07:23 +02:00
this._isHovered = false;
2022-05-13 08:07:23 +02:00
this._setTimeout(() => {
if (!this._isHovered) {
this.hide();
}
2022-05-13 08:07:23 +02:00
}, this._config.delay.hide);
2021-03-23 17:26:54 +01:00
}
2022-05-13 08:07:23 +02:00
_setTimeout(handler, timeout) {
clearTimeout(this._timeout);
this._timeout = setTimeout(handler, timeout);
}
2016-10-10 02:26:51 +02:00
2022-05-13 08:07:23 +02:00
_isWithActiveTrigger() {
return Object.values(this._activeTrigger).includes(true);
2021-03-23 17:26:54 +01:00
}
2015-05-13 23:46:50 +02:00
2021-03-23 17:26:54 +01:00
_getConfig(config) {
2021-10-05 17:50:18 +02:00
const dataAttributes = Manipulator__default.default.getDataAttributes(this._element);
2022-05-13 08:07:23 +02:00
for (const dataAttribute of Object.keys(dataAttributes)) {
if (DISALLOWED_ATTRIBUTES.has(dataAttribute)) {
delete dataAttributes[dataAttribute];
2019-02-13 17:01:40 +01:00
}
2022-05-13 08:07:23 +02:00
}
config = { ...dataAttributes,
2021-03-23 17:26:54 +01:00
...(typeof config === 'object' && config ? config : {})
};
2022-05-13 08:07:23 +02:00
config = this._mergeConfigObj(config);
config = this._configAfterMerge(config);
this._typeCheckConfig(config);
return config;
}
_configAfterMerge(config) {
config.container = config.container === false ? document.body : index.getElement(config.container);
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
if (typeof config.delay === 'number') {
config.delay = {
show: config.delay,
hide: config.delay
};
}
2017-04-02 04:18:29 +02:00
2022-05-13 08:07:23 +02:00
config.originalTitle = this._element.getAttribute('title') || '';
config.title = this._resolvePossibleFunction(config.title) || config.originalTitle;
2018-11-13 07:41:12 +01:00
if (typeof config.title === 'number') {
config.title = config.title.toString();
}
2017-04-02 04:18:29 +02:00
2018-11-13 07:41:12 +01:00
if (typeof config.content === 'number') {
config.content = config.content.toString();
}
2016-10-10 02:26:51 +02:00
2018-11-13 07:41:12 +01:00
return config;
2021-03-23 17:26:54 +01:00
}
2016-10-10 02:26:51 +02:00
2021-03-23 17:26:54 +01:00
_getDelegateConfig() {
const config = {};
2016-10-10 02:26:51 +02:00
2021-08-04 17:41:51 +02:00
for (const key in this._config) {
if (this.constructor.Default[key] !== this._config[key]) {
config[key] = this._config[key];
}
2021-08-04 17:41:51 +02:00
} // 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)`
2017-09-30 23:28:03 +02:00
2018-11-13 07:41:12 +01:00
return config;
2021-03-23 17:26:54 +01:00
}
2017-09-30 23:28:03 +02:00
_disposePopper() {
if (this._popper) {
this._popper.destroy();
this._popper = null;
}
2019-01-04 17:29:45 +01:00
} // Static
2017-09-30 23:28:03 +02:00
2021-03-23 17:26:54 +01:00
static jQueryInterface(config) {
2018-11-13 07:41:12 +01:00
return this.each(function () {
const data = Tooltip.getOrCreateInstance(this, config);
2016-10-10 02:26:51 +02:00
2022-05-13 08:07:23 +02:00
if (typeof config !== 'string') {
return;
}
2017-09-06 06:05:12 +02:00
2022-05-13 08:07:23 +02:00
if (typeof data[config] === 'undefined') {
throw new TypeError(`No method named "${config}"`);
2018-07-24 02:51:14 +02:00
}
2022-05-13 08:07:23 +02:00
data[config]();
2018-11-13 07:41:12 +01:00
});
2021-03-23 17:26:54 +01:00
}
2021-03-23 17:26:54 +01:00
}
2018-11-13 07:41:12 +01:00
/**
* jQuery
*/
2022-05-13 08:07:23 +02:00
index.defineJQueryPlugin(Tooltip);
return Tooltip;
2018-07-24 02:51:14 +02:00
2021-10-05 17:50:18 +02:00
}));
2018-07-24 02:51:14 +02:00
//# sourceMappingURL=tooltip.js.map