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: made tooltip a11y friendly/focusable Created Feb. 5, 2018, 11:03 a.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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 905
912 // General tab 906 // General tab
913 getDocLink("contribute", (link) => 907 getDocLink("contribute", (link) =>
914 { 908 {
915 E("contribute").href = link; 909 E("contribute").href = link;
916 }); 910 });
917 getDocLink("acceptable_ads_criteria", (link) => 911 getDocLink("acceptable_ads_criteria", (link) =>
918 { 912 {
919 setLinks("enable-acceptable-ads-description", link); 913 setLinks("enable-acceptable-ads-description", link);
920 }); 914 });
921 setElementText(E("tracking-warning-1"), "options_tracking_warning_1", 915 setElementText(E("tracking-warning-1"), "options_tracking_warning_1",
922 [getMessage("common_feature_privacy_title"), 916 [getMessage("common_feature_privacy_title"),
923 getMessage("options_acceptableAds_ads_label")]); 917 getMessage("options_acceptableAds_ads_label")]);
924 setElementText(E("tracking-warning-3"), "options_tracking_warning_3", 918 setElementText(E("tracking-warning-3"), "options_tracking_warning_3",
925 [getMessage("options_acceptableAds_privacy_label")]); 919 [getMessage("options_acceptableAds_privacy_label")]);
926 920
927 getDocLink("privacy_friendly_ads", (link) => 921 getDocLink("privacy_friendly_ads", (link) =>
928 { 922 {
929 E("enable-acceptable-ads-privacy-description").href = link; 923 E("enable-acceptable-ads-privacy-description").href = link;
930 }); 924 });
931 getDocLink("adblock_plus_{browser}_dnt", url => 925 getDocLink("adblock_plus_{browser}_dnt", url =>
932 { 926 {
933 setLinks("dnt", url); 927 setLinks("dnt", url);
934 }); 928 });
(...skipping 353 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 tooltipsSelector = ":not(.tooltip) > [data-tooltip]";
1405 for (let anchor of anchors) 1399 const anchors = document.querySelectorAll(tooltipsSelector);
1400 for (const anchor of anchors)
1406 { 1401 {
1407 let id = anchor.getAttribute("data-tooltip"); 1402 // avoid creating same tooltip N times
1403 // updateTooltips gets invoked during bootstrap
1404 if (anchor.querySelector('[role="tooltip"]'))
1405 continue;
1408 1406
1409 let wrapper = document.createElement("div"); 1407 const id = anchor.getAttribute("data-tooltip");
1410 wrapper.className = "icon tooltip";
1411 anchor.parentNode.replaceChild(wrapper, anchor);
1412 wrapper.appendChild(anchor);
1413 1408
1414 let tooltip = document.createElement("div"); 1409 anchor.classList.add("icon", "tooltip");
1410
1411 const tooltip = document.createElement("div");
1415 tooltip.setAttribute("role", "tooltip"); 1412 tooltip.setAttribute("role", "tooltip");
1416 1413
1417 let paragraph = document.createElement("p"); 1414 const paragraph = document.createElement("p");
1418 paragraph.textContent = getMessage(id); 1415 paragraph.textContent = getMessage(id);
1419 tooltip.appendChild(paragraph); 1416 tooltip.appendChild(paragraph);
1420 1417
1421 wrapper.appendChild(tooltip); 1418 anchor.appendChild(tooltip);
1419
1420 // if focused and the mouse reaches another (?)
1421 // blur the active element to drop previous tooltip
1422 anchor.addEventListener("mouseover", dropActiveElement);
1422 } 1423 }
1423 } 1424 }
1424 1425
1426 function dropActiveElement(event)
1427 {
1428 const active = event.target.ownerDocument.activeElement;
1429 if (active)
1430 active.blur();
1431 }
1432
1425 ext.onMessage.addListener((message) => 1433 ext.onMessage.addListener((message) =>
1426 { 1434 {
1427 switch (message.type) 1435 switch (message.type)
1428 { 1436 {
1429 case "app.respond": 1437 case "app.respond":
1430 switch (message.action) 1438 switch (message.action)
1431 { 1439 {
1432 case "addSubscription": 1440 case "addSubscription":
1433 let subscription = message.args[0]; 1441 let subscription = message.args[0];
1434 let dialog = E("dialog-content-predefined"); 1442 let dialog = E("dialog-content-predefined");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 }); 1477 });
1470 browser.runtime.sendMessage({ 1478 browser.runtime.sendMessage({
1471 type: "subscriptions.listen", 1479 type: "subscriptions.listen",
1472 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1480 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1473 "title", "downloadStatus", "downloading"] 1481 "title", "downloadStatus", "downloading"]
1474 }); 1482 });
1475 1483
1476 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1484 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1477 window.addEventListener("hashchange", onHashChange, false); 1485 window.addEventListener("hashchange", onHashChange, false);
1478 } 1486 }
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