Skip to content

Commit

Permalink
Update tooltips.js
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Mar 18, 2022
1 parent 9be65d6 commit 60e4232
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions war/src/main/js/tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@ const TOOLTIP_BASE = {
appendTo: document.body
}

let tooltipInstances = []
const globalPlugin = {
fn() {
return {
onCreate(instance) {
tooltipInstances = tooltipInstances.concat(instance);
},
onDestroy(instance) {
tooltipInstances = tooltipInstances.filter(i => i !== instance);
}
}
}
}

tippy.setDefaultProps({
plugins: [globalPlugin]
})

registerTooltips()

/**
* Registers tooltips for the page
* If called again, destroys existing tooltips and registers them again (useful for progressive rendering)
*/
function registerTooltips() {
[...document.querySelectorAll("*")].forEach(node => {
if (node._tippy) {
node._tippy.destroy()
}
tooltipInstances.forEach(instance => {
instance.destroy()
})

tippy("[tooltip]", {
Expand Down

0 comments on commit 60e4232

Please sign in to comment.