luci-base: luci.js: emit custom events for tooltip open/close actions
The new `tooltip-open` and `tooltip-close` events allow other code to hook into the tooltip div rendering, e.g. to populate it with custom markup. Also ignore tooltip events originating from descendant elements while we're at it. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
df9ba6981e
commit
a7dcfbe06b
1 changed files with 9 additions and 1 deletions
|
@ -129,10 +129,16 @@
|
|||
tooltipDiv.style.top = y + 'px';
|
||||
tooltipDiv.style.left = x + 'px';
|
||||
tooltipDiv.style.opacity = 1;
|
||||
|
||||
tooltipDiv.dispatchEvent(new CustomEvent('tooltip-open', {
|
||||
bubbles: true,
|
||||
detail: { target: target }
|
||||
}));
|
||||
},
|
||||
|
||||
hideTooltip: function(ev) {
|
||||
if (ev.target === tooltipDiv || ev.relatedTarget === tooltipDiv)
|
||||
if (ev.target === tooltipDiv || ev.relatedTarget === tooltipDiv ||
|
||||
tooltipDiv.contains(ev.target) || tooltipDiv.contains(ev.relatedTarget))
|
||||
return;
|
||||
|
||||
if (tooltipTimeout !== null) {
|
||||
|
@ -142,6 +148,8 @@
|
|||
|
||||
tooltipDiv.style.opacity = 0;
|
||||
tooltipTimeout = window.setTimeout(function() { tooltipDiv.removeAttribute('style'); }, 250);
|
||||
|
||||
tooltipDiv.dispatchEvent(new CustomEvent('tooltip-close', { bubbles: true }));
|
||||
},
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue