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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « desktop-options.html ('k') | skin/desktop-options.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 type + "_title"); 526 type + "_title");
527 } 527 }
528 528
529 addSubscription(subscription); 529 addSubscription(subscription);
530 } 530 }
531 }); 531 });
532 } 532 }
533 533
534 function findParentData(element, dataName, returnElement) 534 function findParentData(element, dataName, returnElement)
535 { 535 {
536 while (element) 536 element = element.closest(`[data-${dataName}]`);
537 { 537 if (!element)
538 if (element.hasAttribute("data-" + dataName)) 538 return null;
539 { 539 if (returnElement)
540 if (returnElement) 540 return element;
541 return element; 541 return element.getAttribute(`data-${dataName}`);
542 return element.getAttribute("data-" + dataName);
543 }
544
545 element = element.parentElement;
546 }
547 return null;
548 } 542 }
549 543
550 function sendMessageHandleErrors(message, onSuccess) 544 function sendMessageHandleErrors(message, onSuccess)
551 { 545 {
552 browser.runtime.sendMessage(message, (errors) => 546 browser.runtime.sendMessage(message, (errors) =>
553 { 547 {
554 if (errors.length > 0) 548 if (errors.length > 0)
555 alert(errors.join("\n")); 549 alert(errors.join("\n"));
556 else if (onSuccess) 550 else if (onSuccess)
557 onSuccess(); 551 onSuccess();
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 setPrivacyConflict(); 1282 setPrivacyConflict();
1289 break; 1283 break;
1290 case "downloading": 1284 case "downloading":
1291 case "downloadStatus": 1285 case "downloadStatus":
1292 case "homepage": 1286 case "homepage":
1293 case "lastDownload": 1287 case "lastDownload":
1294 case "title": 1288 case "title":
1295 updateSubscription(subscription); 1289 updateSubscription(subscription);
1296 break; 1290 break;
1297 case "added": 1291 case "added":
1298 let {url, recommended} = subscription; 1292 let {url} = subscription;
1299 // Handle custom subscription 1293 // Handle custom subscription
1300 if (/^~user/.test(url)) 1294 if (/^~user/.test(url))
1301 { 1295 {
1302 loadCustomFilters(subscription.filters); 1296 loadCustomFilters(subscription.filters);
1303 return; 1297 return;
1304 } 1298 }
1305 else if (url in subscriptionsMap) 1299 else if (url in subscriptionsMap)
1306 updateSubscription(subscription); 1300 updateSubscription(subscription);
1307 else 1301 else
1308 addSubscription(subscription); 1302 addSubscription(subscription);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 1388
1395 let checkbox = document.querySelector( 1389 let checkbox = document.querySelector(
1396 "[data-pref='" + key + "'] button[role='checkbox']" 1390 "[data-pref='" + key + "'] button[role='checkbox']"
1397 ); 1391 );
1398 if (checkbox) 1392 if (checkbox)
1399 checkbox.setAttribute("aria-checked", value); 1393 checkbox.setAttribute("aria-checked", value);
1400 } 1394 }
1401 1395
1402 function updateTooltips() 1396 function updateTooltips()
1403 { 1397 {
1404 let anchors = document.querySelectorAll(":not(.tooltip) > [data-tooltip]"); 1398 const anchors = document.querySelectorAll("[data-tooltip]");
1405 for (let anchor of anchors) 1399 for (const anchor of anchors)
1406 { 1400 {
1407 let id = anchor.getAttribute("data-tooltip"); 1401 let id = anchor.getAttribute("data-tooltip");
1408 1402
1409 let wrapper = document.createElement("div"); 1403 // instead of replacing the whole node
1410 wrapper.setAttribute("aria-describedby", id); 1404 // just make it non discoverable for
1411 wrapper.setAttribute("tabindex", "0"); 1405 // the next updateTooltips call
1412 wrapper.className = "icon tooltip"; 1406 anchor.removeAttribute("data-tooltip");
1413 anchor.parentNode.replaceChild(wrapper, anchor); 1407 anchor.classList.add("icon", "tooltip");
1414 wrapper.appendChild(anchor);
1415 1408
1416 let tooltip = document.createElement("div"); 1409 const tooltip = document.createElement("div");
1410 tooltip.setAttribute("role", "tooltip");
1411 // needed by aria-describedby
1417 tooltip.id = id; 1412 tooltip.id = id;
1418 tooltip.setAttribute("role", "tooltip");
1419 1413
1420 let paragraph = document.createElement("p"); 1414 const paragraph = document.createElement("p");
1421 paragraph.textContent = getMessage(id); 1415 paragraph.textContent = getMessage(id);
1422 tooltip.appendChild(paragraph); 1416 tooltip.appendChild(paragraph);
1423 1417
1424 wrapper.appendChild(tooltip); 1418 anchor.appendChild(tooltip);
1419 anchor.setAttribute("aria-describedby", id);
1420
1421 // if focused and the mouse reaches another (?)
1422 // blur the active element to drop previous tooltip
1423 anchor.addEventListener("mouseover", dropActiveElement);
1425 } 1424 }
1426 } 1425 }
1427 1426
1427 function dropActiveElement(event)
1428 {
1429 const active = event.target.ownerDocument.activeElement;
1430 if (active)
1431 active.blur();
1432 }
1433
1428 ext.onMessage.addListener((message) => 1434 ext.onMessage.addListener((message) =>
1429 { 1435 {
1430 switch (message.type) 1436 switch (message.type)
1431 { 1437 {
1432 case "app.respond": 1438 case "app.respond":
1433 switch (message.action) 1439 switch (message.action)
1434 { 1440 {
1435 case "addSubscription": 1441 case "addSubscription":
1436 let subscription = message.args[0]; 1442 let subscription = message.args[0];
1437 let dialog = E("dialog-content-predefined"); 1443 let dialog = E("dialog-content-predefined");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 }); 1478 });
1473 browser.runtime.sendMessage({ 1479 browser.runtime.sendMessage({
1474 type: "subscriptions.listen", 1480 type: "subscriptions.listen",
1475 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1481 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1476 "title", "downloadStatus", "downloading"] 1482 "title", "downloadStatus", "downloading"]
1477 }); 1483 });
1478 1484
1479 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1485 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1480 window.addEventListener("hashchange", onHashChange, false); 1486 window.addEventListener("hashchange", onHashChange, false);
1481 } 1487 }
OLDNEW
« 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