| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 (function() | 20 (function() |
| 21 { | 21 { |
| 22 var subscriptionsMap = Object.create(null); | 22 var subscriptionsMap = Object.create(null); |
| 23 var filtersMap = Object.create(null); | 23 var filtersMap = Object.create(null); |
| 24 var collections = Object.create(null); | 24 var collections = Object.create(null); |
| 25 var acceptableAdsUrl = null; | 25 var acceptableAdsUrl = null; |
| 26 var maxLabelId = 0; | 26 var maxItemId = 0; |
| 27 var getMessage = ext.i18n.getMessage; | 27 var getMessage = ext.i18n.getMessage; |
| 28 var filterErrors = | 28 var filterErrors = |
| 29 { | 29 { |
| 30 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", | 30 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", |
| 31 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror", | 31 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror", |
| 32 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", | 32 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", |
| 33 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch" | 33 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch" |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 function Collection(details) | 36 function Collection(details) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 }.bind(this)); | 94 }.bind(this)); |
| 95 | 95 |
| 96 for (var j = 0; j < this.details.length; j++) | 96 for (var j = 0; j < this.details.length; j++) |
| 97 { | 97 { |
| 98 var table = E(this.details[j].id); | 98 var table = E(this.details[j].id); |
| 99 var template = table.querySelector("template"); | 99 var template = table.querySelector("template"); |
| 100 for (var i = 0; i < arguments.length; i++) | 100 for (var i = 0; i < arguments.length; i++) |
| 101 { | 101 { |
| 102 var item = arguments[i]; | 102 var item = arguments[i]; |
| 103 var listItem = document.createElement("li"); | 103 var listItem = document.createElement("li"); |
| 104 var ItemId = "item-" + (++maxItemId); | |
|
Thomas Greiner
2016/06/16 10:42:22
Detail: Variable names should start with a lower-c
saroyanm
2016/06/16 18:22:59
Done.
| |
| 104 listItem.appendChild(document.importNode(template.content, true)); | 105 listItem.appendChild(document.importNode(template.content, true)); |
| 105 listItem.setAttribute("data-access", item.url || item.text); | 106 listItem.setAttribute("data-access", item.url || item.text); |
| 107 listItem.setAttribute("id", ItemId); | |
| 108 listItem.setAttribute("role", "section"); | |
| 106 | 109 |
| 107 var labelId = "label-" + (++maxLabelId); | |
| 108 var label = listItem.querySelector(".display"); | 110 var label = listItem.querySelector(".display"); |
| 109 label.setAttribute("id", labelId); | 111 label.setAttribute("for", ItemId); |
| 110 if (item.recommended && label.hasAttribute("data-tooltip")) | 112 if (item.recommended && label.hasAttribute("data-tooltip")) |
| 111 { | 113 { |
| 112 var tooltipId = label.getAttribute("data-tooltip"); | 114 var tooltipId = label.getAttribute("data-tooltip"); |
| 113 tooltipId = tooltipId.replace("%value%", item.recommended); | 115 tooltipId = tooltipId.replace("%value%", item.recommended); |
| 114 label.setAttribute("data-tooltip", tooltipId); | 116 label.setAttribute("data-tooltip", tooltipId); |
| 115 } | 117 } |
| 116 | 118 |
| 117 var control = listItem.querySelector(".control"); | 119 var controls = listItem.querySelectorAll(".control"); |
| 118 if (control) | 120 for (var k = 0; k < controls.length; k++) |
| 119 { | 121 controls[k].setAttribute("aria-labelledby", ItemId); |
| 120 control.setAttribute("aria-labelledby", labelId); | |
| 121 control.addEventListener("click", this.details[j].onClick, false); | |
| 122 | |
| 123 var role = control.getAttribute("role"); | |
| 124 if (role == "checkbox" && !label.hasAttribute("data-action")) | |
| 125 { | |
| 126 var controlId = "control-" + maxLabelId; | |
| 127 control.setAttribute("id", controlId); | |
| 128 label.setAttribute("for", controlId); | |
| 129 } | |
| 130 } | |
| 131 | 122 |
| 132 this._setEmpty(table, null); | 123 this._setEmpty(table, null); |
| 133 if (table.hasChildNodes()) | 124 if (table.hasChildNodes()) |
| 134 { | 125 { |
| 135 table.insertBefore(listItem, | 126 table.insertBefore(listItem, |
| 136 table.childNodes[this.items.indexOf(item)]); | 127 table.childNodes[this.items.indexOf(item)]); |
| 137 } | 128 } |
| 138 else | 129 else |
| 139 table.appendChild(listItem); | 130 table.appendChild(listItem); |
| 140 this.updateItem(item); | 131 this.updateItem(item); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 var access = (item.url || item.text).replace(/'/g, "\\'"); | 178 var access = (item.url || item.text).replace(/'/g, "\\'"); |
| 188 for (var i = 0; i < this.details.length; i++) | 179 for (var i = 0; i < this.details.length; i++) |
| 189 { | 180 { |
| 190 var table = E(this.details[i].id); | 181 var table = E(this.details[i].id); |
| 191 var element = table.querySelector("[data-access='" + access + "']"); | 182 var element = table.querySelector("[data-access='" + access + "']"); |
| 192 if (!element) | 183 if (!element) |
| 193 continue; | 184 continue; |
| 194 | 185 |
| 195 var title = this._getItemTitle(item, i); | 186 var title = this._getItemTitle(item, i); |
| 196 element.querySelector(".display").textContent = title; | 187 element.querySelector(".display").textContent = title; |
| 188 element.setAttribute("label", title); | |
|
Thomas Greiner
2016/06/16 10:42:22
What's the "label" attribute supposed to do?
saroyanm
2016/06/16 18:22:59
I was testing with screen reader and apparently in
Thomas Greiner
2016/06/17 14:07:50
Ok, in that case please use the standardized "aria
saroyanm
2016/06/21 13:29:56
I had another look and seems like removing this at
Thomas Greiner
2016/06/22 10:26:13
I could imagine that the duplication might be beca
saroyanm
2016/06/22 13:46:16
Genius! Done.
| |
| 197 if (title) | 189 if (title) |
| 198 element.setAttribute("data-search", title.toLowerCase()); | 190 element.setAttribute("data-search", title.toLowerCase()); |
| 199 var control = element.querySelector(".control[role='checkbox']"); | 191 var control = element.querySelector(".control[role='checkbox']"); |
| 200 if (control) | 192 if (control) |
| 201 { | 193 { |
| 202 control.setAttribute("aria-checked", item.disabled == false); | 194 control.setAttribute("aria-checked", item.disabled == false); |
| 203 if (item.url == acceptableAdsUrl && this.details[i].onClick == | 195 if (item.url == acceptableAdsUrl && this == collections.filterLists) |
| 204 toggleDisableSubscription) | |
| 205 control.setAttribute("disabled", true); | 196 control.setAttribute("disabled", true); |
| 206 } | 197 } |
| 207 | 198 |
| 208 var dateElement = element.querySelector(".date"); | 199 var dateElement = element.querySelector(".date"); |
| 209 var timeElement = element.querySelector(".time"); | 200 var timeElement = element.querySelector(".time"); |
| 210 if (dateElement && timeElement) | 201 if (dateElement && timeElement) |
| 211 { | 202 { |
| 212 var message = element.querySelector(".message"); | 203 var message = element.querySelector(".message"); |
| 213 if (item.isDownloading) | 204 if (item.isDownloading) |
| 214 { | 205 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 index += (index == focusables.length - 1) ? -1 : 1; | 266 index += (index == focusables.length - 1) ? -1 : 1; |
| 276 | 267 |
| 277 var nextElement = focusables[index]; | 268 var nextElement = focusables[index]; |
| 278 if (!nextElement) | 269 if (!nextElement) |
| 279 return false; | 270 return false; |
| 280 | 271 |
| 281 nextElement.focus(); | 272 nextElement.focus(); |
| 282 return true; | 273 return true; |
| 283 } | 274 } |
| 284 | 275 |
| 285 function toggleRemoveSubscription(e) | |
| 286 { | |
| 287 e.preventDefault(); | |
| 288 var subscriptionUrl = findParentData(e.target, "access", false); | |
| 289 if (e.target.getAttribute("aria-checked") == "true") | |
| 290 { | |
| 291 ext.backgroundPage.sendMessage({ | |
| 292 type: "subscriptions.remove", | |
| 293 url: subscriptionUrl | |
| 294 }); | |
| 295 } | |
| 296 else | |
| 297 addEnableSubscription(subscriptionUrl); | |
| 298 } | |
| 299 | |
| 300 function toggleDisableSubscription(e) | |
| 301 { | |
| 302 e.preventDefault(); | |
| 303 var subscriptionUrl = findParentData(e.target, "access", false); | |
| 304 ext.backgroundPage.sendMessage( | |
| 305 { | |
| 306 type: "subscriptions.toggle", | |
| 307 keepInstalled: true, | |
| 308 url: subscriptionUrl | |
| 309 }); | |
| 310 } | |
| 311 | |
| 312 function onAddLanguageSubscriptionClick(e) | |
| 313 { | |
| 314 e.preventDefault(); | |
| 315 var url = findParentData(this, "access", false); | |
| 316 addEnableSubscription(url); | |
| 317 } | |
| 318 | |
| 319 function onRemoveFilterClick() | |
| 320 { | |
| 321 var filter = findParentData(this, "access", false); | |
| 322 ext.backgroundPage.sendMessage( | |
| 323 { | |
| 324 type: "filters.remove", | |
| 325 text: filter | |
| 326 }); | |
| 327 } | |
| 328 | |
| 329 collections.popular = new Collection( | 276 collections.popular = new Collection( |
| 330 [ | 277 [ |
| 331 { | 278 { |
| 332 id: "recommend-list-table", | 279 id: "recommend-list-table" |
| 333 onClick: toggleRemoveSubscription | |
| 334 } | 280 } |
| 335 ]); | 281 ]); |
| 336 collections.langs = new Collection( | 282 collections.langs = new Collection( |
| 337 [ | 283 [ |
| 338 { | 284 { |
| 339 id: "blocking-languages-table", | 285 id: "blocking-languages-table", |
| 340 emptyText: "options_dialog_language_added_empty", | 286 emptyText: "options_dialog_language_added_empty" |
| 341 onClick: toggleRemoveSubscription | |
| 342 }, | 287 }, |
| 343 { | 288 { |
| 344 id: "blocking-languages-dialog-table", | 289 id: "blocking-languages-dialog-table", |
| 345 emptyText: "options_dialog_language_added_empty" | 290 emptyText: "options_dialog_language_added_empty" |
| 346 } | 291 } |
| 347 ]); | 292 ]); |
| 348 collections.allLangs = new Collection( | 293 collections.allLangs = new Collection( |
| 349 [ | 294 [ |
| 350 { | 295 { |
| 351 id: "all-lang-table", | 296 id: "all-lang-table", |
| 352 emptyText: "options_dialog_language_other_empty", | 297 emptyText: "options_dialog_language_other_empty" |
| 353 onClick: onAddLanguageSubscriptionClick | |
| 354 } | 298 } |
| 355 ]); | 299 ]); |
| 356 collections.acceptableAds = new Collection( | 300 collections.acceptableAds = new Collection( |
| 357 [ | 301 [ |
| 358 { | 302 { |
| 359 id: "acceptableads-table", | 303 id: "acceptableads-table" |
| 360 onClick: toggleRemoveSubscription | |
| 361 } | 304 } |
| 362 ]); | 305 ]); |
| 363 collections.custom = new Collection( | 306 collections.custom = new Collection( |
| 364 [ | 307 [ |
| 365 { | 308 { |
| 366 id: "custom-list-table", | 309 id: "custom-list-table" |
| 367 onClick: toggleRemoveSubscription | |
| 368 } | 310 } |
| 369 ]); | 311 ]); |
| 370 collections.whitelist = new Collection( | 312 collections.whitelist = new Collection( |
| 371 [ | 313 [ |
| 372 { | 314 { |
| 373 id: "whitelisting-table", | 315 id: "whitelisting-table", |
| 374 emptyText: "options_whitelisted_empty", | 316 emptyText: "options_whitelisted_empty" |
| 375 onClick: onRemoveFilterClick | |
| 376 } | 317 } |
| 377 ]); | 318 ]); |
| 378 collections.customFilters = new Collection( | 319 collections.customFilters = new Collection( |
| 379 [ | 320 [ |
| 380 { | 321 { |
| 381 id: "custom-filters-table", | 322 id: "custom-filters-table", |
| 382 emptyText: "options_customFilters_empty" | 323 emptyText: "options_customFilters_empty" |
| 383 } | 324 } |
| 384 ]); | 325 ]); |
| 385 collections.filterLists = new Collection( | 326 collections.filterLists = new Collection( |
| 386 [ | 327 [ |
| 387 { | 328 { |
| 388 id: "all-filter-lists-table", | 329 id: "all-filter-lists-table", |
| 389 onClick: toggleDisableSubscription, | |
| 390 useOriginalTitle: true | 330 useOriginalTitle: true |
| 391 } | 331 } |
| 392 ]); | 332 ]); |
| 393 | 333 |
| 394 function updateLanguageCollections(subscription) | 334 function updateLanguageCollections(subscription) |
| 395 { | 335 { |
| 396 if (subscription.recommended == "ads") | 336 if (subscription.recommended == "ads") |
| 397 { | 337 { |
| 398 if (subscription.disabled) | 338 if (subscription.disabled) |
| 399 { | 339 { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 url: findParentData(element, "access", false) | 566 url: findParentData(element, "access", false) |
| 627 }); | 567 }); |
| 628 break; | 568 break; |
| 629 case "remove-subscription": | 569 case "remove-subscription": |
| 630 ext.backgroundPage.sendMessage( | 570 ext.backgroundPage.sendMessage( |
| 631 { | 571 { |
| 632 type: "subscriptions.remove", | 572 type: "subscriptions.remove", |
| 633 url: findParentData(element, "access", false) | 573 url: findParentData(element, "access", false) |
| 634 }); | 574 }); |
| 635 break; | 575 break; |
| 576 case "toggle-remove-subscription": | |
| 577 var subscriptionUrl = findParentData(element, "access", false); | |
| 578 if (element.getAttribute("aria-checked") == "true") | |
| 579 { | |
| 580 ext.backgroundPage.sendMessage({ | |
| 581 type: "subscriptions.remove", | |
| 582 url: subscriptionUrl | |
| 583 }); | |
| 584 } | |
| 585 else | |
| 586 addEnableSubscription(subscriptionUrl); | |
| 587 break; | |
| 588 case "toggle-disable-subscription": | |
| 589 ext.backgroundPage.sendMessage( | |
| 590 { | |
| 591 type: "subscriptions.toggle", | |
| 592 keepInstalled: true, | |
| 593 url: findParentData(element, "access", false) | |
| 594 }); | |
| 595 break; | |
| 596 case "add-language-subscription": | |
| 597 addEnableSubscription(findParentData(element, "access", false)); | |
| 598 break; | |
| 599 case "remove-filter": | |
| 600 ext.backgroundPage.sendMessage( | |
| 601 { | |
| 602 type: "filters.remove", | |
| 603 text: findParentData(element, "access", false) | |
| 604 }); | |
| 605 break; | |
| 636 } | 606 } |
| 637 } | 607 } |
| 638 } | 608 } |
| 639 | 609 |
| 640 function onDOMLoaded() | 610 function onDOMLoaded() |
| 641 { | 611 { |
| 642 populateLists(); | 612 populateLists(); |
| 643 function onFindLanguageKeyUp() | 613 function onFindLanguageKeyUp() |
| 644 { | 614 { |
| 645 var searchStyle = E("search-style"); | 615 var searchStyle = E("search-style"); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1198 }); | 1168 }); |
| 1199 ext.backgroundPage.sendMessage( | 1169 ext.backgroundPage.sendMessage( |
| 1200 { | 1170 { |
| 1201 type: "subscriptions.listen", | 1171 type: "subscriptions.listen", |
| 1202 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1172 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
| 1203 "title", "downloadStatus", "downloading"] | 1173 "title", "downloadStatus", "downloading"] |
| 1204 }); | 1174 }); |
| 1205 | 1175 |
| 1206 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1176 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
| 1207 })(); | 1177 })(); |
| OLD | NEW |