aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/src/tooltip.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/twbs/bootstrap/js/src/tooltip.js')
-rw-r--r--vendor/twbs/bootstrap/js/src/tooltip.js605
1 files changed, 287 insertions, 318 deletions
diff --git a/vendor/twbs/bootstrap/js/src/tooltip.js b/vendor/twbs/bootstrap/js/src/tooltip.js
index fd6ceea67..cd4a2878e 100644
--- a/vendor/twbs/bootstrap/js/src/tooltip.js
+++ b/vendor/twbs/bootstrap/js/src/tooltip.js
@@ -1,17 +1,31 @@
/**
* --------------------------------------------------------------------------
- * Bootstrap (v4.6.0): tooltip.js
+ * Bootstrap (v5.0.2): tooltip.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
+import * as Popper from '@popperjs/core'
+
+import {
+ defineJQueryPlugin,
+ findShadowRoot,
+ getElement,
+ getUID,
+ isElement,
+ isRTL,
+ noop,
+ typeCheckConfig
+} from './util/index'
import {
- DefaultWhitelist,
+ DefaultAllowlist,
sanitizeHtml
-} from './tools/sanitizer'
-import $ from 'jquery'
-import Popper from 'popper.js'
-import Util from './util'
+} from './util/sanitizer'
+import Data from './dom/data'
+import EventHandler from './dom/event-handler'
+import Manipulator from './dom/manipulator'
+import SelectorEngine from './dom/selector-engine'
+import BaseComponent from './base-component'
/**
* ------------------------------------------------------------------------
@@ -20,13 +34,11 @@ import Util from './util'
*/
const NAME = 'tooltip'
-const VERSION = '4.6.0'
const DATA_KEY = 'bs.tooltip'
const EVENT_KEY = `.${DATA_KEY}`
-const JQUERY_NO_CONFLICT = $.fn[NAME]
const CLASS_PREFIX = 'bs-tooltip'
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
-const DISALLOWED_ATTRIBUTES = ['sanitize', 'whiteList', 'sanitizeFn']
+const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn'])
const DefaultType = {
animation: 'boolean',
@@ -37,50 +49,48 @@ const DefaultType = {
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)'
}
const AttachmentMap = {
AUTO: 'auto',
TOP: 'top',
- RIGHT: 'right',
+ RIGHT: isRTL() ? 'left' : 'right',
BOTTOM: 'bottom',
- LEFT: 'left'
+ LEFT: isRTL() ? 'right' : 'left'
}
const Default = {
animation: true,
template: '<div class="tooltip" role="tooltip">' +
- '<div class="arrow"></div>' +
- '<div class="tooltip-inner"></div></div>',
+ '<div class="tooltip-arrow"></div>' +
+ '<div class="tooltip-inner"></div>' +
+ '</div>',
trigger: 'hover focus',
title: '',
delay: 0,
html: false,
selector: false,
placement: 'top',
- offset: 0,
+ offset: [0, 0],
container: false,
- fallbackPlacement: 'flip',
- boundary: 'scrollParent',
+ fallbackPlacements: ['top', 'right', 'bottom', 'left'],
+ boundary: 'clippingParents',
customClass: '',
sanitize: true,
sanitizeFn: null,
- whiteList: DefaultWhitelist,
+ allowList: DefaultAllowlist,
popperConfig: null
}
-const HOVER_STATE_SHOW = 'show'
-const HOVER_STATE_OUT = 'out'
-
const Event = {
HIDE: `hide${EVENT_KEY}`,
HIDDEN: `hidden${EVENT_KEY}`,
@@ -95,10 +105,13 @@ const Event = {
}
const CLASS_NAME_FADE = 'fade'
+const CLASS_NAME_MODAL = 'modal'
const CLASS_NAME_SHOW = 'show'
+const HOVER_STATE_SHOW = 'show'
+const HOVER_STATE_OUT = 'out'
+
const SELECTOR_TOOLTIP_INNER = '.tooltip-inner'
-const SELECTOR_ARROW = '.arrow'
const TRIGGER_HOVER = 'hover'
const TRIGGER_FOCUS = 'focus'
@@ -111,12 +124,14 @@ const TRIGGER_MANUAL = 'manual'
* ------------------------------------------------------------------------
*/
-class Tooltip {
+class Tooltip extends BaseComponent {
constructor(element, config) {
if (typeof Popper === 'undefined') {
throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)')
}
+ super(element)
+
// private
this._isEnabled = true
this._timeout = 0
@@ -125,8 +140,7 @@ class Tooltip {
this._popper = null
// Protected
- this.element = element
- this.config = this._getConfig(config)
+ this._config = this._getConfig(config)
this.tip = null
this._setListeners()
@@ -134,10 +148,6 @@ class Tooltip {
// Getters
- static get VERSION() {
- return VERSION
- }
-
static get Default() {
return Default
}
@@ -146,18 +156,10 @@ class Tooltip {
return NAME
}
- static get DATA_KEY() {
- return DATA_KEY
- }
-
static get Event() {
return Event
}
- static get EVENT_KEY() {
- return EVENT_KEY
- }
-
static get DefaultType() {
return DefaultType
}
@@ -182,16 +184,7 @@ class Tooltip {
}
if (event) {
- const dataKey = this.constructor.DATA_KEY
- let context = $(event.currentTarget).data(dataKey)
-
- if (!context) {
- context = new this.constructor(
- event.currentTarget,
- this._getDelegateConfig()
- )
- $(event.currentTarget).data(dataKey, context)
- }
+ const context = this._initializeOnDelegatedTarget(event)
context._activeTrigger.click = !context._activeTrigger.click
@@ -201,7 +194,7 @@ class Tooltip {
context._leave(null, context)
}
} else {
- if ($(this.getTipElement()).hasClass(CLASS_NAME_SHOW)) {
+ if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) {
this._leave(null, this)
return
}
@@ -213,170 +206,154 @@ class Tooltip {
dispose() {
clearTimeout(this._timeout)
- $.removeData(this.element, this.constructor.DATA_KEY)
-
- $(this.element).off(this.constructor.EVENT_KEY)
- $(this.element).closest('.modal').off('hide.bs.modal', this._hideModalHandler)
+ EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
if (this.tip) {
- $(this.tip).remove()
+ this.tip.remove()
}
- 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
+ super.dispose()
}
show() {
- if ($(this.element).css('display') === 'none') {
+ if (this._element.style.display === 'none') {
throw new Error('Please use show on visible elements')
}
- const showEvent = $.Event(this.constructor.Event.SHOW)
- if (this.isWithContent() && this._isEnabled) {
- $(this.element).trigger(showEvent)
-
- const shadowRoot = Util.findShadowRoot(this.element)
- const isInTheDom = $.contains(
- shadowRoot !== null ? shadowRoot : this.element.ownerDocument.documentElement,
- this.element
- )
+ if (!(this.isWithContent() && this._isEnabled)) {
+ return
+ }
- if (showEvent.isDefaultPrevented() || !isInTheDom) {
- return
- }
+ const showEvent = EventHandler.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)
- const tip = this.getTipElement()
- const tipId = Util.getUID(this.constructor.NAME)
+ if (showEvent.defaultPrevented || !isInTheDom) {
+ return
+ }
- tip.setAttribute('id', tipId)
- this.element.setAttribute('aria-describedby', tipId)
+ const tip = this.getTipElement()
+ const tipId = getUID(this.constructor.NAME)
- this.setContent()
+ tip.setAttribute('id', tipId)
+ this._element.setAttribute('aria-describedby', tipId)
- if (this.config.animation) {
- $(tip).addClass(CLASS_NAME_FADE)
- }
+ this.setContent()
- const placement = typeof this.config.placement === 'function' ?
- this.config.placement.call(this, tip, this.element) :
- this.config.placement
+ if (this._config.animation) {
+ tip.classList.add(CLASS_NAME_FADE)
+ }
- const attachment = this._getAttachment(placement)
- this.addAttachmentClass(attachment)
+ const placement = typeof this._config.placement === 'function' ?
+ this._config.placement.call(this, tip, this._element) :
+ this._config.placement
- const container = this._getContainer()
- $(tip).data(this.constructor.DATA_KEY, this)
+ const attachment = this._getAttachment(placement)
+ this._addAttachmentClass(attachment)
- if (!$.contains(this.element.ownerDocument.documentElement, this.tip)) {
- $(tip).appendTo(container)
- }
+ const { container } = this._config
+ Data.set(tip, this.constructor.DATA_KEY, this)
- $(this.element).trigger(this.constructor.Event.INSERTED)
+ if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
+ container.appendChild(tip)
+ EventHandler.trigger(this._element, this.constructor.Event.INSERTED)
+ }
- this._popper = new Popper(this.element, tip, this._getPopperConfig(attachment))
+ if (this._popper) {
+ this._popper.update()
+ } else {
+ this._popper = Popper.createPopper(this._element, tip, this._getPopperConfig(attachment))
+ }
- $(tip).addClass(CLASS_NAME_SHOW)
- $(tip).addClass(this.config.customClass)
+ 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
- if ('ontouchstart' in document.documentElement) {
- $(document.body).children().on('mouseover', null, $.noop)
- }
+ const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : this._config.customClass
+ if (customClass) {
+ tip.classList.add(...customClass.split(' '))
+ }
- const complete = () => {
- if (this.config.animation) {
- this._fixTransition()
- }
+ // 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) {
+ [].concat(...document.body.children).forEach(element => {
+ EventHandler.on(element, 'mouseover', noop)
+ })
+ }
- const prevHoverState = this._hoverState
- this._hoverState = null
+ const complete = () => {
+ const prevHoverState = this._hoverState
- $(this.element).trigger(this.constructor.Event.SHOWN)
+ this._hoverState = null
+ EventHandler.trigger(this._element, this.constructor.Event.SHOWN)
- if (prevHoverState === HOVER_STATE_OUT) {
- this._leave(null, this)
- }
+ if (prevHoverState === HOVER_STATE_OUT) {
+ this._leave(null, this)
}
+ }
- if ($(this.tip).hasClass(CLASS_NAME_FADE)) {
- const transitionDuration = Util.getTransitionDurationFromElement(this.tip)
+ const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE)
+ this._queueCallback(complete, this.tip, isAnimated)
+ }
- $(this.tip)
- .one(Util.TRANSITION_END, complete)
- .emulateTransitionEnd(transitionDuration)
- } else {
- complete()
- }
+ hide() {
+ if (!this._popper) {
+ return
}
- }
- hide(callback) {
const tip = this.getTipElement()
- const hideEvent = $.Event(this.constructor.Event.HIDE)
const complete = () => {
- if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
- tip.parentNode.removeChild(tip)
+ if (this._isWithActiveTrigger()) {
+ return
}
- this._cleanTipClass()
- this.element.removeAttribute('aria-describedby')
- $(this.element).trigger(this.constructor.Event.HIDDEN)
- if (this._popper !== null) {
- this._popper.destroy()
+ if (this._hoverState !== HOVER_STATE_SHOW) {
+ tip.remove()
}
- if (callback) {
- callback()
+ this._cleanTipClass()
+ this._element.removeAttribute('aria-describedby')
+ EventHandler.trigger(this._element, this.constructor.Event.HIDDEN)
+
+ if (this._popper) {
+ this._popper.destroy()
+ this._popper = null
}
}
- $(this.element).trigger(hideEvent)
-
- if (hideEvent.isDefaultPrevented()) {
+ const hideEvent = EventHandler.trigger(this._element, this.constructor.Event.HIDE)
+ if (hideEvent.defaultPrevented) {
return
}
- $(tip).removeClass(CLASS_NAME_SHOW)
+ 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) {
- $(document.body).children().off('mouseover', null, $.noop)
+ [].concat(...document.body.children)
+ .forEach(element => EventHandler.off(element, 'mouseover', noop))
}
this._activeTrigger[TRIGGER_CLICK] = false
this._activeTrigger[TRIGGER_FOCUS] = false
this._activeTrigger[TRIGGER_HOVER] = false
- if ($(this.tip).hasClass(CLASS_NAME_FADE)) {
- const transitionDuration = Util.getTransitionDurationFromElement(tip)
-
- $(tip)
- .one(Util.TRANSITION_END, complete)
- .emulateTransitionEnd(transitionDuration)
- } else {
- complete()
- }
-
+ const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE)
+ this._queueCallback(complete, this.tip, isAnimated)
this._hoverState = ''
}
update() {
if (this._popper !== null) {
- this._popper.scheduleUpdate()
+ this._popper.update()
}
}
@@ -386,118 +363,158 @@ class Tooltip {
return Boolean(this.getTitle())
}
- addAttachmentClass(attachment) {
- $(this.getTipElement()).addClass(`${CLASS_PREFIX}-${attachment}`)
- }
-
getTipElement() {
- this.tip = this.tip || $(this.config.template)[0]
+ if (this.tip) {
+ return this.tip
+ }
+
+ const element = document.createElement('div')
+ element.innerHTML = this._config.template
+
+ this.tip = element.children[0]
return this.tip
}
setContent() {
const tip = this.getTipElement()
- this.setElementContent($(tip.querySelectorAll(SELECTOR_TOOLTIP_INNER)), this.getTitle())
- $(tip).removeClass(`${CLASS_NAME_FADE} ${CLASS_NAME_SHOW}`)
+ this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle())
+ tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
}
- setElementContent($element, content) {
- if (typeof content === 'object' && (content.nodeType || content.jquery)) {
- // Content is a DOM node or a jQuery
- if (this.config.html) {
- if (!$(content).parent().is($element)) {
- $element.empty().append(content)
+ setElementContent(element, content) {
+ if (element === null) {
+ return
+ }
+
+ if (isElement(content)) {
+ content = getElement(content)
+
+ // content is a DOM node or a jQuery
+ if (this._config.html) {
+ if (content.parentNode !== element) {
+ element.innerHTML = ''
+ element.appendChild(content)
}
} else {
- $element.text($(content).text())
+ element.textContent = content.textContent
}
return
}
- if (this.config.html) {
- if (this.config.sanitize) {
- content = sanitizeHtml(content, this.config.whiteList, this.config.sanitizeFn)
+ if (this._config.html) {
+ if (this._config.sanitize) {
+ content = sanitizeHtml(content, this._config.allowList, this._config.sanitizeFn)
}
- $element.html(content)
+ element.innerHTML = content
} else {
- $element.text(content)
+ element.textContent = content
}
}
getTitle() {
- let title = this.element.getAttribute('data-original-title')
+ 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
+ updateAttachment(attachment) {
+ if (attachment === 'right') {
+ return 'end'
+ }
- _getPopperConfig(attachment) {
- const defaultBsConfig = {
- placement: attachment,
- modifiers: {
- offset: this._getOffset(),
- flip: {
- behavior: this.config.fallbackPlacement
- },
- arrow: {
- element: SELECTOR_ARROW
- },
- preventOverflow: {
- boundariesElement: this.config.boundary
- }
- },
- onCreate: data => {
- if (data.originalPlacement !== data.placement) {
- this._handlePopperPlacementChange(data)
- }
- },
- onUpdate: data => this._handlePopperPlacementChange(data)
+ if (attachment === 'left') {
+ return 'start'
}
- return {
- ...defaultBsConfig,
- ...this.config.popperConfig
+ return attachment
+ }
+
+ // Private
+
+ _initializeOnDelegatedTarget(event, context) {
+ const dataKey = this.constructor.DATA_KEY
+ context = context || Data.get(event.delegateTarget, dataKey)
+
+ if (!context) {
+ context = new this.constructor(event.delegateTarget, this._getDelegateConfig())
+ Data.set(event.delegateTarget, dataKey, context)
}
+
+ return context
}
_getOffset() {
- const offset = {}
+ const { offset } = this._config
- if (typeof this.config.offset === 'function') {
- offset.fn = data => {
- data.offsets = {
- ...data.offsets,
- ...(this.config.offset(data.offsets, this.element) || {})
- }
+ if (typeof offset === 'string') {
+ return offset.split(',').map(val => Number.parseInt(val, 10))
+ }
- return data
- }
- } else {
- offset.offset = this.config.offset
+ if (typeof offset === 'function') {
+ return popperData => offset(popperData, this._element)
}
return offset
}
- _getContainer() {
- if (this.config.container === false) {
- return document.body
+ _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)
+ }
+ }
}
- if (Util.isElement(this.config.container)) {
- return $(this.config.container)
+ return {
+ ...defaultBsPopperConfig,
+ ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
}
+ }
- return $(document).find(this.config.container)
+ _addAttachmentClass(attachment) {
+ this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`)
}
_getAttachment(placement) {
@@ -505,15 +522,11 @@ class Tooltip {
}
_setListeners() {
- const triggers = this.config.trigger.split(' ')
+ const triggers = this._config.trigger.split(' ')
triggers.forEach(trigger => {
if (trigger === 'click') {
- $(this.element).on(
- this.constructor.Event.CLICK,
- this.config.selector,
- event => this.toggle(event)
- )
+ EventHandler.on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event))
} else if (trigger !== TRIGGER_MANUAL) {
const eventIn = trigger === TRIGGER_HOVER ?
this.constructor.Event.MOUSEENTER :
@@ -522,23 +535,22 @@ class Tooltip {
this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT
- $(this.element)
- .on(eventIn, this.config.selector, event => this._enter(event))
- .on(eventOut, this.config.selector, event => this._leave(event))
+ EventHandler.on(this._element, eventIn, this._config.selector, event => this._enter(event))
+ EventHandler.on(this._element, eventOut, this._config.selector, event => this._leave(event))
}
})
this._hideModalHandler = () => {
- if (this.element) {
+ if (this._element) {
this.hide()
}
}
- $(this.element).closest('.modal').on('hide.bs.modal', this._hideModalHandler)
+ EventHandler.on(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
- if (this.config.selector) {
- this.config = {
- ...this.config,
+ if (this._config.selector) {
+ this._config = {
+ ...this._config,
trigger: 'manual',
selector: ''
}
@@ -548,29 +560,21 @@ class Tooltip {
}
_fixTitle() {
- const titleType = typeof this.element.getAttribute('data-original-title')
+ const title = this._element.getAttribute('title')
+ const originalTitleType = typeof this._element.getAttribute('data-bs-original-title')
- if (this.element.getAttribute('title') || titleType !== 'string') {
- this.element.setAttribute(
- 'data-original-title',
- this.element.getAttribute('title') || ''
- )
+ if (title || originalTitleType !== 'string') {
+ this._element.setAttribute('data-bs-original-title', title || '')
+ if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
+ this._element.setAttribute('aria-label', title)
+ }
- this.element.setAttribute('title', '')
+ this._element.setAttribute('title', '')
}
}
_enter(event, context) {
- const dataKey = this.constructor.DATA_KEY
- context = context || $(event.currentTarget).data(dataKey)
-
- if (!context) {
- context = new this.constructor(
- event.currentTarget,
- this._getDelegateConfig()
- )
- $(event.currentTarget).data(dataKey, context)
- }
+ context = this._initializeOnDelegatedTarget(event, context)
if (event) {
context._activeTrigger[
@@ -578,7 +582,7 @@ class Tooltip {
] = true
}
- if ($(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
}
@@ -587,7 +591,7 @@ class Tooltip {
context._hoverState = HOVER_STATE_SHOW
- if (!context.config.delay || !context.config.delay.show) {
+ if (!context._config.delay || !context._config.delay.show) {
context.show()
return
}
@@ -596,25 +600,16 @@ class Tooltip {
if (context._hoverState === HOVER_STATE_SHOW) {
context.show()
}
- }, context.config.delay.show)
+ }, context._config.delay.show)
}
_leave(event, context) {
- const dataKey = this.constructor.DATA_KEY
- context = context || $(event.currentTarget).data(dataKey)
-
- if (!context) {
- context = new this.constructor(
- event.currentTarget,
- this._getDelegateConfig()
- )
- $(event.currentTarget).data(dataKey, context)
- }
+ context = this._initializeOnDelegatedTarget(event, context)
if (event) {
context._activeTrigger[
event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER
- ] = false
+ ] = context._element.contains(event.relatedTarget)
}
if (context._isWithActiveTrigger()) {
@@ -625,7 +620,7 @@ class Tooltip {
context._hoverState = HOVER_STATE_OUT
- if (!context.config.delay || !context.config.delay.hide) {
+ if (!context._config.delay || !context._config.delay.hide) {
context.hide()
return
}
@@ -634,7 +629,7 @@ class Tooltip {
if (context._hoverState === HOVER_STATE_OUT) {
context.hide()
}
- }, context.config.delay.hide)
+ }, context._config.delay.hide)
}
_isWithActiveTrigger() {
@@ -648,14 +643,13 @@ class Tooltip {
}
_getConfig(config) {
- const dataAttributes = $(this.element).data()
+ const dataAttributes = Manipulator.getDataAttributes(this._element)
- Object.keys(dataAttributes)
- .forEach(dataAttr => {
- if (DISALLOWED_ATTRIBUTES.indexOf(dataAttr) !== -1) {
- delete dataAttributes[dataAttr]
- }
- })
+ Object.keys(dataAttributes).forEach(dataAttr => {
+ if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
+ delete dataAttributes[dataAttr]
+ }
+ })
config = {
...this.constructor.Default,
@@ -663,6 +657,8 @@ class Tooltip {
...(typeof config === 'object' && config ? config : {})
}
+ config.container = config.container === false ? document.body : getElement(config.container)
+
if (typeof config.delay === 'number') {
config.delay = {
show: config.delay,
@@ -678,14 +674,10 @@ class Tooltip {
config.content = config.content.toString()
}
- Util.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
@@ -694,10 +686,10 @@ class Tooltip {
_getDelegateConfig() {
const config = {}
- if (this.config) {
- for (const key in this.config) {
- if (this.constructor.Default[key] !== this.config[key]) {
- config[key] = this.config[key]
+ if (this._config) {
+ for (const key in this._config) {
+ if (this.constructor.Default[key] !== this._config[key]) {
+ config[key] = this._config[key]
}
}
}
@@ -706,50 +698,31 @@ class Tooltip {
}
_cleanTipClass() {
- const $tip = $(this.getTipElement())
- const tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX)
- if (tabClass !== null && tabClass.length) {
- $tip.removeClass(tabClass.join(''))
+ const tip = this.getTipElement()
+ const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
+ if (tabClass !== null && tabClass.length > 0) {
+ tabClass.map(token => token.trim())
+ .forEach(tClass => tip.classList.remove(tClass))
}
}
_handlePopperPlacementChange(popperData) {
- this.tip = popperData.instance.popper
- this._cleanTipClass()
- this.addAttachmentClass(this._getAttachment(popperData.placement))
- }
-
- _fixTransition() {
- const tip = this.getTipElement()
- const initConfigAnimation = this.config.animation
+ const { state } = popperData
- if (tip.getAttribute('x-placement') !== null) {
+ if (!state) {
return
}
- $(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
- static _jQueryInterface(config) {
+ static jQueryInterface(config) {
return this.each(function () {
- const $element = $(this)
- let data = $element.data(DATA_KEY)
- const _config = typeof config === 'object' && config
-
- if (!data && /dispose|hide/.test(config)) {
- return
- }
-
- if (!data) {
- data = new Tooltip(this, _config)
- $element.data(DATA_KEY, data)
- }
+ const data = Tooltip.getOrCreateInstance(this, config)
if (typeof config === 'string') {
if (typeof data[config] === 'undefined') {
@@ -766,13 +739,9 @@ class Tooltip {
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
+ * add .Tooltip to jQuery only if jQuery is present
*/
-$.fn[NAME] = Tooltip._jQueryInterface
-$.fn[NAME].Constructor = Tooltip
-$.fn[NAME].noConflict = () => {
- $.fn[NAME] = JQUERY_NO_CONFLICT
- return Tooltip._jQueryInterface
-}
+defineJQueryPlugin(Tooltip)
export default Tooltip