luci-base: luci.js: emit custom events for tooltip open/close actions
authorJo-Philipp Wich <jo@mein.io>
Fri, 7 Dec 2018 16:57:45 +0000 (17:57 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 10 Dec 2018 12:41:34 +0000 (13:41 +0100)
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>
modules/luci-base/htdocs/luci-static/resources/luci.js

index 04c460182fbd40af6488eb84dd530737cf68a4b7..c1c1b0dd3c238f871de27222e5e8253b41f223cc 100644 (file)
                        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) {
 
                        tooltipDiv.style.opacity = 0;
                        tooltipTimeout = window.setTimeout(function() { tooltipDiv.removeAttribute('style'); }, 250);
+
+                       tooltipDiv.dispatchEvent(new CustomEvent('tooltip-close', { bubbles: true }));
                },