Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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 element = element.closest(`[data-${dataName}]`); | 536 while (element) |
537 if (!element) | 537 { |
538 return null; | 538 if (element.hasAttribute("data-" + dataName)) |
539 if (returnElement) | 539 { |
540 return element; | 540 if (returnElement) |
541 return element.getAttribute(`data-${dataName}`); | 541 return element; |
542 return element.getAttribute("data-" + dataName); | |
543 } | |
544 | |
545 element = element.parentElement; | |
546 } | |
547 return null; | |
542 } | 548 } |
543 | 549 |
544 function sendMessageHandleErrors(message, onSuccess) | 550 function sendMessageHandleErrors(message, onSuccess) |
545 { | 551 { |
546 browser.runtime.sendMessage(message, (errors) => | 552 browser.runtime.sendMessage(message, (errors) => |
547 { | 553 { |
548 if (errors.length > 0) | 554 if (errors.length > 0) |
549 alert(errors.join("\n")); | 555 alert(errors.join("\n")); |
550 else if (onSuccess) | 556 else if (onSuccess) |
551 onSuccess(); | 557 onSuccess(); |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1388 | 1394 |
1389 let checkbox = document.querySelector( | 1395 let checkbox = document.querySelector( |
1390 "[data-pref='" + key + "'] button[role='checkbox']" | 1396 "[data-pref='" + key + "'] button[role='checkbox']" |
1391 ); | 1397 ); |
1392 if (checkbox) | 1398 if (checkbox) |
1393 checkbox.setAttribute("aria-checked", value); | 1399 checkbox.setAttribute("aria-checked", value); |
1394 } | 1400 } |
1395 | 1401 |
1396 function updateTooltips() | 1402 function updateTooltips() |
1397 { | 1403 { |
1398 const tooltipsSelector = ":not(.tooltip) > [data-tooltip]"; | 1404 const anchors = document.querySelectorAll("[data-tooltip]"); |
sergei
2018/02/19 10:18:42
I thought we don't use `const` in such cases, do w
a.giammarchi
2018/02/19 10:26:38
why not, if I might ask? `const` is used to guard
sergei
2018/02/19 10:44:45
Yep, I know what it is for but I got several times
a.giammarchi
2018/02/19 10:53:05
that's the second point though, the first one says
| |
1399 const anchors = document.querySelectorAll(tooltipsSelector); | |
1400 for (const anchor of anchors) | 1405 for (const anchor of anchors) |
1401 { | 1406 { |
1402 // avoid creating same tooltip N times | 1407 let id = anchor.getAttribute("data-tooltip"); |
1403 // updateTooltips gets invoked during bootstrap | 1408 |
1404 if (anchor.querySelector('[role="tooltip"]')) | 1409 // instead of replacing the whole node |
1405 continue; | 1410 // just make it non discoverable for |
1406 | 1411 // the next updateTooltips call |
1407 const id = anchor.getAttribute("data-tooltip"); | 1412 anchor.removeAttribute("data-tooltip"); |
1408 | |
1409 anchor.classList.add("icon", "tooltip"); | 1413 anchor.classList.add("icon", "tooltip"); |
1410 | 1414 |
1411 const tooltip = document.createElement("div"); | 1415 const tooltip = document.createElement("div"); |
1412 tooltip.setAttribute("role", "tooltip"); | 1416 tooltip.setAttribute("role", "tooltip"); |
1417 // needed by aria-describedby | |
1418 tooltip.id = id; | |
1413 | 1419 |
1414 const paragraph = document.createElement("p"); | 1420 const paragraph = document.createElement("p"); |
1415 paragraph.textContent = getMessage(id); | 1421 paragraph.textContent = getMessage(id); |
1416 tooltip.appendChild(paragraph); | 1422 tooltip.appendChild(paragraph); |
1417 | 1423 |
1418 anchor.appendChild(tooltip); | 1424 anchor.appendChild(tooltip); |
1425 anchor.setAttribute("aria-describedby", id); | |
1419 | 1426 |
1420 // if focused and the mouse reaches another (?) | 1427 // if focused and the mouse reaches another (?) |
1421 // blur the active element to drop previous tooltip | 1428 // blur the active element to drop previous tooltip |
1422 anchor.addEventListener("mouseover", dropActiveElement); | 1429 anchor.addEventListener("mouseover", dropActiveElement); |
1423 } | 1430 } |
1424 } | 1431 } |
1425 | 1432 |
1426 function dropActiveElement(event) | 1433 function dropActiveElement(event) |
1427 { | 1434 { |
1428 const active = event.target.ownerDocument.activeElement; | 1435 const active = event.target.ownerDocument.activeElement; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1477 }); | 1484 }); |
1478 browser.runtime.sendMessage({ | 1485 browser.runtime.sendMessage({ |
1479 type: "subscriptions.listen", | 1486 type: "subscriptions.listen", |
1480 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1487 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1481 "title", "downloadStatus", "downloading"] | 1488 "title", "downloadStatus", "downloading"] |
1482 }); | 1489 }); |
1483 | 1490 |
1484 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1491 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1485 window.addEventListener("hashchange", onHashChange, false); | 1492 window.addEventListener("hashchange", onHashChange, false); |
1486 } | 1493 } |
LEFT | RIGHT |