@coreui/coreui 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +183 -0
- package/dist/css/coreui-grid.css +5004 -0
- package/dist/css/coreui-grid.css.map +1 -0
- package/dist/css/coreui-grid.min.css +8 -0
- package/dist/css/coreui-grid.min.css.map +1 -0
- package/dist/css/coreui-grid.rtl.css +5011 -0
- package/dist/css/coreui-grid.rtl.css.map +1 -0
- package/dist/css/coreui-grid.rtl.min.css +14 -0
- package/dist/css/coreui-grid.rtl.min.css.map +1 -0
- package/dist/css/coreui-reboot.css +440 -0
- package/dist/css/coreui-reboot.css.map +1 -0
- package/dist/css/coreui-reboot.min.css +8 -0
- package/dist/css/coreui-reboot.min.css.map +1 -0
- package/dist/css/coreui-reboot.rtl.css +441 -0
- package/dist/css/coreui-reboot.rtl.css.map +1 -0
- package/dist/css/coreui-reboot.rtl.min.css +14 -0
- package/dist/css/coreui-reboot.rtl.min.css.map +1 -0
- package/dist/css/coreui-utilities.css +5030 -0
- package/dist/css/coreui-utilities.css.map +1 -0
- package/dist/css/coreui-utilities.min.css +8 -0
- package/dist/css/coreui-utilities.min.css.map +1 -0
- package/dist/css/coreui-utilities.rtl.css +5024 -0
- package/dist/css/coreui-utilities.rtl.css.map +1 -0
- package/dist/css/coreui-utilities.rtl.min.css +14 -0
- package/dist/css/coreui-utilities.rtl.min.css.map +1 -0
- package/dist/css/coreui.css +12152 -0
- package/dist/css/coreui.css.map +1 -0
- package/dist/css/coreui.min.css +8 -0
- package/dist/css/coreui.min.css.map +1 -0
- package/dist/css/coreui.rtl.css +12041 -0
- package/dist/css/coreui.rtl.css.map +1 -0
- package/dist/css/coreui.rtl.min.css +14 -0
- package/dist/css/coreui.rtl.min.css.map +1 -0
- package/dist/js/coreui.bundle.js +7437 -0
- package/dist/js/coreui.bundle.js.map +1 -0
- package/dist/js/coreui.bundle.min.js +7 -0
- package/dist/js/coreui.bundle.min.js.map +1 -0
- package/dist/js/coreui.esm.js +5622 -0
- package/dist/js/coreui.esm.js.map +1 -0
- package/dist/js/coreui.esm.min.js +7 -0
- package/dist/js/coreui.esm.min.js.map +1 -0
- package/dist/js/coreui.js +5673 -0
- package/dist/js/coreui.js.map +1 -0
- package/dist/js/coreui.min.js +7 -0
- package/dist/js/coreui.min.js.map +1 -0
- package/js/dist/alert.js +208 -0
- package/js/dist/alert.js.map +1 -0
- package/js/dist/base-component.js +181 -0
- package/js/dist/base-component.js.map +1 -0
- package/js/dist/button.js +142 -0
- package/js/dist/button.js.map +1 -0
- package/js/dist/carousel.js +724 -0
- package/js/dist/carousel.js.map +1 -0
- package/js/dist/collapse.js +515 -0
- package/js/dist/collapse.js.map +1 -0
- package/js/dist/dom/data.js +72 -0
- package/js/dist/dom/data.js.map +1 -0
- package/js/dist/dom/event-handler.js +319 -0
- package/js/dist/dom/event-handler.js.map +1 -0
- package/js/dist/dom/manipulator.js +92 -0
- package/js/dist/dom/manipulator.js.map +1 -0
- package/js/dist/dom/selector-engine.js +89 -0
- package/js/dist/dom/selector-engine.js.map +1 -0
- package/js/dist/dropdown.js +700 -0
- package/js/dist/dropdown.js.map +1 -0
- package/js/dist/modal.js +891 -0
- package/js/dist/modal.js.map +1 -0
- package/js/dist/offcanvas.js +724 -0
- package/js/dist/offcanvas.js.map +1 -0
- package/js/dist/popover.js +220 -0
- package/js/dist/popover.js.map +1 -0
- package/js/dist/scrollspy.js +387 -0
- package/js/dist/scrollspy.js.map +1 -0
- package/js/dist/tab.js +317 -0
- package/js/dist/tab.js.map +1 -0
- package/js/dist/toast.js +331 -0
- package/js/dist/toast.js.map +1 -0
- package/js/dist/tooltip.js +997 -0
- package/js/dist/tooltip.js.map +1 -0
- package/js/src/alert.js +128 -0
- package/js/src/base-component.js +78 -0
- package/js/src/button.js +89 -0
- package/js/src/carousel.js +589 -0
- package/js/src/collapse.js +391 -0
- package/js/src/dom/data.js +60 -0
- package/js/src/dom/event-handler.js +352 -0
- package/js/src/dom/manipulator.js +83 -0
- package/js/src/dom/selector-engine.js +78 -0
- package/js/src/dropdown.js +517 -0
- package/js/src/modal.js +451 -0
- package/js/src/navigation.js +298 -0
- package/js/src/offcanvas.js +277 -0
- package/js/src/popover.js +173 -0
- package/js/src/scrollspy.js +298 -0
- package/js/src/sidebar.js +347 -0
- package/js/src/tab.js +227 -0
- package/js/src/toast.js +245 -0
- package/js/src/tooltip.js +750 -0
- package/js/src/util/backdrop.js +129 -0
- package/js/src/util/index.js +327 -0
- package/js/src/util/sanitizer.js +130 -0
- package/js/src/util/scrollbar.js +97 -0
- package/package.json +166 -0
- package/scss/_accordion.scss +118 -0
- package/scss/_alert.scss +52 -0
- package/scss/_avatar.scss +49 -0
- package/scss/_badge.scss +38 -0
- package/scss/_breadcrumb.scss +33 -0
- package/scss/_button-group.scss +139 -0
- package/scss/_buttons.scss +143 -0
- package/scss/_callout.scss +16 -0
- package/scss/_card.scss +215 -0
- package/scss/_carousel.scss +231 -0
- package/scss/_close.scss +40 -0
- package/scss/_containers.scss +41 -0
- package/scss/_dropdown.scss +227 -0
- package/scss/_footer.scss +25 -0
- package/scss/_forms.scss +9 -0
- package/scss/_functions.scss +356 -0
- package/scss/_grid.scss +56 -0
- package/scss/_header.scss +170 -0
- package/scss/_helpers.scss +7 -0
- package/scss/_icon.scss +32 -0
- package/scss/_images.scss +42 -0
- package/scss/_list-group.scss +169 -0
- package/scss/_mixins.scss +50 -0
- package/scss/_modal.scss +219 -0
- package/scss/_nav.scss +140 -0
- package/scss/_navbar.scss +254 -0
- package/scss/_offcanvas.scss +79 -0
- package/scss/_pagination.scss +64 -0
- package/scss/_popover.scss +158 -0
- package/scss/_progress.scss +91 -0
- package/scss/_reboot.scss +632 -0
- package/scss/_root.scss +25 -0
- package/scss/_sidebar.scss +3 -0
- package/scss/_spinners.scss +69 -0
- package/scss/_subheader.scss +72 -0
- package/scss/_tables.scss +166 -0
- package/scss/_toasts.scss +52 -0
- package/scss/_tooltip.scss +115 -0
- package/scss/_transitions.scss +21 -0
- package/scss/_type.scss +104 -0
- package/scss/_utilities.scss +678 -0
- package/scss/_variables.scss +1801 -0
- package/scss/coreui-grid.rtl.scss +12 -0
- package/scss/coreui-grid.scss +67 -0
- package/scss/coreui-reboot.rtl.scss +12 -0
- package/scss/coreui-reboot.scss +15 -0
- package/scss/coreui-utilities.rtl.scss +12 -0
- package/scss/coreui-utilities.scss +19 -0
- package/scss/coreui.rtl.scss +12 -0
- package/scss/coreui.scss +61 -0
- package/scss/forms/_floating-labels.scss +63 -0
- package/scss/forms/_form-check.scss +188 -0
- package/scss/forms/_form-control.scss +219 -0
- package/scss/forms/_form-range.scss +91 -0
- package/scss/forms/_form-select.scss +70 -0
- package/scss/forms/_form-text.scss +11 -0
- package/scss/forms/_input-group.scss +121 -0
- package/scss/forms/_labels.scss +36 -0
- package/scss/forms/_validation.scss +12 -0
- package/scss/helpers/_clearfix.scss +3 -0
- package/scss/helpers/_colored-links.scss +12 -0
- package/scss/helpers/_position.scss +30 -0
- package/scss/helpers/_ratio.scss +26 -0
- package/scss/helpers/_stretched-link.scss +15 -0
- package/scss/helpers/_text-truncation.scss +7 -0
- package/scss/helpers/_visually-hidden.scss +8 -0
- package/scss/mixins/_alert.scss +15 -0
- package/scss/mixins/_avatar.scss +10 -0
- package/scss/mixins/_border-radius.scss +78 -0
- package/scss/mixins/_box-shadow.scss +18 -0
- package/scss/mixins/_breakpoints.scss +140 -0
- package/scss/mixins/_buttons.scss +101 -0
- package/scss/mixins/_caret.scss +64 -0
- package/scss/mixins/_clearfix.scss +9 -0
- package/scss/mixins/_color-scheme.scss +7 -0
- package/scss/mixins/_container.scss +9 -0
- package/scss/mixins/_css-vars.scss +87 -0
- package/scss/mixins/_deprecate.scss +10 -0
- package/scss/mixins/_forms.scss +144 -0
- package/scss/mixins/_gradients.scss +47 -0
- package/scss/mixins/_grid.scss +132 -0
- package/scss/mixins/_icon.scss +6 -0
- package/scss/mixins/_image.scss +16 -0
- package/scss/mixins/_list-group.scss +18 -0
- package/scss/mixins/_lists.scss +7 -0
- package/scss/mixins/_ltr-rtl.scss +60 -0
- package/scss/mixins/_pagination.scss +31 -0
- package/scss/mixins/_reset-text.scss +17 -0
- package/scss/mixins/_resize.scss +6 -0
- package/scss/mixins/_table-variants.scss +16 -0
- package/scss/mixins/_text-truncate.scss +8 -0
- package/scss/mixins/_transition.scss +26 -0
- package/scss/mixins/_utilities.scss +104 -0
- package/scss/mixins/_visually-hidden.scss +29 -0
- package/scss/sidebar/_sidebar-narrow.scss +106 -0
- package/scss/sidebar/_sidebar-nav.scss +165 -0
- package/scss/sidebar/_sidebar.scss +261 -0
- package/scss/utilities/_api.scss +47 -0
- package/scss/vendor/_rfs.scss +354 -0
|
@@ -0,0 +1,750 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* CoreUI (v4.0.2): tooltip.js
|
|
4
|
+
* Licensed under MIT (https://coreui.io/license)
|
|
5
|
+
*
|
|
6
|
+
* This component is a modified version of the Bootstrap's tooltip.js
|
|
7
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
8
|
+
* --------------------------------------------------------------------------
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as Popper from '@popperjs/core'
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
defineJQueryPlugin,
|
|
15
|
+
findShadowRoot,
|
|
16
|
+
getElement,
|
|
17
|
+
getUID,
|
|
18
|
+
isElement,
|
|
19
|
+
isRTL,
|
|
20
|
+
noop,
|
|
21
|
+
typeCheckConfig
|
|
22
|
+
} from './util/index'
|
|
23
|
+
import {
|
|
24
|
+
DefaultAllowlist,
|
|
25
|
+
sanitizeHtml
|
|
26
|
+
} from './util/sanitizer'
|
|
27
|
+
import Data from './dom/data'
|
|
28
|
+
import EventHandler from './dom/event-handler'
|
|
29
|
+
import Manipulator from './dom/manipulator'
|
|
30
|
+
import SelectorEngine from './dom/selector-engine'
|
|
31
|
+
import BaseComponent from './base-component'
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* ------------------------------------------------------------------------
|
|
35
|
+
* Constants
|
|
36
|
+
* ------------------------------------------------------------------------
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
const NAME = 'tooltip'
|
|
40
|
+
const DATA_KEY = 'coreui.tooltip'
|
|
41
|
+
const EVENT_KEY = `.${DATA_KEY}`
|
|
42
|
+
const CLASS_PREFIX = 'bs-tooltip'
|
|
43
|
+
const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
|
|
44
|
+
const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn'])
|
|
45
|
+
|
|
46
|
+
const DefaultType = {
|
|
47
|
+
animation: 'boolean',
|
|
48
|
+
template: 'string',
|
|
49
|
+
title: '(string|element|function)',
|
|
50
|
+
trigger: 'string',
|
|
51
|
+
delay: '(number|object)',
|
|
52
|
+
html: 'boolean',
|
|
53
|
+
selector: '(string|boolean)',
|
|
54
|
+
placement: '(string|function)',
|
|
55
|
+
offset: '(array|string|function)',
|
|
56
|
+
container: '(string|element|boolean)',
|
|
57
|
+
fallbackPlacements: 'array',
|
|
58
|
+
boundary: '(string|element)',
|
|
59
|
+
customClass: '(string|function)',
|
|
60
|
+
sanitize: 'boolean',
|
|
61
|
+
sanitizeFn: '(null|function)',
|
|
62
|
+
allowList: 'object',
|
|
63
|
+
popperConfig: '(null|object|function)'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const AttachmentMap = {
|
|
67
|
+
AUTO: 'auto',
|
|
68
|
+
TOP: 'top',
|
|
69
|
+
RIGHT: isRTL() ? 'left' : 'right',
|
|
70
|
+
BOTTOM: 'bottom',
|
|
71
|
+
LEFT: isRTL() ? 'right' : 'left'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const Default = {
|
|
75
|
+
animation: true,
|
|
76
|
+
template: '<div class="tooltip" role="tooltip">' +
|
|
77
|
+
'<div class="tooltip-arrow"></div>' +
|
|
78
|
+
'<div class="tooltip-inner"></div>' +
|
|
79
|
+
'</div>',
|
|
80
|
+
trigger: 'hover focus',
|
|
81
|
+
title: '',
|
|
82
|
+
delay: 0,
|
|
83
|
+
html: false,
|
|
84
|
+
selector: false,
|
|
85
|
+
placement: 'top',
|
|
86
|
+
offset: [0, 0],
|
|
87
|
+
container: false,
|
|
88
|
+
fallbackPlacements: ['top', 'right', 'bottom', 'left'],
|
|
89
|
+
boundary: 'clippingParents',
|
|
90
|
+
customClass: '',
|
|
91
|
+
sanitize: true,
|
|
92
|
+
sanitizeFn: null,
|
|
93
|
+
allowList: DefaultAllowlist,
|
|
94
|
+
popperConfig: null
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const Event = {
|
|
98
|
+
HIDE: `hide${EVENT_KEY}`,
|
|
99
|
+
HIDDEN: `hidden${EVENT_KEY}`,
|
|
100
|
+
SHOW: `show${EVENT_KEY}`,
|
|
101
|
+
SHOWN: `shown${EVENT_KEY}`,
|
|
102
|
+
INSERTED: `inserted${EVENT_KEY}`,
|
|
103
|
+
CLICK: `click${EVENT_KEY}`,
|
|
104
|
+
FOCUSIN: `focusin${EVENT_KEY}`,
|
|
105
|
+
FOCUSOUT: `focusout${EVENT_KEY}`,
|
|
106
|
+
MOUSEENTER: `mouseenter${EVENT_KEY}`,
|
|
107
|
+
MOUSELEAVE: `mouseleave${EVENT_KEY}`
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const CLASS_NAME_FADE = 'fade'
|
|
111
|
+
const CLASS_NAME_MODAL = 'modal'
|
|
112
|
+
const CLASS_NAME_SHOW = 'show'
|
|
113
|
+
|
|
114
|
+
const HOVER_STATE_SHOW = 'show'
|
|
115
|
+
const HOVER_STATE_OUT = 'out'
|
|
116
|
+
|
|
117
|
+
const SELECTOR_TOOLTIP_INNER = '.tooltip-inner'
|
|
118
|
+
|
|
119
|
+
const TRIGGER_HOVER = 'hover'
|
|
120
|
+
const TRIGGER_FOCUS = 'focus'
|
|
121
|
+
const TRIGGER_CLICK = 'click'
|
|
122
|
+
const TRIGGER_MANUAL = 'manual'
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* ------------------------------------------------------------------------
|
|
126
|
+
* Class Definition
|
|
127
|
+
* ------------------------------------------------------------------------
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
class Tooltip extends BaseComponent {
|
|
131
|
+
constructor(element, config) {
|
|
132
|
+
if (typeof Popper === 'undefined') {
|
|
133
|
+
throw new TypeError('Bootstrap\'s tooltips require Popper (https://popper.js.org)')
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
super(element)
|
|
137
|
+
|
|
138
|
+
// private
|
|
139
|
+
this._isEnabled = true
|
|
140
|
+
this._timeout = 0
|
|
141
|
+
this._hoverState = ''
|
|
142
|
+
this._activeTrigger = {}
|
|
143
|
+
this._popper = null
|
|
144
|
+
|
|
145
|
+
// Protected
|
|
146
|
+
this._config = this._getConfig(config)
|
|
147
|
+
this.tip = null
|
|
148
|
+
|
|
149
|
+
this._setListeners()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Getters
|
|
153
|
+
|
|
154
|
+
static get Default() {
|
|
155
|
+
return Default
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static get NAME() {
|
|
159
|
+
return NAME
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static get Event() {
|
|
163
|
+
return Event
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static get DefaultType() {
|
|
167
|
+
return DefaultType
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Public
|
|
171
|
+
|
|
172
|
+
enable() {
|
|
173
|
+
this._isEnabled = true
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
disable() {
|
|
177
|
+
this._isEnabled = false
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
toggleEnabled() {
|
|
181
|
+
this._isEnabled = !this._isEnabled
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
toggle(event) {
|
|
185
|
+
if (!this._isEnabled) {
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (event) {
|
|
190
|
+
const context = this._initializeOnDelegatedTarget(event)
|
|
191
|
+
|
|
192
|
+
context._activeTrigger.click = !context._activeTrigger.click
|
|
193
|
+
|
|
194
|
+
if (context._isWithActiveTrigger()) {
|
|
195
|
+
context._enter(null, context)
|
|
196
|
+
} else {
|
|
197
|
+
context._leave(null, context)
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
if (this.getTipElement().classList.contains(CLASS_NAME_SHOW)) {
|
|
201
|
+
this._leave(null, this)
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
this._enter(null, this)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
dispose() {
|
|
210
|
+
clearTimeout(this._timeout)
|
|
211
|
+
|
|
212
|
+
EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.coreui.modal', this._hideModalHandler)
|
|
213
|
+
|
|
214
|
+
if (this.tip) {
|
|
215
|
+
this.tip.remove()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (this._popper) {
|
|
219
|
+
this._popper.destroy()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
super.dispose()
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
show() {
|
|
226
|
+
if (this._element.style.display === 'none') {
|
|
227
|
+
throw new Error('Please use show on visible elements')
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!(this.isWithContent() && this._isEnabled)) {
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const showEvent = EventHandler.trigger(this._element, this.constructor.Event.SHOW)
|
|
235
|
+
const shadowRoot = findShadowRoot(this._element)
|
|
236
|
+
const isInTheDom = shadowRoot === null ?
|
|
237
|
+
this._element.ownerDocument.documentElement.contains(this._element) :
|
|
238
|
+
shadowRoot.contains(this._element)
|
|
239
|
+
|
|
240
|
+
if (showEvent.defaultPrevented || !isInTheDom) {
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const tip = this.getTipElement()
|
|
245
|
+
const tipId = getUID(this.constructor.NAME)
|
|
246
|
+
|
|
247
|
+
tip.setAttribute('id', tipId)
|
|
248
|
+
this._element.setAttribute('aria-describedby', tipId)
|
|
249
|
+
|
|
250
|
+
this.setContent()
|
|
251
|
+
|
|
252
|
+
if (this._config.animation) {
|
|
253
|
+
tip.classList.add(CLASS_NAME_FADE)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const placement = typeof this._config.placement === 'function' ?
|
|
257
|
+
this._config.placement.call(this, tip, this._element) :
|
|
258
|
+
this._config.placement
|
|
259
|
+
|
|
260
|
+
const attachment = this._getAttachment(placement)
|
|
261
|
+
this._addAttachmentClass(attachment)
|
|
262
|
+
|
|
263
|
+
const { container } = this._config
|
|
264
|
+
Data.set(tip, this.constructor.DATA_KEY, this)
|
|
265
|
+
|
|
266
|
+
if (!this._element.ownerDocument.documentElement.contains(this.tip)) {
|
|
267
|
+
container.appendChild(tip)
|
|
268
|
+
EventHandler.trigger(this._element, this.constructor.Event.INSERTED)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (this._popper) {
|
|
272
|
+
this._popper.update()
|
|
273
|
+
} else {
|
|
274
|
+
this._popper = Popper.createPopper(this._element, tip, this._getPopperConfig(attachment))
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
tip.classList.add(CLASS_NAME_SHOW)
|
|
278
|
+
|
|
279
|
+
const customClass = typeof this._config.customClass === 'function' ? this._config.customClass() : this._config.customClass
|
|
280
|
+
if (customClass) {
|
|
281
|
+
tip.classList.add(...customClass.split(' '))
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// If this is a touch-enabled device we add extra
|
|
285
|
+
// empty mouseover listeners to the body's immediate children;
|
|
286
|
+
// only needed because of broken event delegation on iOS
|
|
287
|
+
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
|
|
288
|
+
if ('ontouchstart' in document.documentElement) {
|
|
289
|
+
[].concat(...document.body.children).forEach(element => {
|
|
290
|
+
EventHandler.on(element, 'mouseover', noop)
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const complete = () => {
|
|
295
|
+
const prevHoverState = this._hoverState
|
|
296
|
+
|
|
297
|
+
this._hoverState = null
|
|
298
|
+
EventHandler.trigger(this._element, this.constructor.Event.SHOWN)
|
|
299
|
+
|
|
300
|
+
if (prevHoverState === HOVER_STATE_OUT) {
|
|
301
|
+
this._leave(null, this)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE)
|
|
306
|
+
this._queueCallback(complete, this.tip, isAnimated)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
hide() {
|
|
310
|
+
if (!this._popper) {
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const tip = this.getTipElement()
|
|
315
|
+
const complete = () => {
|
|
316
|
+
if (this._isWithActiveTrigger()) {
|
|
317
|
+
return
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (this._hoverState !== HOVER_STATE_SHOW) {
|
|
321
|
+
tip.remove()
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
this._cleanTipClass()
|
|
325
|
+
this._element.removeAttribute('aria-describedby')
|
|
326
|
+
EventHandler.trigger(this._element, this.constructor.Event.HIDDEN)
|
|
327
|
+
|
|
328
|
+
if (this._popper) {
|
|
329
|
+
this._popper.destroy()
|
|
330
|
+
this._popper = null
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const hideEvent = EventHandler.trigger(this._element, this.constructor.Event.HIDE)
|
|
335
|
+
if (hideEvent.defaultPrevented) {
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
tip.classList.remove(CLASS_NAME_SHOW)
|
|
340
|
+
|
|
341
|
+
// If this is a touch-enabled device we remove the extra
|
|
342
|
+
// empty mouseover listeners we added for iOS support
|
|
343
|
+
if ('ontouchstart' in document.documentElement) {
|
|
344
|
+
[].concat(...document.body.children)
|
|
345
|
+
.forEach(element => EventHandler.off(element, 'mouseover', noop))
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
this._activeTrigger[TRIGGER_CLICK] = false
|
|
349
|
+
this._activeTrigger[TRIGGER_FOCUS] = false
|
|
350
|
+
this._activeTrigger[TRIGGER_HOVER] = false
|
|
351
|
+
|
|
352
|
+
const isAnimated = this.tip.classList.contains(CLASS_NAME_FADE)
|
|
353
|
+
this._queueCallback(complete, this.tip, isAnimated)
|
|
354
|
+
this._hoverState = ''
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
update() {
|
|
358
|
+
if (this._popper !== null) {
|
|
359
|
+
this._popper.update()
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Protected
|
|
364
|
+
|
|
365
|
+
isWithContent() {
|
|
366
|
+
return Boolean(this.getTitle())
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
getTipElement() {
|
|
370
|
+
if (this.tip) {
|
|
371
|
+
return this.tip
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const element = document.createElement('div')
|
|
375
|
+
element.innerHTML = this._config.template
|
|
376
|
+
|
|
377
|
+
this.tip = element.children[0]
|
|
378
|
+
return this.tip
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
setContent() {
|
|
382
|
+
const tip = this.getTipElement()
|
|
383
|
+
this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle())
|
|
384
|
+
tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
setElementContent(element, content) {
|
|
388
|
+
if (element === null) {
|
|
389
|
+
return
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (isElement(content)) {
|
|
393
|
+
content = getElement(content)
|
|
394
|
+
|
|
395
|
+
// content is a DOM node or a jQuery
|
|
396
|
+
if (this._config.html) {
|
|
397
|
+
if (content.parentNode !== element) {
|
|
398
|
+
element.innerHTML = ''
|
|
399
|
+
element.appendChild(content)
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
element.textContent = content.textContent
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (this._config.html) {
|
|
409
|
+
if (this._config.sanitize) {
|
|
410
|
+
content = sanitizeHtml(content, this._config.allowList, this._config.sanitizeFn)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
element.innerHTML = content
|
|
414
|
+
} else {
|
|
415
|
+
element.textContent = content
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
getTitle() {
|
|
420
|
+
let title = this._element.getAttribute('data-coreui-original-title')
|
|
421
|
+
|
|
422
|
+
if (!title) {
|
|
423
|
+
title = typeof this._config.title === 'function' ?
|
|
424
|
+
this._config.title.call(this._element) :
|
|
425
|
+
this._config.title
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return title
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
updateAttachment(attachment) {
|
|
432
|
+
if (attachment === 'right') {
|
|
433
|
+
return 'end'
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (attachment === 'left') {
|
|
437
|
+
return 'start'
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return attachment
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Private
|
|
444
|
+
|
|
445
|
+
_initializeOnDelegatedTarget(event, context) {
|
|
446
|
+
const dataKey = this.constructor.DATA_KEY
|
|
447
|
+
context = context || Data.get(event.delegateTarget, dataKey)
|
|
448
|
+
|
|
449
|
+
if (!context) {
|
|
450
|
+
context = new this.constructor(event.delegateTarget, this._getDelegateConfig())
|
|
451
|
+
Data.set(event.delegateTarget, dataKey, context)
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return context
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
_getOffset() {
|
|
458
|
+
const { offset } = this._config
|
|
459
|
+
|
|
460
|
+
if (typeof offset === 'string') {
|
|
461
|
+
return offset.split(',').map(val => Number.parseInt(val, 10))
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (typeof offset === 'function') {
|
|
465
|
+
return popperData => offset(popperData, this._element)
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return offset
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
_getPopperConfig(attachment) {
|
|
472
|
+
const defaultBsPopperConfig = {
|
|
473
|
+
placement: attachment,
|
|
474
|
+
modifiers: [
|
|
475
|
+
{
|
|
476
|
+
name: 'flip',
|
|
477
|
+
options: {
|
|
478
|
+
fallbackPlacements: this._config.fallbackPlacements
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: 'offset',
|
|
483
|
+
options: {
|
|
484
|
+
offset: this._getOffset()
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
name: 'preventOverflow',
|
|
489
|
+
options: {
|
|
490
|
+
boundary: this._config.boundary
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
name: 'arrow',
|
|
495
|
+
options: {
|
|
496
|
+
element: `.${this.constructor.NAME}-arrow`
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: 'onChange',
|
|
501
|
+
enabled: true,
|
|
502
|
+
phase: 'afterWrite',
|
|
503
|
+
fn: data => this._handlePopperPlacementChange(data)
|
|
504
|
+
}
|
|
505
|
+
],
|
|
506
|
+
onFirstUpdate: data => {
|
|
507
|
+
if (data.options.placement !== data.placement) {
|
|
508
|
+
this._handlePopperPlacementChange(data)
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
return {
|
|
514
|
+
...defaultBsPopperConfig,
|
|
515
|
+
...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
_addAttachmentClass(attachment) {
|
|
520
|
+
this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`)
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
_getAttachment(placement) {
|
|
524
|
+
return AttachmentMap[placement.toUpperCase()]
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
_setListeners() {
|
|
528
|
+
const triggers = this._config.trigger.split(' ')
|
|
529
|
+
|
|
530
|
+
triggers.forEach(trigger => {
|
|
531
|
+
if (trigger === 'click') {
|
|
532
|
+
EventHandler.on(this._element, this.constructor.Event.CLICK, this._config.selector, event => this.toggle(event))
|
|
533
|
+
} else if (trigger !== TRIGGER_MANUAL) {
|
|
534
|
+
const eventIn = trigger === TRIGGER_HOVER ?
|
|
535
|
+
this.constructor.Event.MOUSEENTER :
|
|
536
|
+
this.constructor.Event.FOCUSIN
|
|
537
|
+
const eventOut = trigger === TRIGGER_HOVER ?
|
|
538
|
+
this.constructor.Event.MOUSELEAVE :
|
|
539
|
+
this.constructor.Event.FOCUSOUT
|
|
540
|
+
|
|
541
|
+
EventHandler.on(this._element, eventIn, this._config.selector, event => this._enter(event))
|
|
542
|
+
EventHandler.on(this._element, eventOut, this._config.selector, event => this._leave(event))
|
|
543
|
+
}
|
|
544
|
+
})
|
|
545
|
+
|
|
546
|
+
this._hideModalHandler = () => {
|
|
547
|
+
if (this._element) {
|
|
548
|
+
this.hide()
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
EventHandler.on(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.coreui.modal', this._hideModalHandler)
|
|
553
|
+
|
|
554
|
+
if (this._config.selector) {
|
|
555
|
+
this._config = {
|
|
556
|
+
...this._config,
|
|
557
|
+
trigger: 'manual',
|
|
558
|
+
selector: ''
|
|
559
|
+
}
|
|
560
|
+
} else {
|
|
561
|
+
this._fixTitle()
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
_fixTitle() {
|
|
566
|
+
const title = this._element.getAttribute('title')
|
|
567
|
+
const originalTitleType = typeof this._element.getAttribute('data-coreui-original-title')
|
|
568
|
+
|
|
569
|
+
if (title || originalTitleType !== 'string') {
|
|
570
|
+
this._element.setAttribute('data-coreui-original-title', title || '')
|
|
571
|
+
if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
|
|
572
|
+
this._element.setAttribute('aria-label', title)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
this._element.setAttribute('title', '')
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
_enter(event, context) {
|
|
580
|
+
context = this._initializeOnDelegatedTarget(event, context)
|
|
581
|
+
|
|
582
|
+
if (event) {
|
|
583
|
+
context._activeTrigger[
|
|
584
|
+
event.type === 'focusin' ? TRIGGER_FOCUS : TRIGGER_HOVER
|
|
585
|
+
] = true
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (context.getTipElement().classList.contains(CLASS_NAME_SHOW) || context._hoverState === HOVER_STATE_SHOW) {
|
|
589
|
+
context._hoverState = HOVER_STATE_SHOW
|
|
590
|
+
return
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
clearTimeout(context._timeout)
|
|
594
|
+
|
|
595
|
+
context._hoverState = HOVER_STATE_SHOW
|
|
596
|
+
|
|
597
|
+
if (!context._config.delay || !context._config.delay.show) {
|
|
598
|
+
context.show()
|
|
599
|
+
return
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
context._timeout = setTimeout(() => {
|
|
603
|
+
if (context._hoverState === HOVER_STATE_SHOW) {
|
|
604
|
+
context.show()
|
|
605
|
+
}
|
|
606
|
+
}, context._config.delay.show)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
_leave(event, context) {
|
|
610
|
+
context = this._initializeOnDelegatedTarget(event, context)
|
|
611
|
+
|
|
612
|
+
if (event) {
|
|
613
|
+
context._activeTrigger[
|
|
614
|
+
event.type === 'focusout' ? TRIGGER_FOCUS : TRIGGER_HOVER
|
|
615
|
+
] = context._element.contains(event.relatedTarget)
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (context._isWithActiveTrigger()) {
|
|
619
|
+
return
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
clearTimeout(context._timeout)
|
|
623
|
+
|
|
624
|
+
context._hoverState = HOVER_STATE_OUT
|
|
625
|
+
|
|
626
|
+
if (!context._config.delay || !context._config.delay.hide) {
|
|
627
|
+
context.hide()
|
|
628
|
+
return
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
context._timeout = setTimeout(() => {
|
|
632
|
+
if (context._hoverState === HOVER_STATE_OUT) {
|
|
633
|
+
context.hide()
|
|
634
|
+
}
|
|
635
|
+
}, context._config.delay.hide)
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
_isWithActiveTrigger() {
|
|
639
|
+
for (const trigger in this._activeTrigger) {
|
|
640
|
+
if (this._activeTrigger[trigger]) {
|
|
641
|
+
return true
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return false
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
_getConfig(config) {
|
|
649
|
+
const dataAttributes = Manipulator.getDataAttributes(this._element)
|
|
650
|
+
|
|
651
|
+
Object.keys(dataAttributes).forEach(dataAttr => {
|
|
652
|
+
if (DISALLOWED_ATTRIBUTES.has(dataAttr)) {
|
|
653
|
+
delete dataAttributes[dataAttr]
|
|
654
|
+
}
|
|
655
|
+
})
|
|
656
|
+
|
|
657
|
+
config = {
|
|
658
|
+
...this.constructor.Default,
|
|
659
|
+
...dataAttributes,
|
|
660
|
+
...(typeof config === 'object' && config ? config : {})
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
config.container = config.container === false ? document.body : getElement(config.container)
|
|
664
|
+
|
|
665
|
+
if (typeof config.delay === 'number') {
|
|
666
|
+
config.delay = {
|
|
667
|
+
show: config.delay,
|
|
668
|
+
hide: config.delay
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
if (typeof config.title === 'number') {
|
|
673
|
+
config.title = config.title.toString()
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
if (typeof config.content === 'number') {
|
|
677
|
+
config.content = config.content.toString()
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
typeCheckConfig(NAME, config, this.constructor.DefaultType)
|
|
681
|
+
|
|
682
|
+
if (config.sanitize) {
|
|
683
|
+
config.template = sanitizeHtml(config.template, config.allowList, config.sanitizeFn)
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
return config
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
_getDelegateConfig() {
|
|
690
|
+
const config = {}
|
|
691
|
+
|
|
692
|
+
if (this._config) {
|
|
693
|
+
for (const key in this._config) {
|
|
694
|
+
if (this.constructor.Default[key] !== this._config[key]) {
|
|
695
|
+
config[key] = this._config[key]
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return config
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
_cleanTipClass() {
|
|
704
|
+
const tip = this.getTipElement()
|
|
705
|
+
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
|
|
706
|
+
if (tabClass !== null && tabClass.length > 0) {
|
|
707
|
+
tabClass.map(token => token.trim())
|
|
708
|
+
.forEach(tClass => tip.classList.remove(tClass))
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
_handlePopperPlacementChange(popperData) {
|
|
713
|
+
const { state } = popperData
|
|
714
|
+
|
|
715
|
+
if (!state) {
|
|
716
|
+
return
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
this.tip = state.elements.popper
|
|
720
|
+
this._cleanTipClass()
|
|
721
|
+
this._addAttachmentClass(this._getAttachment(state.placement))
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// Static
|
|
725
|
+
|
|
726
|
+
static jQueryInterface(config) {
|
|
727
|
+
return this.each(function () {
|
|
728
|
+
const data = Tooltip.getOrCreateInstance(this, config)
|
|
729
|
+
|
|
730
|
+
if (typeof config === 'string') {
|
|
731
|
+
if (typeof data[config] === 'undefined') {
|
|
732
|
+
throw new TypeError(`No method named "${config}"`)
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
data[config]()
|
|
736
|
+
}
|
|
737
|
+
})
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* ------------------------------------------------------------------------
|
|
743
|
+
* jQuery
|
|
744
|
+
* ------------------------------------------------------------------------
|
|
745
|
+
* add .Tooltip to jQuery only if jQuery is present
|
|
746
|
+
*/
|
|
747
|
+
|
|
748
|
+
defineJQueryPlugin(Tooltip)
|
|
749
|
+
|
|
750
|
+
export default Tooltip
|