Commit 3748cafd authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Benni Mack
Browse files

[BUGFIX] Initialize tooltips only once

Due to several modules initializing tooltips, it might happen that they
are initializing the same element twice or even more times. This can be
easily avoided by using the new bootstrap Tooltip method
"getOrCreateInstance". This should fix weird behaviour, where the
tooltip did not disappear.

Also, since updating to a newer bootstrap version the fix 0005bc5b did
not work anymore. This is fixed by using the container context as
selector basis.

Resolves: #94477
Releases: master
Change-Id: Iea67db7fe63825f2eba028302d435cf7e2c8e7b8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70119

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 62be6503
......@@ -1127,7 +1127,7 @@ export class SvgTree extends LitElement {
this.scrollBottom = this.scrollTop + this.viewportHeight + (this.viewportHeight / 2);
// wait for the tooltip to appear and disable tooltips when scrolling
setTimeout(() => {
Tooltip.hide(this.querySelectorAll('.bs-tooltip-end'));
Tooltip.hide(document.querySelector(<string>this.tooltipOptions.container).querySelectorAll('.bs-tooltip-end'));
}, <number>this.tooltipOptions.delay)
}
......
......@@ -45,7 +45,12 @@ class Tooltip {
}
const elements = document.querySelectorAll(selector);
for (const element of elements) {
new BootstrapTooltip(element, options);
// @ts-ignore
// todo this method is missing in types/bootstrap.
// todo see: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/54289
// todo Remove ts-ignore, when it is added.
// Ensure elements are not initialized multiple times.
BootstrapTooltip.getOrCreateInstance(element, options);
}
}
......
......@@ -10,4 +10,4 @@
*
* The TYPO3 project - inspiring people to share!
*/
define(["require","exports","bootstrap","TYPO3/CMS/Core/DocumentService"],(function(e,t,o,n){"use strict";class s{static applyAttributes(e,t){for(const[o,n]of Object.entries(e))t.setAttribute(o,n)}constructor(){n.ready().then(()=>{this.initialize('[data-bs-toggle="tooltip"]')})}initialize(e,t={}){0===Object.entries(t).length&&(t={container:"body",trigger:"hover",delay:{show:500,hide:100}});const n=document.querySelectorAll(e);for(const e of n)new o.Tooltip(e,t)}show(e,t){const n={"data-bs-placement":"auto",title:t};if(e instanceof NodeList||e instanceof HTMLElement){if(e instanceof NodeList)for(const t of e)s.applyAttributes(n,t),o.Tooltip.getInstance(t).show();else if(e instanceof HTMLElement)return s.applyAttributes(n,e),void o.Tooltip.getInstance(e).show()}else{console.warn("Passing an jQuery object to Tooltip.show() has been marked as deprecated. Either pass a NodeList or an HTMLElement.");for(const[t,o]of Object.entries(n))e.attr(t,o);e.tooltip("show")}}hide(e){if(!(e instanceof NodeList||e instanceof HTMLElement))return console.warn("Passing an jQuery object to Tooltip.hide() has been marked as deprecated. Either pass a NodeList or an HTMLElement."),void e.tooltip("hide");if(e instanceof NodeList)for(const t of e){const e=o.Tooltip.getInstance(t);null!==e&&e.hide()}else e instanceof HTMLElement&&o.Tooltip.getInstance(e).hide()}}const i=new s;return TYPO3.Tooltip=i,i}));
\ No newline at end of file
define(["require","exports","bootstrap","TYPO3/CMS/Core/DocumentService"],(function(e,t,o,n){"use strict";class s{static applyAttributes(e,t){for(const[o,n]of Object.entries(e))t.setAttribute(o,n)}constructor(){n.ready().then(()=>{this.initialize('[data-bs-toggle="tooltip"]')})}initialize(e,t={}){0===Object.entries(t).length&&(t={container:"body",trigger:"hover",delay:{show:500,hide:100}});const n=document.querySelectorAll(e);for(const e of n)o.Tooltip.getOrCreateInstance(e,t)}show(e,t){const n={"data-bs-placement":"auto",title:t};if(e instanceof NodeList||e instanceof HTMLElement){if(e instanceof NodeList)for(const t of e)s.applyAttributes(n,t),o.Tooltip.getInstance(t).show();else if(e instanceof HTMLElement)return s.applyAttributes(n,e),void o.Tooltip.getInstance(e).show()}else{console.warn("Passing an jQuery object to Tooltip.show() has been marked as deprecated. Either pass a NodeList or an HTMLElement.");for(const[t,o]of Object.entries(n))e.attr(t,o);e.tooltip("show")}}hide(e){if(!(e instanceof NodeList||e instanceof HTMLElement))return console.warn("Passing an jQuery object to Tooltip.hide() has been marked as deprecated. Either pass a NodeList or an HTMLElement."),void e.tooltip("hide");if(e instanceof NodeList)for(const t of e){const e=o.Tooltip.getInstance(t);null!==e&&e.hide()}else e instanceof HTMLElement&&o.Tooltip.getInstance(e).hide()}}const i=new s;return TYPO3.Tooltip=i,i}));
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment