Left: | ||
Right: |
OLD | NEW |
---|---|
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 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1288 setPrivacyConflict(); | 1288 setPrivacyConflict(); |
1289 break; | 1289 break; |
1290 case "downloading": | 1290 case "downloading": |
1291 case "downloadStatus": | 1291 case "downloadStatus": |
1292 case "homepage": | 1292 case "homepage": |
1293 case "lastDownload": | 1293 case "lastDownload": |
1294 case "title": | 1294 case "title": |
1295 updateSubscription(subscription); | 1295 updateSubscription(subscription); |
1296 break; | 1296 break; |
1297 case "added": | 1297 case "added": |
1298 let {url, recommended} = subscription; | 1298 let {url} = subscription; |
1299 // Handle custom subscription | 1299 // Handle custom subscription |
1300 if (/^~user/.test(url)) | 1300 if (/^~user/.test(url)) |
1301 { | 1301 { |
1302 loadCustomFilters(subscription.filters); | 1302 loadCustomFilters(subscription.filters); |
1303 return; | 1303 return; |
1304 } | 1304 } |
1305 else if (url in subscriptionsMap) | 1305 else if (url in subscriptionsMap) |
1306 updateSubscription(subscription); | 1306 updateSubscription(subscription); |
1307 else | 1307 else |
1308 addSubscription(subscription); | 1308 addSubscription(subscription); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1394 | 1394 |
1395 let checkbox = document.querySelector( | 1395 let checkbox = document.querySelector( |
1396 "[data-pref='" + key + "'] button[role='checkbox']" | 1396 "[data-pref='" + key + "'] button[role='checkbox']" |
1397 ); | 1397 ); |
1398 if (checkbox) | 1398 if (checkbox) |
1399 checkbox.setAttribute("aria-checked", value); | 1399 checkbox.setAttribute("aria-checked", value); |
1400 } | 1400 } |
1401 | 1401 |
1402 function updateTooltips() | 1402 function updateTooltips() |
1403 { | 1403 { |
1404 let anchors = document.querySelectorAll(":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
| |
1405 for (let anchor of anchors) | 1405 for (const anchor of anchors) |
1406 { | 1406 { |
1407 let id = anchor.getAttribute("data-tooltip"); | 1407 let id = anchor.getAttribute("data-tooltip"); |
1408 | 1408 |
1409 let wrapper = document.createElement("div"); | 1409 // instead of replacing the whole node |
1410 wrapper.setAttribute("aria-describedby", id); | 1410 // just make it non discoverable for |
1411 wrapper.setAttribute("tabindex", "0"); | 1411 // the next updateTooltips call |
1412 wrapper.className = "icon tooltip"; | 1412 anchor.removeAttribute("data-tooltip"); |
1413 anchor.parentNode.replaceChild(wrapper, anchor); | 1413 anchor.classList.add("icon", "tooltip"); |
1414 wrapper.appendChild(anchor); | |
1415 | 1414 |
1416 let tooltip = document.createElement("div"); | 1415 const tooltip = document.createElement("div"); |
1416 tooltip.setAttribute("role", "tooltip"); | |
1417 // needed by aria-describedby | |
1417 tooltip.id = id; | 1418 tooltip.id = id; |
1418 tooltip.setAttribute("role", "tooltip"); | |
1419 | 1419 |
1420 let paragraph = document.createElement("p"); | 1420 const paragraph = document.createElement("p"); |
1421 paragraph.textContent = getMessage(id); | 1421 paragraph.textContent = getMessage(id); |
1422 tooltip.appendChild(paragraph); | 1422 tooltip.appendChild(paragraph); |
1423 | 1423 |
1424 wrapper.appendChild(tooltip); | 1424 anchor.appendChild(tooltip); |
1425 anchor.setAttribute("aria-describedby", id); | |
1426 | |
1427 // if focused and the mouse reaches another (?) | |
1428 // blur the active element to drop previous tooltip | |
1429 anchor.addEventListener("mouseover", dropActiveElement); | |
1425 } | 1430 } |
1426 } | 1431 } |
1427 | 1432 |
1433 function dropActiveElement(event) | |
1434 { | |
1435 const active = event.target.ownerDocument.activeElement; | |
1436 if (active) | |
1437 active.blur(); | |
1438 } | |
1439 | |
1428 ext.onMessage.addListener((message) => | 1440 ext.onMessage.addListener((message) => |
1429 { | 1441 { |
1430 switch (message.type) | 1442 switch (message.type) |
1431 { | 1443 { |
1432 case "app.respond": | 1444 case "app.respond": |
1433 switch (message.action) | 1445 switch (message.action) |
1434 { | 1446 { |
1435 case "addSubscription": | 1447 case "addSubscription": |
1436 let subscription = message.args[0]; | 1448 let subscription = message.args[0]; |
1437 let dialog = E("dialog-content-predefined"); | 1449 let dialog = E("dialog-content-predefined"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 }); | 1484 }); |
1473 browser.runtime.sendMessage({ | 1485 browser.runtime.sendMessage({ |
1474 type: "subscriptions.listen", | 1486 type: "subscriptions.listen", |
1475 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1487 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1476 "title", "downloadStatus", "downloading"] | 1488 "title", "downloadStatus", "downloading"] |
1477 }); | 1489 }); |
1478 | 1490 |
1479 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1491 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1480 window.addEventListener("hashchange", onHashChange, false); | 1492 window.addEventListener("hashchange", onHashChange, false); |
1481 } | 1493 } |
OLD | NEW |