aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-08-27 03:16:51 +0300
committerGeoSot <[email protected]>2021-09-29 02:55:20 +0300
commitd07858170ada7c41a6ce82325653f6c871301bd2 (patch)
tree965d831e289cd1b6a1d000d0fd815fcb386482a2
parent145f076e88ec484fe1073c17d171a3769a0c214c (diff)
downloadbootstrap-gs-make-template_factory.tar.xz
bootstrap-gs-make-template_factory.zip
Fix `setContent`gs-make-template_factory
Remove 'data-bs-original-title' trick fix class selector on `_popperConfig`
-rw-r--r--js/src/tooltip.js37
-rw-r--r--site/assets/js/application.js16
2 files changed, 25 insertions, 28 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js
index fabc6b020..5e29a5aea 100644
--- a/js/src/tooltip.js
+++ b/js/src/tooltip.js
@@ -107,6 +107,7 @@ const HOVER_STATE_SHOW = 'show'
const HOVER_STATE_OUT = 'out'
const SELECTOR_TOOLTIP_INNER = '.tooltip-inner'
+const SELECTOR_TOOLTIP_ARROW = '.tooltip-arrow'
const SELECTOR_MODAL = `.${CLASS_NAME_MODAL}`
const EVENT_MODAL_HIDE = 'hide.bs.modal'
@@ -234,14 +235,6 @@ class Tooltip extends BaseComponent {
return
}
- // A trick to recreate a tooltip in case a new title is given by using the NOT documented `data-bs-original-title`
- // This will be removed later in favor of a `setContent` method
- if (this.constructor.NAME === 'tooltip' && this.tip && this.getTitle() !== this.tip.querySelector(SELECTOR_TOOLTIP_INNER).innerHTML) {
- this._disposePopper()
- this.tip.remove()
- this.tip = null
- }
-
const tip = this.getTipElement()
const tipId = getUID(this.constructor.NAME)
@@ -372,7 +365,19 @@ class Tooltip extends BaseComponent {
}
setContent(content) {
+ let isShown = false
+ if (this.tip) {
+ isShown = this.tip.classList.contains(CLASS_NAME_SHOW)
+ this.tip.remove()
+ }
+
+ this._disposePopper()
+
this.tip = this._getTemplateFactory(content).toHtml()
+
+ if (isShown) {
+ this.show()
+ }
}
_getTemplateFactory(content) {
@@ -397,9 +402,7 @@ class Tooltip extends BaseComponent {
}
getTitle() {
- const title = this._element.getAttribute('data-bs-original-title') || this._config.title
-
- return this._resolvePossibleFunction(title)
+ return this._resolvePossibleFunction(this._config.title) || this._element.getAttribute('title')
}
updateAttachment(attachment) {
@@ -463,7 +466,7 @@ class Tooltip extends BaseComponent {
{
name: 'arrow',
options: {
- element: `.${this.constructor.NAME}-arrow`
+ element: SELECTOR_TOOLTIP_ARROW
}
},
{
@@ -534,15 +537,9 @@ class Tooltip extends BaseComponent {
_fixTitle() {
const title = this._element.getAttribute('title')
- const originalTitleType = typeof this._element.getAttribute('data-bs-original-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', '')
+ if (title && !this._element.getAttribute('aria-label') && !this._element.textContent) {
+ this._element.setAttribute('aria-label', title)
}
}
diff --git a/site/assets/js/application.js b/site/assets/js/application.js
index acf859764..dad08f782 100644
--- a/site/assets/js/application.js
+++ b/site/assets/js/application.js
@@ -145,10 +145,10 @@
clipboard.on('success', function (event) {
var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
- event.trigger.setAttribute('data-bs-original-title', 'Copied!')
- tooltipBtn.show()
-
- event.trigger.setAttribute('data-bs-original-title', 'Copy to clipboard')
+ tooltipBtn.setContent({ '.tooltip-inner': 'Copied!' })
+ event.trigger.addEventListener('hidden.bs.tooltip', function () {
+ tooltipBtn.setContent({ '.tooltip-inner': 'Copy to clipboard' })
+ }, { once: true })
event.clearSelection()
})
@@ -157,10 +157,10 @@
var fallbackMsg = 'Press ' + modifierKey + 'C to copy'
var tooltipBtn = bootstrap.Tooltip.getInstance(event.trigger)
- event.trigger.setAttribute('data-bs-original-title', fallbackMsg)
- tooltipBtn.show()
-
- event.trigger.setAttribute('data-bs-original-title', 'Copy to clipboard')
+ tooltipBtn.setContent({ '.tooltip-inner': fallbackMsg })
+ event.trigger.addEventListener('hidden.bs.tooltip', function () {
+ tooltipBtn.setContent({ '.tooltip-inner': 'Copy to clipboard' })
+ }, { once: true })
})
anchors.options = {