2015-05-12 08:32:37 +02:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2020-11-11 18:07:37 +01:00
|
|
|
* Bootstrap (v5.0.0-alpha3): tooltip.js
|
2020-06-16 20:41:47 +02:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
2015-05-12 08:32:37 +02:00
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2019-02-22 23:37:55 +01:00
|
|
|
import {
|
2019-08-02 15:51:05 +02:00
|
|
|
getjQuery,
|
2020-11-01 14:32:36 +01:00
|
|
|
onDOMContentLoaded,
|
2019-02-22 23:37:55 +01:00
|
|
|
TRANSITION_END,
|
|
|
|
emulateTransitionEnd,
|
|
|
|
findShadowRoot,
|
|
|
|
getTransitionDurationFromElement,
|
|
|
|
getUID,
|
|
|
|
isElement,
|
|
|
|
noop,
|
|
|
|
typeCheckConfig
|
2019-10-02 11:43:54 +02:00
|
|
|
} from './util/index'
|
2019-02-11 15:59:39 +01:00
|
|
|
import {
|
2020-06-19 10:31:37 +02:00
|
|
|
DefaultAllowlist,
|
2019-02-11 15:59:39 +01:00
|
|
|
sanitizeHtml
|
2019-10-02 11:43:54 +02:00
|
|
|
} from './util/sanitizer'
|
|
|
|
import Data from './dom/data'
|
|
|
|
import EventHandler from './dom/event-handler'
|
|
|
|
import Manipulator from './dom/manipulator'
|
2018-11-14 10:16:56 +01:00
|
|
|
import Popper from 'popper.js'
|
2019-10-02 11:43:54 +02:00
|
|
|
import SelectorEngine from './dom/selector-engine'
|
2019-09-04 16:58:29 +02:00
|
|
|
import BaseComponent from './base-component'
|
2018-11-14 10:16:56 +01:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Constants
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-02-26 12:20:34 +01:00
|
|
|
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')
|
2020-05-02 15:56:23 +02:00
|
|
|
const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn'])
|
2018-09-26 10:39:01 +02:00
|
|
|
|
|
|
|
const DefaultType = {
|
2019-02-26 12:20:34 +01:00
|
|
|
animation: 'boolean',
|
|
|
|
template: 'string',
|
|
|
|
title: '(string|element|function)',
|
|
|
|
trigger: 'string',
|
|
|
|
delay: '(number|object)',
|
|
|
|
html: 'boolean',
|
|
|
|
selector: '(string|boolean)',
|
|
|
|
placement: '(string|function)',
|
|
|
|
offset: '(number|string|function)',
|
|
|
|
container: '(string|element|boolean)',
|
|
|
|
fallbackPlacement: '(string|array)',
|
|
|
|
boundary: '(string|element)',
|
2020-11-25 08:16:22 +01:00
|
|
|
customClass: '(string|function)',
|
2019-02-26 12:20:34 +01:00
|
|
|
sanitize: 'boolean',
|
|
|
|
sanitizeFn: '(null|function)',
|
2020-06-19 10:31:37 +02:00
|
|
|
allowList: 'object',
|
2019-08-14 17:27:58 +02:00
|
|
|
popperConfig: '(null|object)'
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const AttachmentMap = {
|
2019-02-26 12:20:34 +01:00
|
|
|
AUTO: 'auto',
|
|
|
|
TOP: 'top',
|
|
|
|
RIGHT: 'right',
|
|
|
|
BOTTOM: 'bottom',
|
|
|
|
LEFT: 'left'
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Default = {
|
2019-02-26 12:20:34 +01:00
|
|
|
animation: true,
|
|
|
|
template: '<div class="tooltip" role="tooltip">' +
|
2019-02-11 11:27:14 +01:00
|
|
|
'<div class="tooltip-arrow"></div>' +
|
2018-11-14 10:16:56 +01:00
|
|
|
'<div class="tooltip-inner"></div></div>',
|
2019-02-26 12:20:34 +01:00
|
|
|
trigger: 'hover focus',
|
|
|
|
title: '',
|
|
|
|
delay: 0,
|
|
|
|
html: false,
|
|
|
|
selector: false,
|
|
|
|
placement: 'top',
|
|
|
|
offset: 0,
|
|
|
|
container: false,
|
|
|
|
fallbackPlacement: 'flip',
|
|
|
|
boundary: 'scrollParent',
|
2020-11-25 08:16:22 +01:00
|
|
|
customClass: '',
|
2019-02-26 12:20:34 +01:00
|
|
|
sanitize: true,
|
|
|
|
sanitizeFn: null,
|
2020-06-19 10:31:37 +02:00
|
|
|
allowList: DefaultAllowlist,
|
2019-08-14 17:27:58 +02:00
|
|
|
popperConfig: null
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Event = {
|
2019-02-26 12:20:34 +01:00
|
|
|
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}`
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
const CLASS_NAME_FADE = 'fade'
|
|
|
|
const CLASS_NAME_MODAL = 'modal'
|
|
|
|
const CLASS_NAME_SHOW = 'show'
|
2018-09-26 10:39:01 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
const HOVER_STATE_SHOW = 'show'
|
|
|
|
const HOVER_STATE_OUT = 'out'
|
2018-09-26 10:39:01 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
const SELECTOR_TOOLTIP_INNER = '.tooltip-inner'
|
|
|
|
|
|
|
|
const TRIGGER_HOVER = 'hover'
|
|
|
|
const TRIGGER_FOCUS = 'focus'
|
|
|
|
const TRIGGER_CLICK = 'click'
|
|
|
|
const TRIGGER_MANUAL = 'manual'
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Class Definition
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
class Tooltip extends BaseComponent {
|
2018-09-26 10:39:01 +02:00
|
|
|
constructor(element, config) {
|
|
|
|
if (typeof Popper === 'undefined') {
|
2020-11-21 15:22:08 +01:00
|
|
|
throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)')
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
super(element)
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// private
|
2019-02-26 12:20:34 +01:00
|
|
|
this._isEnabled = true
|
|
|
|
this._timeout = 0
|
|
|
|
this._hoverState = ''
|
2018-09-26 10:39:01 +02:00
|
|
|
this._activeTrigger = {}
|
2019-02-26 12:20:34 +01:00
|
|
|
this._popper = null
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Protected
|
2019-02-26 12:20:34 +01:00
|
|
|
this.config = this._getConfig(config)
|
|
|
|
this.tip = null
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
this._setListeners()
|
|
|
|
}
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Getters
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get Default() {
|
|
|
|
return Default
|
|
|
|
}
|
2015-05-13 23:46:50 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get NAME() {
|
|
|
|
return NAME
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get DATA_KEY() {
|
|
|
|
return DATA_KEY
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get Event() {
|
|
|
|
return Event
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get EVENT_KEY() {
|
|
|
|
return EVENT_KEY
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
static get DefaultType() {
|
|
|
|
return DefaultType
|
|
|
|
}
|
2017-08-24 09:40:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Public
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
enable() {
|
|
|
|
this._isEnabled = true
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
disable() {
|
|
|
|
this._isEnabled = false
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
toggleEnabled() {
|
|
|
|
this._isEnabled = !this._isEnabled
|
|
|
|
}
|
2015-08-19 04:22:46 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
toggle(event) {
|
|
|
|
if (!this._isEnabled) {
|
|
|
|
return
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (event) {
|
|
|
|
const dataKey = this.constructor.DATA_KEY
|
2020-06-18 09:02:44 +02:00
|
|
|
let context = Data.getData(event.delegateTarget, dataKey)
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!context) {
|
|
|
|
context = new this.constructor(
|
2020-06-18 09:02:44 +02:00
|
|
|
event.delegateTarget,
|
2018-09-26 10:39:01 +02:00
|
|
|
this._getDelegateConfig()
|
|
|
|
)
|
2020-06-18 09:02:44 +02:00
|
|
|
Data.setData(event.delegateTarget, dataKey, context)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
context._activeTrigger.click = !context._activeTrigger.click
|
2015-05-13 21:48:34 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (context._isWithActiveTrigger()) {
|
|
|
|
context._enter(null, context)
|
|
|
|
} else {
|
|
|
|
context._leave(null, context)
|
2015-05-13 21:48:34 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
} else {
|
2020-03-07 10:31:42 +01:00
|
|
|
if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) {
|
2018-09-26 10:39:01 +02:00
|
|
|
this._leave(null, this)
|
|
|
|
return
|
2017-04-19 15:08:06 +02:00
|
|
|
}
|
2015-05-13 21:48:34 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
this._enter(null, this)
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
dispose() {
|
|
|
|
clearTimeout(this._timeout)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
|
|
|
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (this.tip) {
|
2017-09-21 18:04:47 +02:00
|
|
|
this.tip.parentNode.removeChild(this.tip)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 12:20:34 +01:00
|
|
|
this._isEnabled = null
|
|
|
|
this._timeout = null
|
|
|
|
this._hoverState = null
|
2018-09-26 10:39:01 +02:00
|
|
|
this._activeTrigger = null
|
2019-08-14 17:27:58 +02:00
|
|
|
if (this._popper) {
|
2018-09-26 10:39:01 +02:00
|
|
|
this._popper.destroy()
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
this._popper = null
|
2019-02-26 12:20:34 +01:00
|
|
|
this.config = null
|
|
|
|
this.tip = null
|
2020-11-20 11:13:11 +01:00
|
|
|
super.dispose()
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
show() {
|
2019-09-04 16:58:29 +02:00
|
|
|
if (this._element.style.display === 'none') {
|
2018-09-26 10:39:01 +02:00
|
|
|
throw new Error('Please use show on visible elements')
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (this.isWithContent() && this._isEnabled) {
|
2019-09-04 16:58:29 +02:00
|
|
|
const showEvent = EventHandler.trigger(this._element, this.constructor.Event.SHOW)
|
|
|
|
const shadowRoot = findShadowRoot(this._element)
|
2019-02-26 12:20:34 +01:00
|
|
|
const isInTheDom = shadowRoot === null ?
|
2019-09-04 16:58:29 +02:00
|
|
|
this._element.ownerDocument.documentElement.contains(this._element) :
|
|
|
|
shadowRoot.contains(this._element)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2017-09-21 18:04:47 +02:00
|
|
|
if (showEvent.defaultPrevented || !isInTheDom) {
|
2018-09-26 10:39:01 +02:00
|
|
|
return
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-02-26 12:20:34 +01:00
|
|
|
const tip = this.getTipElement()
|
2019-02-22 23:37:55 +01:00
|
|
|
const tipId = getUID(this.constructor.NAME)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
tip.setAttribute('id', tipId)
|
2019-09-04 16:58:29 +02:00
|
|
|
this._element.setAttribute('aria-describedby', tipId)
|
2016-09-15 11:33:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
this.setContent()
|
2017-03-28 23:43:16 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (this.config.animation) {
|
2020-03-07 10:31:42 +01:00
|
|
|
tip.classList.add(CLASS_NAME_FADE)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-02-26 12:20:34 +01:00
|
|
|
const placement = typeof this.config.placement === 'function' ?
|
2019-09-04 16:58:29 +02:00
|
|
|
this.config.placement.call(this, tip, this._element) :
|
2019-02-26 12:20:34 +01:00
|
|
|
this.config.placement
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
const attachment = this._getAttachment(placement)
|
2019-05-10 21:57:27 +02:00
|
|
|
this._addAttachmentClass(attachment)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-12-05 10:25:00 +01:00
|
|
|
const container = this._getContainer()
|
2017-09-21 18:04:47 +02:00
|
|
|
Data.setData(tip, this.constructor.DATA_KEY, this)
|
2018-09-26 10:39:01 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
|
2017-09-21 18:04:47 +02:00
|
|
|
container.appendChild(tip)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.trigger(this._element, this.constructor.Event.INSERTED)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
this._popper = new Popper(this._element, tip, this._getPopperConfig(attachment))
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
tip.classList.add(CLASS_NAME_SHOW)
|
2018-03-13 09:59:20 +01:00
|
|
|
|
2020-11-25 08:16:22 +01:00
|
|
|
const customClass = typeof this.config.customClass === 'function' ? this.config.customClass() : this.config.customClass
|
|
|
|
if (customClass) {
|
|
|
|
tip.classList.add(...customClass.split(' '))
|
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// 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 ('ontouchstart' in document.documentElement) {
|
2020-03-25 15:35:02 +01:00
|
|
|
[].concat(...document.body.children).forEach(element => {
|
2019-02-22 23:37:55 +01:00
|
|
|
EventHandler.on(element, 'mouseover', noop())
|
2017-09-21 18:04:47 +02:00
|
|
|
})
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 13:00:38 +01:00
|
|
|
const complete = () => {
|
2018-09-26 10:39:01 +02:00
|
|
|
if (this.config.animation) {
|
|
|
|
this._fixTransition()
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2019-02-26 12:20:34 +01:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
const prevHoverState = this._hoverState
|
2019-02-26 12:20:34 +01:00
|
|
|
this._hoverState = null
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.trigger(this._element, this.constructor.Event.SHOWN)
|
2017-04-07 11:12:17 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
if (prevHoverState === HOVER_STATE_OUT) {
|
2018-09-26 10:39:01 +02:00
|
|
|
this._leave(null, this)
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
if (this.tip.classList.contains(CLASS_NAME_FADE)) {
|
2019-02-22 23:37:55 +01:00
|
|
|
const transitionDuration = getTransitionDurationFromElement(this.tip)
|
|
|
|
EventHandler.one(this.tip, TRANSITION_END, complete)
|
|
|
|
emulateTransitionEnd(this.tip, transitionDuration)
|
2015-05-12 08:32:37 +02:00
|
|
|
} else {
|
|
|
|
complete()
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-05-10 21:57:27 +02:00
|
|
|
hide() {
|
2020-09-24 13:55:38 +02:00
|
|
|
if (!this._popper) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-02-26 12:20:34 +01:00
|
|
|
const tip = this.getTipElement()
|
|
|
|
const complete = () => {
|
2020-03-07 10:31:42 +01:00
|
|
|
if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
|
2018-09-26 10:39:01 +02:00
|
|
|
tip.parentNode.removeChild(tip)
|
2017-04-19 15:08:06 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
this._cleanTipClass()
|
2019-09-04 16:58:29 +02:00
|
|
|
this._element.removeAttribute('aria-describedby')
|
|
|
|
EventHandler.trigger(this._element, this.constructor.Event.HIDDEN)
|
2019-05-10 21:57:27 +02:00
|
|
|
this._popper.destroy()
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
const hideEvent = EventHandler.trigger(this._element, this.constructor.Event.HIDE)
|
2017-09-21 18:04:47 +02:00
|
|
|
if (hideEvent.defaultPrevented) {
|
2018-09-26 10:39:01 +02:00
|
|
|
return
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
tip.classList.remove(CLASS_NAME_SHOW)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// If this is a touch-enabled device we remove the extra
|
|
|
|
// empty mouseover listeners we added for iOS support
|
|
|
|
if ('ontouchstart' in document.documentElement) {
|
2020-03-25 15:35:02 +01:00
|
|
|
[].concat(...document.body.children)
|
2019-02-26 12:20:34 +01:00
|
|
|
.forEach(element => EventHandler.off(element, 'mouseover', noop))
|
2015-08-31 01:57:16 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
this._activeTrigger[TRIGGER_CLICK] = false
|
|
|
|
this._activeTrigger[TRIGGER_FOCUS] = false
|
|
|
|
this._activeTrigger[TRIGGER_HOVER] = false
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
if (this.tip.classList.contains(CLASS_NAME_FADE)) {
|
2019-02-22 23:37:55 +01:00
|
|
|
const transitionDuration = getTransitionDurationFromElement(tip)
|
|
|
|
|
|
|
|
EventHandler.one(tip, TRANSITION_END, complete)
|
|
|
|
emulateTransitionEnd(tip, transitionDuration)
|
2018-09-26 10:39:01 +02:00
|
|
|
} else {
|
|
|
|
complete()
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
this._hoverState = ''
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
update() {
|
|
|
|
if (this._popper !== null) {
|
|
|
|
this._popper.scheduleUpdate()
|
2015-05-12 23:28:11 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Protected
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
isWithContent() {
|
|
|
|
return Boolean(this.getTitle())
|
|
|
|
}
|
2016-11-29 18:45:14 +01:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
getTipElement() {
|
2017-09-21 18:04:47 +02:00
|
|
|
if (this.tip) {
|
|
|
|
return this.tip
|
|
|
|
}
|
|
|
|
|
|
|
|
const element = document.createElement('div')
|
|
|
|
element.innerHTML = this.config.template
|
|
|
|
|
|
|
|
this.tip = element.children[0]
|
2018-09-26 10:39:01 +02:00
|
|
|
return this.tip
|
|
|
|
}
|
|
|
|
|
|
|
|
setContent() {
|
|
|
|
const tip = this.getTipElement()
|
2020-03-07 10:31:42 +01:00
|
|
|
this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle())
|
2020-04-09 19:56:43 +02:00
|
|
|
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
2017-09-21 18:04:47 +02:00
|
|
|
setElementContent(element, content) {
|
|
|
|
if (element === null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-05-10 21:57:27 +02:00
|
|
|
if (typeof content === 'object' && isElement(content)) {
|
2017-09-21 18:04:47 +02:00
|
|
|
if (content.jquery) {
|
|
|
|
content = content[0]
|
|
|
|
}
|
|
|
|
|
|
|
|
// content is a DOM node or a jQuery
|
2019-02-11 15:59:39 +01:00
|
|
|
if (this.config.html) {
|
2017-09-21 18:04:47 +02:00
|
|
|
if (content.parentNode !== element) {
|
|
|
|
element.innerHTML = ''
|
|
|
|
element.appendChild(content)
|
2017-11-13 11:25:36 +01:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
} else {
|
2020-03-29 08:53:57 +02:00
|
|
|
element.textContent = content.textContent
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2019-02-11 15:59:39 +01:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.config.html) {
|
|
|
|
if (this.config.sanitize) {
|
2020-06-19 10:31:37 +02:00
|
|
|
content = sanitizeHtml(content, this.config.allowList, this.config.sanitizeFn)
|
2019-02-11 15:59:39 +01:00
|
|
|
}
|
|
|
|
|
2017-09-21 18:04:47 +02:00
|
|
|
element.innerHTML = content
|
2018-09-26 10:39:01 +02:00
|
|
|
} else {
|
2020-03-29 08:53:57 +02:00
|
|
|
element.textContent = content
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
getTitle() {
|
2019-09-04 16:58:29 +02:00
|
|
|
let title = this._element.getAttribute('data-bs-original-title')
|
2018-09-26 10:39:01 +02:00
|
|
|
|
|
|
|
if (!title) {
|
2019-02-26 12:20:34 +01:00
|
|
|
title = typeof this.config.title === 'function' ?
|
2019-09-04 16:58:29 +02:00
|
|
|
this.config.title.call(this._element) :
|
2019-02-26 12:20:34 +01:00
|
|
|
this.config.title
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
return title
|
|
|
|
}
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
// Private
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-08-14 17:27:58 +02:00
|
|
|
_getPopperConfig(attachment) {
|
|
|
|
const defaultBsConfig = {
|
|
|
|
placement: attachment,
|
|
|
|
modifiers: {
|
|
|
|
offset: this._getOffset(),
|
|
|
|
flip: {
|
|
|
|
behavior: this.config.fallbackPlacement
|
|
|
|
},
|
|
|
|
arrow: {
|
|
|
|
element: `.${this.constructor.NAME}-arrow`
|
|
|
|
},
|
|
|
|
preventOverflow: {
|
|
|
|
boundariesElement: this.config.boundary
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onCreate: data => {
|
|
|
|
if (data.originalPlacement !== data.placement) {
|
|
|
|
this._handlePopperPlacementChange(data)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onUpdate: data => this._handlePopperPlacementChange(data)
|
|
|
|
}
|
|
|
|
|
2019-08-14 18:02:41 +02:00
|
|
|
return {
|
|
|
|
...defaultBsConfig,
|
|
|
|
...this.config.popperConfig
|
2019-08-14 17:27:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 21:57:27 +02:00
|
|
|
_addAttachmentClass(attachment) {
|
|
|
|
this.getTipElement().classList.add(`${CLASS_PREFIX}-${attachment}`)
|
|
|
|
}
|
|
|
|
|
2019-01-29 20:56:38 +01:00
|
|
|
_getOffset() {
|
|
|
|
const offset = {}
|
|
|
|
|
|
|
|
if (typeof this.config.offset === 'function') {
|
2019-02-26 12:20:34 +01:00
|
|
|
offset.fn = data => {
|
2019-01-29 20:56:38 +01:00
|
|
|
data.offsets = {
|
|
|
|
...data.offsets,
|
2019-09-04 16:58:29 +02:00
|
|
|
...(this.config.offset(data.offsets, this._element) || {})
|
2019-01-29 20:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
offset.offset = this.config.offset
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset
|
|
|
|
}
|
|
|
|
|
2018-12-05 10:25:00 +01:00
|
|
|
_getContainer() {
|
|
|
|
if (this.config.container === false) {
|
|
|
|
return document.body
|
|
|
|
}
|
|
|
|
|
2019-02-22 23:37:55 +01:00
|
|
|
if (isElement(this.config.container)) {
|
2017-09-21 18:04:47 +02:00
|
|
|
return this.config.container
|
2018-12-05 10:25:00 +01:00
|
|
|
}
|
|
|
|
|
2017-09-21 18:04:47 +02:00
|
|
|
return SelectorEngine.findOne(this.config.container)
|
2018-12-05 10:25:00 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_getAttachment(placement) {
|
|
|
|
return AttachmentMap[placement.toUpperCase()]
|
|
|
|
}
|
|
|
|
|
|
|
|
_setListeners() {
|
|
|
|
const triggers = this.config.trigger.split(' ')
|
|
|
|
|
2019-02-26 12:20:34 +01:00
|
|
|
triggers.forEach(trigger => {
|
2018-09-26 10:39:01 +02:00
|
|
|
if (trigger === 'click') {
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.on(this._element,
|
2018-09-26 10:39:01 +02:00
|
|
|
this.constructor.Event.CLICK,
|
|
|
|
this.config.selector,
|
2019-02-26 12:20:34 +01:00
|
|
|
event => this.toggle(event)
|
2015-05-12 08:32:37 +02:00
|
|
|
)
|
2020-03-07 10:31:42 +01:00
|
|
|
} else if (trigger !== TRIGGER_MANUAL) {
|
|
|
|
const eventIn = trigger === TRIGGER_HOVER ?
|
2019-02-26 12:20:34 +01:00
|
|
|
this.constructor.Event.MOUSEENTER :
|
|
|
|
this.constructor.Event.FOCUSIN
|
2020-03-07 10:31:42 +01:00
|
|
|
const eventOut = trigger === TRIGGER_HOVER ?
|
2019-02-26 12:20:34 +01:00
|
|
|
this.constructor.Event.MOUSELEAVE :
|
|
|
|
this.constructor.Event.FOCUSOUT
|
2018-09-26 10:39:01 +02:00
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.on(this._element,
|
2017-09-21 18:04:47 +02:00
|
|
|
eventIn,
|
|
|
|
this.config.selector,
|
2019-02-26 12:20:34 +01:00
|
|
|
event => this._enter(event)
|
2017-09-21 18:04:47 +02:00
|
|
|
)
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.on(this._element,
|
2017-09-21 18:04:47 +02:00
|
|
|
eventOut,
|
|
|
|
this.config.selector,
|
2019-02-26 12:20:34 +01:00
|
|
|
event => this._leave(event)
|
2017-09-21 18:04:47 +02:00
|
|
|
)
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
})
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-06-13 10:42:54 +02:00
|
|
|
this._hideModalHandler = () => {
|
2019-09-04 16:58:29 +02:00
|
|
|
if (this._element) {
|
2019-06-13 10:42:54 +02:00
|
|
|
this.hide()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
EventHandler.on(this._element.closest(`.${CLASS_NAME_MODAL}`),
|
2018-11-02 10:24:35 +01:00
|
|
|
'hide.bs.modal',
|
2019-06-13 10:42:54 +02:00
|
|
|
this._hideModalHandler
|
2018-11-02 10:24:35 +01:00
|
|
|
)
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (this.config.selector) {
|
|
|
|
this.config = {
|
|
|
|
...this.config,
|
|
|
|
trigger: 'manual',
|
|
|
|
selector: ''
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
} else {
|
|
|
|
this._fixTitle()
|
|
|
|
}
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_fixTitle() {
|
2019-09-04 16:58:29 +02:00
|
|
|
const title = this._element.getAttribute('title')
|
|
|
|
const originalTitleType = typeof this._element.getAttribute('data-bs-original-title')
|
2018-11-14 10:16:56 +01:00
|
|
|
|
2020-11-14 14:43:25 +01:00
|
|
|
if (title || originalTitleType !== 'string') {
|
2019-09-04 16:58:29 +02:00
|
|
|
this._element.setAttribute('data-bs-original-title', title || '')
|
2020-11-09 23:44:24 +01:00
|
|
|
if (this._element.getAttribute('title') && !this._element.getAttribute('aria-label') && !this._element.textContent) {
|
|
|
|
this._element.setAttribute('aria-label', this._element.getAttribute('title'))
|
2019-05-29 20:48:59 +02:00
|
|
|
}
|
|
|
|
|
2019-09-04 16:58:29 +02:00
|
|
|
this._element.setAttribute('title', '')
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_enter(event, context) {
|
|
|
|
const dataKey = this.constructor.DATA_KEY
|
2020-06-18 09:02:44 +02:00
|
|
|
context = context || Data.getData(event.delegateTarget, dataKey)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!context) {
|
|
|
|
context = new this.constructor(
|
2020-06-18 09:02:44 +02:00
|
|
|
event.delegateTarget,
|
2018-09-26 10:39:01 +02:00
|
|
|
this._getDelegateConfig()
|
|
|
|
)
|
2020-06-18 09:02:44 +02:00
|
|
|
Data.setData(event.delegateTarget, dataKey, context)
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (event) {
|
|
|
|
context._activeTrigger[
|
2020-03-07 10:31:42 +01:00
|
|
|
event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER
|
2018-09-26 10:39:01 +02:00
|
|
|
] = true
|
|
|
|
}
|
2015-05-12 23:28:11 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
if (context.getTipElement().classList.contains(CLASS_NAME_SHOW) ||
|
|
|
|
context._hoverState === HOVER_STATE_SHOW) {
|
|
|
|
context._hoverState = HOVER_STATE_SHOW
|
2018-09-26 10:39:01 +02:00
|
|
|
return
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
clearTimeout(context._timeout)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
context._hoverState = HOVER_STATE_SHOW
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!context.config.delay || !context.config.delay.show) {
|
|
|
|
context.show()
|
|
|
|
return
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
context._timeout = setTimeout(() => {
|
2020-03-07 10:31:42 +01:00
|
|
|
if (context._hoverState === HOVER_STATE_SHOW) {
|
2018-09-26 10:39:01 +02:00
|
|
|
context.show()
|
|
|
|
}
|
|
|
|
}, context.config.delay.show)
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_leave(event, context) {
|
|
|
|
const dataKey = this.constructor.DATA_KEY
|
2020-06-18 09:02:44 +02:00
|
|
|
context = context || Data.getData(event.delegateTarget, dataKey)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!context) {
|
|
|
|
context = new this.constructor(
|
2020-06-18 09:02:44 +02:00
|
|
|
event.delegateTarget,
|
2018-09-26 10:39:01 +02:00
|
|
|
this._getDelegateConfig()
|
|
|
|
)
|
2020-06-18 09:02:44 +02:00
|
|
|
Data.setData(event.delegateTarget, dataKey, context)
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (event) {
|
|
|
|
context._activeTrigger[
|
2020-03-07 10:31:42 +01:00
|
|
|
event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER
|
2018-09-26 10:39:01 +02:00
|
|
|
] = false
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (context._isWithActiveTrigger()) {
|
|
|
|
return
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
clearTimeout(context._timeout)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
context._hoverState = HOVER_STATE_OUT
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (!context.config.delay || !context.config.delay.hide) {
|
|
|
|
context.hide()
|
|
|
|
return
|
|
|
|
}
|
2017-03-31 10:03:54 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
context._timeout = setTimeout(() => {
|
2020-03-07 10:31:42 +01:00
|
|
|
if (context._hoverState === HOVER_STATE_OUT) {
|
2018-09-26 10:39:01 +02:00
|
|
|
context.hide()
|
2017-03-31 10:03:54 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}, context.config.delay.hide)
|
|
|
|
}
|
2017-03-31 10:03:54 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_isWithActiveTrigger() {
|
|
|
|
for (const trigger in this._activeTrigger) {
|
|
|
|
if (this._activeTrigger[trigger]) {
|
|
|
|
return true
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
return false
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_getConfig(config) {
|
2019-09-04 16:58:29 +02:00
|
|
|
const dataAttributes = Manipulator.getDataAttributes(this._element)
|
2019-02-11 15:59:39 +01:00
|
|
|
|
2020-06-20 18:00:53 +02:00
|
|
|
Object.keys(dataAttributes).forEach(dataAttr => {
|
2020-05-02 15:56:23 +02:00
|
|
|
if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
|
2020-06-20 18:00:53 +02:00
|
|
|
delete dataAttributes[dataAttr]
|
|
|
|
}
|
|
|
|
})
|
2019-02-11 15:59:39 +01:00
|
|
|
|
2018-07-25 11:29:16 +02:00
|
|
|
if (config && typeof config.container === 'object' && config.container.jquery) {
|
2017-09-21 18:04:47 +02:00
|
|
|
config.container = config.container[0]
|
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
config = {
|
|
|
|
...this.constructor.Default,
|
2019-02-11 15:59:39 +01:00
|
|
|
...dataAttributes,
|
2020-06-26 17:50:04 +02:00
|
|
|
...(typeof config === 'object' && config ? config : {})
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (typeof config.delay === 'number') {
|
|
|
|
config.delay = {
|
|
|
|
show: config.delay,
|
|
|
|
hide: config.delay
|
2017-04-08 21:13:15 +02:00
|
|
|
}
|
2017-04-07 13:20:34 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (typeof config.title === 'number') {
|
|
|
|
config.title = config.title.toString()
|
2017-04-19 10:20:50 +02:00
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (typeof config.content === 'number') {
|
|
|
|
config.content = config.content.toString()
|
2017-05-12 09:39:27 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 17:40:52 +02:00
|
|
|
typeCheckConfig(NAME, config, this.constructor.DefaultType)
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2019-02-11 15:59:39 +01:00
|
|
|
if (config.sanitize) {
|
2020-06-19 10:31:37 +02:00
|
|
|
config.template = sanitizeHtml(config.template, config.allowList, config.sanitizeFn)
|
2019-02-11 15:59:39 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
return config
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_getDelegateConfig() {
|
|
|
|
const config = {}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (this.config) {
|
|
|
|
for (const key in this.config) {
|
|
|
|
if (this.constructor.Default[key] !== this.config[key]) {
|
|
|
|
config[key] = this.config[key]
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
_cleanTipClass() {
|
2017-09-21 18:04:47 +02:00
|
|
|
const tip = this.getTipElement()
|
|
|
|
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
|
2020-01-07 21:07:51 +01:00
|
|
|
if (tabClass !== null && tabClass.length > 0) {
|
|
|
|
tabClass.map(token => token.trim())
|
2019-02-26 12:20:34 +01:00
|
|
|
.forEach(tClass => tip.classList.remove(tClass))
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
_handlePopperPlacementChange(popperData) {
|
2020-05-08 10:44:01 +02:00
|
|
|
this.tip = popperData.instance.popper
|
2018-09-26 10:39:01 +02:00
|
|
|
this._cleanTipClass()
|
2019-05-10 21:57:27 +02:00
|
|
|
this._addAttachmentClass(this._getAttachment(popperData.placement))
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_fixTransition() {
|
|
|
|
const tip = this.getTipElement()
|
|
|
|
const initConfigAnimation = this.config.animation
|
|
|
|
if (tip.getAttribute('x-placement') !== null) {
|
|
|
|
return
|
|
|
|
}
|
2019-02-26 12:20:34 +01:00
|
|
|
|
2020-03-07 10:31:42 +01:00
|
|
|
tip.classList.remove(CLASS_NAME_FADE)
|
2018-09-26 10:39:01 +02:00
|
|
|
this.config.animation = false
|
|
|
|
this.hide()
|
|
|
|
this.show()
|
|
|
|
this.config.animation = initConfigAnimation
|
|
|
|
}
|
|
|
|
|
|
|
|
// Static
|
|
|
|
|
2019-07-28 15:24:46 +02:00
|
|
|
static jQueryInterface(config) {
|
2018-09-26 10:39:01 +02:00
|
|
|
return this.each(function () {
|
2019-02-26 12:20:34 +01:00
|
|
|
let data = Data.getData(this, DATA_KEY)
|
2018-09-26 10:39:01 +02:00
|
|
|
const _config = typeof config === 'object' && config
|
|
|
|
|
|
|
|
if (!data && /dispose|hide/.test(config)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
data = new Tooltip(this, _config)
|
|
|
|
}
|
2015-05-12 08:32:37 +02:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
if (typeof config === 'string') {
|
|
|
|
if (typeof data[config] === 'undefined') {
|
|
|
|
throw new TypeError(`No method named "${config}"`)
|
|
|
|
}
|
2019-02-26 12:20:34 +01:00
|
|
|
|
2018-09-26 10:39:01 +02:00
|
|
|
data[config]()
|
|
|
|
}
|
|
|
|
})
|
2015-05-12 08:32:37 +02:00
|
|
|
}
|
2018-09-26 10:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* jQuery
|
|
|
|
* ------------------------------------------------------------------------
|
2020-11-01 14:49:51 +01:00
|
|
|
* add .Tooltip to jQuery only if jQuery is present
|
2018-09-26 10:39:01 +02:00
|
|
|
*/
|
2020-11-01 14:32:36 +01:00
|
|
|
|
|
|
|
onDOMContentLoaded(() => {
|
|
|
|
const $ = getjQuery()
|
|
|
|
/* istanbul ignore if */
|
|
|
|
if ($) {
|
|
|
|
const JQUERY_NO_CONFLICT = $.fn[NAME]
|
|
|
|
$.fn[NAME] = Tooltip.jQueryInterface
|
|
|
|
$.fn[NAME].Constructor = Tooltip
|
|
|
|
$.fn[NAME].noConflict = () => {
|
|
|
|
$.fn[NAME] = JQUERY_NO_CONFLICT
|
|
|
|
return Tooltip.jQueryInterface
|
|
|
|
}
|
2017-09-21 18:04:47 +02:00
|
|
|
}
|
2020-11-01 14:32:36 +01:00
|
|
|
})
|
2015-05-12 08:32:37 +02:00
|
|
|
|
|
|
|
export default Tooltip
|