Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: desktop-options.js

Issue 29683678: Issue 5542: Implement tooltips for new options page (Closed)
Patch Set: Created Feb. 5, 2018, 12:32 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « desktop-options.html ('k') | skin/desktop-options.css » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: desktop-options.js
===================================================================
--- a/desktop-options.js
+++ b/desktop-options.js
@@ -533,18 +533,12 @@
function findParentData(element, dataName, returnElement)
{
- while (element)
- {
- if (element.hasAttribute("data-" + dataName))
- {
- if (returnElement)
- return element;
- return element.getAttribute("data-" + dataName);
- }
-
- element = element.parentElement;
- }
- return null;
+ element = element.closest(`[data-${dataName}]`);
+ if (!element)
+ return null;
+ if (returnElement)
+ return element;
+ return element.getAttribute(`data-${dataName}`);
}
function sendMessageHandleErrors(message, onSuccess)
@@ -1295,7 +1289,7 @@
updateSubscription(subscription);
break;
case "added":
- let {url, recommended} = subscription;
+ let {url} = subscription;
// Handle custom subscription
if (/^~user/.test(url))
{
@@ -1401,30 +1395,42 @@
function updateTooltips()
{
- let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]");
- for (let anchor of anchors)
+ const anchors = document.querySelectorAll("[data-tooltip]");
+ for (const anchor of anchors)
{
let id = anchor.getAttribute("data-tooltip");
- let wrapper = document.createElement("div");
- wrapper.setAttribute("aria-describedby", id);
- wrapper.setAttribute("tabindex", "0");
- wrapper.className = "icon tooltip";
- anchor.parentNode.replaceChild(wrapper, anchor);
- wrapper.appendChild(anchor);
+ // instead of replacing the whole node
+ // just make it non discoverable for
+ // the next updateTooltips call
+ anchor.removeAttribute("data-tooltip");
+ anchor.classList.add("icon", "tooltip");
- let tooltip = document.createElement("div");
- tooltip.id = id;
+ const tooltip = document.createElement("div");
tooltip.setAttribute("role", "tooltip");
+ // needed by aria-describedby
+ tooltip.id = id;
- let paragraph = document.createElement("p");
+ const paragraph = document.createElement("p");
paragraph.textContent = getMessage(id);
tooltip.appendChild(paragraph);
- wrapper.appendChild(tooltip);
+ anchor.appendChild(tooltip);
+ anchor.setAttribute("aria-describedby", id);
+
+ // if focused and the mouse reaches another (?)
+ // blur the active element to drop previous tooltip
+ anchor.addEventListener("mouseover", dropActiveElement);
}
}
+ function dropActiveElement(event)
+ {
+ const active = event.target.ownerDocument.activeElement;
+ if (active)
+ active.blur();
+ }
+
ext.onMessage.addListener((message) =>
{
switch (message.type)
« no previous file with comments | « desktop-options.html ('k') | skin/desktop-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld