aboutsummaryrefslogtreecommitdiff
path: root/js/src/tooltip.js
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2020-03-07 11:31:42 +0200
committerXhmikosR <[email protected]>2020-03-18 12:58:54 +0200
commit38333feda548fa973e034de03d34429a1f214089 (patch)
tree5626c4eb68f38bc03a4b26498d110ac150a24d2d /js/src/tooltip.js
parentcece839fc98caa12e73715a2351845580f74c51b (diff)
downloadbootstrap-38333feda548fa973e034de03d34429a1f214089.tar.xz
bootstrap-38333feda548fa973e034de03d34429a1f214089.zip
Switch to strings constants.
This allows the minifier to mangle the constants. It also allows the linter to find unused strings properly. While at it, remove a few unused properties. File Before After Diff -------------------------------------------------------- bootstrap.bundle.min.js 23.61 kB 22.61 kB -1.00 kB (-4.23 %) bootstrap.min.js 17.04 kB 16.08 kB -0.96 kB (-5.63 %)
Diffstat (limited to 'js/src/tooltip.js')
-rw-r--r--js/src/tooltip.js88
1 files changed, 40 insertions, 48 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index 9b2ae6f61..b723b1ba8 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -89,11 +89,6 @@ const Default = {
popperConfig: null
}
-const HoverState = {
- SHOW: 'show',
- OUT: 'out'
-}
-
const Event = {
HIDE: `hide${EVENT_KEY}`,
HIDDEN: `hidden${EVENT_KEY}`,
@@ -107,22 +102,19 @@ const Event = {
MOUSELEAVE: `mouseleave${EVENT_KEY}`
}
-const ClassName = {
- FADE: 'fade',
- MODAL: 'modal',
- SHOW: 'show'
-}
+const CLASS_NAME_FADE = 'fade'
+const CLASS_NAME_MODAL = 'modal'
+const CLASS_NAME_SHOW = 'show'
-const Selector = {
- TOOLTIP_INNER: '.tooltip-inner'
-}
+const HOVER_STATE_SHOW = 'show'
+const HOVER_STATE_OUT = 'out'
-const Trigger = {
- HOVER: 'hover',
- FOCUS: 'focus',
- CLICK: 'click',
- MANUAL: 'manual'
-}
+const SELECTOR_TOOLTIP_INNER = '.tooltip-inner'
+
+const TRIGGER_HOVER = 'hover'
+const TRIGGER_FOCUS = 'focus'
+const TRIGGER_CLICK = 'click'
+const TRIGGER_MANUAL = 'manual'
/**
* ------------------------------------------------------------------------
@@ -221,7 +213,7 @@ class Tooltip {
context._leave(null, context)
}
} else {
- if (this.getTipElement().classList.contains(ClassName.SHOW)) {
+ if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) {
this._leave(null, this)
return
}
@@ -236,7 +228,7 @@ class Tooltip {
Data.removeData(this.element, this.constructor.DATA_KEY)
EventHandler.off(this.element, this.constructor.EVENT_KEY)
- EventHandler.off(SelectorEngine.closest(this.element, `.${ClassName.MODAL}`), 'hide.bs.modal', this._hideModalHandler)
+ EventHandler.off(SelectorEngine.closest(this.element, `.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler)
if (this.tip) {
this.tip.parentNode.removeChild(this.tip)
@@ -281,7 +273,7 @@ class Tooltip {
this.setContent()
if (this.config.animation) {
- tip.classList.add(ClassName.FADE)
+ tip.classList.add(CLASS_NAME_FADE)
}
const placement = typeof this.config.placement === 'function' ?
@@ -302,7 +294,7 @@ class Tooltip {
this._popper = new Popper(this.element, tip, this._getPopperConfig(attachment))
- tip.classList.add(ClassName.SHOW)
+ 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;
@@ -324,12 +316,12 @@ class Tooltip {
EventHandler.trigger(this.element, this.constructor.Event.SHOWN)
- if (prevHoverState === HoverState.OUT) {
+ if (prevHoverState === HOVER_STATE_OUT) {
this._leave(null, this)
}
}
- if (this.tip.classList.contains(ClassName.FADE)) {
+ if (this.tip.classList.contains(CLASS_NAME_FADE)) {
const transitionDuration = getTransitionDurationFromElement(this.tip)
EventHandler.one(this.tip, TRANSITION_END, complete)
emulateTransitionEnd(this.tip, transitionDuration)
@@ -342,7 +334,7 @@ class Tooltip {
hide() {
const tip = this.getTipElement()
const complete = () => {
- if (this._hoverState !== HoverState.SHOW && tip.parentNode) {
+ if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) {
tip.parentNode.removeChild(tip)
}
@@ -357,7 +349,7 @@ class Tooltip {
return
}
- tip.classList.remove(ClassName.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
@@ -366,11 +358,11 @@ class Tooltip {
.forEach(element => EventHandler.off(element, 'mouseover', noop))
}
- this._activeTrigger[Trigger.CLICK] = false
- this._activeTrigger[Trigger.FOCUS] = false
- this._activeTrigger[Trigger.HOVER] = false
+ this._activeTrigger[TRIGGER_CLICK] = false
+ this._activeTrigger[TRIGGER_FOCUS] = false
+ this._activeTrigger[TRIGGER_HOVER] = false
- if (this.tip.classList.contains(ClassName.FADE)) {
+ if (this.tip.classList.contains(CLASS_NAME_FADE)) {
const transitionDuration = getTransitionDurationFromElement(tip)
EventHandler.one(tip, TRANSITION_END, complete)
@@ -408,9 +400,9 @@ class Tooltip {
setContent() {
const tip = this.getTipElement()
- this.setElementContent(SelectorEngine.findOne(Selector.TOOLTIP_INNER, tip), this.getTitle())
- tip.classList.remove(ClassName.FADE)
- tip.classList.remove(ClassName.SHOW)
+ this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle())
+ tip.classList.remove(CLASS_NAME_FADE)
+ tip.classList.remove(CLASS_NAME_SHOW)
}
setElementContent(element, content) {
@@ -539,11 +531,11 @@ class Tooltip {
this.config.selector,
event => this.toggle(event)
)
- } else if (trigger !== Trigger.MANUAL) {
- const eventIn = trigger === Trigger.HOVER ?
+ } else if (trigger !== TRIGGER_MANUAL) {
+ const eventIn = trigger === TRIGGER_HOVER ?
this.constructor.Event.MOUSEENTER :
this.constructor.Event.FOCUSIN
- const eventOut = trigger === Trigger.HOVER ?
+ const eventOut = trigger === TRIGGER_HOVER ?
this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT
@@ -566,7 +558,7 @@ class Tooltip {
}
}
- EventHandler.on(SelectorEngine.closest(this.element, `.${ClassName.MODAL}`),
+ EventHandler.on(SelectorEngine.closest(this.element, `.${CLASS_NAME_MODAL}`),
'hide.bs.modal',
this._hideModalHandler
)
@@ -609,19 +601,19 @@ class Tooltip {
if (event) {
context._activeTrigger[
- event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER
+ event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER
] = true
}
- if (context.getTipElement().classList.contains(ClassName.SHOW) ||
- context._hoverState === HoverState.SHOW) {
- context._hoverState = HoverState.SHOW
+ if (context.getTipElement().classList.contains(CLASS_NAME_SHOW) ||
+ context._hoverState === HOVER_STATE_SHOW) {
+ context._hoverState = HOVER_STATE_SHOW
return
}
clearTimeout(context._timeout)
- context._hoverState = HoverState.SHOW
+ context._hoverState = HOVER_STATE_SHOW
if (!context.config.delay || !context.config.delay.show) {
context.show()
@@ -629,7 +621,7 @@ class Tooltip {
}
context._timeout = setTimeout(() => {
- if (context._hoverState === HoverState.SHOW) {
+ if (context._hoverState === HOVER_STATE_SHOW) {
context.show()
}
}, context.config.delay.show)
@@ -649,7 +641,7 @@ class Tooltip {
if (event) {
context._activeTrigger[
- event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER
+ event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER
] = false
}
@@ -659,7 +651,7 @@ class Tooltip {
clearTimeout(context._timeout)
- context._hoverState = HoverState.OUT
+ context._hoverState = HOVER_STATE_OUT
if (!context.config.delay || !context.config.delay.hide) {
context.hide()
@@ -667,7 +659,7 @@ class Tooltip {
}
context._timeout = setTimeout(() => {
- if (context._hoverState === HoverState.OUT) {
+ if (context._hoverState === HOVER_STATE_OUT) {
context.hide()
}
}, context.config.delay.hide)
@@ -768,7 +760,7 @@ class Tooltip {
return
}
- tip.classList.remove(ClassName.FADE)
+ tip.classList.remove(CLASS_NAME_FADE)
this.config.animation = false
this.hide()
this.show()