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; | |
27 var getMessage = ext.i18n.getMessage; | 26 var getMessage = ext.i18n.getMessage; |
28 var filterErrors = | 27 var filterErrors = |
29 { | 28 { |
30 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", | 29 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", |
31 "synchronize_connection_error": "options_filterList_lastDownload_connectionE
rror", | 30 "synchronize_connection_error": "options_filterList_lastDownload_connectionE
rror", |
32 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", | 31 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", |
33 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi
smatch" | 32 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi
smatch" |
34 }; | 33 }; |
35 | 34 |
36 function Collection(details) | 35 function Collection(details) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 94 |
96 for (var j = 0; j < this.details.length; j++) | 95 for (var j = 0; j < this.details.length; j++) |
97 { | 96 { |
98 var table = E(this.details[j].id); | 97 var table = E(this.details[j].id); |
99 var template = table.querySelector("template"); | 98 var template = table.querySelector("template"); |
100 for (var i = 0; i < arguments.length; i++) | 99 for (var i = 0; i < arguments.length; i++) |
101 { | 100 { |
102 var item = arguments[i]; | 101 var item = arguments[i]; |
103 var listItem = document.createElement("li"); | 102 var listItem = document.createElement("li"); |
104 listItem.appendChild(document.importNode(template.content, true)); | 103 listItem.appendChild(document.importNode(template.content, true)); |
| 104 listItem.setAttribute("aria-label", this._getItemTitle(item, j)); |
105 listItem.setAttribute("data-access", item.url || item.text); | 105 listItem.setAttribute("data-access", item.url || item.text); |
| 106 listItem.setAttribute("role", "section"); |
106 | 107 |
107 var labelId = "label-" + (++maxLabelId); | |
108 var label = listItem.querySelector(".display"); | 108 var label = listItem.querySelector(".display"); |
109 label.setAttribute("id", labelId); | |
110 if (item.recommended && label.hasAttribute("data-tooltip")) | 109 if (item.recommended && label.hasAttribute("data-tooltip")) |
111 { | 110 { |
112 var tooltipId = label.getAttribute("data-tooltip"); | 111 var tooltipId = label.getAttribute("data-tooltip"); |
113 tooltipId = tooltipId.replace("%value%", item.recommended); | 112 tooltipId = tooltipId.replace("%value%", item.recommended); |
114 label.setAttribute("data-tooltip", tooltipId); | 113 label.setAttribute("data-tooltip", tooltipId); |
115 } | 114 } |
116 | 115 |
117 var control = listItem.querySelector(".control"); | 116 var controls = listItem.querySelectorAll(".control"); |
118 if (control) | 117 for (var k = 0; k < controls.length; k++) |
119 { | 118 { |
120 control.setAttribute("aria-labelledby", labelId); | 119 if (controls[k].hasAttribute("title")) |
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 { | 120 { |
126 var controlId = "control-" + maxLabelId; | 121 var titleValue = getMessage(controls[k].getAttribute("title")); |
127 control.setAttribute("id", controlId); | 122 controls[k].setAttribute("title", titleValue) |
128 label.setAttribute("for", controlId); | |
129 } | 123 } |
130 } | 124 } |
131 | 125 |
132 this._setEmpty(table, null); | 126 this._setEmpty(table, null); |
133 if (table.hasChildNodes()) | 127 if (table.hasChildNodes()) |
134 { | 128 { |
135 table.insertBefore(listItem, | 129 table.insertBefore(listItem, |
136 table.childNodes[this.items.indexOf(item)]); | 130 table.childNodes[this.items.indexOf(item)]); |
137 } | 131 } |
138 else | 132 else |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 var access = (item.url || item.text).replace(/'/g, "\\'"); | 181 var access = (item.url || item.text).replace(/'/g, "\\'"); |
188 for (var i = 0; i < this.details.length; i++) | 182 for (var i = 0; i < this.details.length; i++) |
189 { | 183 { |
190 var table = E(this.details[i].id); | 184 var table = E(this.details[i].id); |
191 var element = table.querySelector("[data-access='" + access + "']"); | 185 var element = table.querySelector("[data-access='" + access + "']"); |
192 if (!element) | 186 if (!element) |
193 continue; | 187 continue; |
194 | 188 |
195 var title = this._getItemTitle(item, i); | 189 var title = this._getItemTitle(item, i); |
196 element.querySelector(".display").textContent = title; | 190 element.querySelector(".display").textContent = title; |
197 if (title) | 191 element.setAttribute("aria-label", title); |
| 192 if (this.details[i].searchable) |
198 element.setAttribute("data-search", title.toLowerCase()); | 193 element.setAttribute("data-search", title.toLowerCase()); |
199 var control = element.querySelector(".control[role='checkbox']"); | 194 var control = element.querySelector(".control[role='checkbox']"); |
200 if (control) | 195 if (control) |
201 { | 196 { |
202 control.setAttribute("aria-checked", item.disabled == false); | 197 control.setAttribute("aria-checked", item.disabled == false); |
203 if (item.url == acceptableAdsUrl && this.details[i].onClick == | 198 if (item.url == acceptableAdsUrl && this == collections.filterLists) |
204 toggleDisableSubscription) | |
205 control.setAttribute("disabled", true); | 199 control.setAttribute("disabled", true); |
206 } | 200 } |
207 | 201 |
208 var dateElement = element.querySelector(".date"); | 202 var dateElement = element.querySelector(".date"); |
209 var timeElement = element.querySelector(".time"); | 203 var timeElement = element.querySelector(".time"); |
210 if (dateElement && timeElement) | 204 if (dateElement && timeElement) |
211 { | 205 { |
212 var message = element.querySelector(".message"); | 206 var message = element.querySelector(".message"); |
213 if (item.isDownloading) | 207 if (item.isDownloading) |
214 { | 208 { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 index += (index == focusables.length - 1) ? -1 : 1; | 269 index += (index == focusables.length - 1) ? -1 : 1; |
276 | 270 |
277 var nextElement = focusables[index]; | 271 var nextElement = focusables[index]; |
278 if (!nextElement) | 272 if (!nextElement) |
279 return false; | 273 return false; |
280 | 274 |
281 nextElement.focus(); | 275 nextElement.focus(); |
282 return true; | 276 return true; |
283 } | 277 } |
284 | 278 |
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( | 279 collections.popular = new Collection( |
330 [ | 280 [ |
331 { | 281 { |
332 id: "recommend-list-table", | 282 id: "recommend-list-table" |
333 onClick: toggleRemoveSubscription | |
334 } | 283 } |
335 ]); | 284 ]); |
336 collections.langs = new Collection( | 285 collections.langs = new Collection( |
337 [ | 286 [ |
338 { | 287 { |
339 id: "blocking-languages-table", | 288 id: "blocking-languages-table", |
340 emptyText: "options_dialog_language_added_empty", | 289 emptyText: "options_dialog_language_added_empty" |
341 onClick: toggleRemoveSubscription | |
342 }, | 290 }, |
343 { | 291 { |
344 id: "blocking-languages-dialog-table", | 292 id: "blocking-languages-dialog-table", |
345 emptyText: "options_dialog_language_added_empty" | 293 emptyText: "options_dialog_language_added_empty" |
346 } | 294 } |
347 ]); | 295 ]); |
348 collections.allLangs = new Collection( | 296 collections.allLangs = new Collection( |
349 [ | 297 [ |
350 { | 298 { |
351 id: "all-lang-table", | 299 id: "all-lang-table", |
352 emptyText: "options_dialog_language_other_empty", | 300 emptyText: "options_dialog_language_other_empty", |
353 onClick: onAddLanguageSubscriptionClick | 301 searchable: true |
354 } | 302 } |
355 ]); | 303 ]); |
356 collections.acceptableAds = new Collection( | 304 collections.acceptableAds = new Collection( |
357 [ | 305 [ |
358 { | 306 { |
359 id: "acceptableads-table", | 307 id: "acceptableads-table" |
360 onClick: toggleRemoveSubscription | |
361 } | 308 } |
362 ]); | 309 ]); |
363 collections.custom = new Collection( | 310 collections.custom = new Collection( |
364 [ | 311 [ |
365 { | 312 { |
366 id: "custom-list-table", | 313 id: "custom-list-table" |
367 onClick: toggleRemoveSubscription | |
368 } | 314 } |
369 ]); | 315 ]); |
370 collections.whitelist = new Collection( | 316 collections.whitelist = new Collection( |
371 [ | 317 [ |
372 { | 318 { |
373 id: "whitelisting-table", | 319 id: "whitelisting-table", |
374 emptyText: "options_whitelisted_empty", | 320 emptyText: "options_whitelisted_empty" |
375 onClick: onRemoveFilterClick | |
376 } | 321 } |
377 ]); | 322 ]); |
378 collections.customFilters = new Collection( | 323 collections.customFilters = new Collection( |
379 [ | 324 [ |
380 { | 325 { |
381 id: "custom-filters-table", | 326 id: "custom-filters-table", |
382 emptyText: "options_customFilters_empty" | 327 emptyText: "options_customFilters_empty" |
383 } | 328 } |
384 ]); | 329 ]); |
385 collections.filterLists = new Collection( | 330 collections.filterLists = new Collection( |
386 [ | 331 [ |
387 { | 332 { |
388 id: "all-filter-lists-table", | 333 id: "all-filter-lists-table", |
389 onClick: toggleDisableSubscription, | |
390 useOriginalTitle: true | 334 useOriginalTitle: true |
391 } | 335 } |
392 ]); | 336 ]); |
393 | 337 |
394 function updateLanguageCollections(subscription) | 338 function updateLanguageCollections(subscription) |
395 { | 339 { |
396 if (subscription.recommended == "ads") | 340 if (subscription.recommended == "ads") |
397 { | 341 { |
398 if (subscription.disabled) | 342 if (subscription.disabled) |
399 { | 343 { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 url: findParentData(element, "access", false) | 570 url: findParentData(element, "access", false) |
627 }); | 571 }); |
628 break; | 572 break; |
629 case "remove-subscription": | 573 case "remove-subscription": |
630 ext.backgroundPage.sendMessage( | 574 ext.backgroundPage.sendMessage( |
631 { | 575 { |
632 type: "subscriptions.remove", | 576 type: "subscriptions.remove", |
633 url: findParentData(element, "access", false) | 577 url: findParentData(element, "access", false) |
634 }); | 578 }); |
635 break; | 579 break; |
| 580 case "toggle-remove-subscription": |
| 581 var subscriptionUrl = findParentData(element, "access", false); |
| 582 if (element.getAttribute("aria-checked") == "true") |
| 583 { |
| 584 ext.backgroundPage.sendMessage({ |
| 585 type: "subscriptions.remove", |
| 586 url: subscriptionUrl |
| 587 }); |
| 588 } |
| 589 else |
| 590 addEnableSubscription(subscriptionUrl); |
| 591 break; |
| 592 case "toggle-disable-subscription": |
| 593 ext.backgroundPage.sendMessage( |
| 594 { |
| 595 type: "subscriptions.toggle", |
| 596 keepInstalled: true, |
| 597 url: findParentData(element, "access", false) |
| 598 }); |
| 599 break; |
| 600 case "add-language-subscription": |
| 601 addEnableSubscription(findParentData(element, "access", false)); |
| 602 break; |
| 603 case "remove-filter": |
| 604 ext.backgroundPage.sendMessage( |
| 605 { |
| 606 type: "filters.remove", |
| 607 text: findParentData(element, "access", false) |
| 608 }); |
| 609 break; |
636 } | 610 } |
637 } | 611 } |
638 } | 612 } |
639 | 613 |
640 function onDOMLoaded() | 614 function onDOMLoaded() |
641 { | 615 { |
642 populateLists(); | 616 populateLists(); |
643 function onFindLanguageKeyUp() | 617 function onFindLanguageKeyUp() |
644 { | 618 { |
645 var searchStyle = E("search-style"); | 619 var searchStyle = E("search-style"); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (subscription.url in subscriptionsMap) | 920 if (subscription.url in subscriptionsMap) |
947 subscription = updateSubscription(subscription); | 921 subscription = updateSubscription(subscription); |
948 else | 922 else |
949 addSubscription(subscription); | 923 addSubscription(subscription); |
950 | 924 |
951 collections.filterLists.addItems(subscription); | 925 collections.filterLists.addItems(subscription); |
952 updateLanguageCollections(subscription); | 926 updateLanguageCollections(subscription); |
953 break; | 927 break; |
954 case "removed": | 928 case "removed": |
955 var knownSubscription = subscriptionsMap[subscription.url]; | 929 var knownSubscription = subscriptionsMap[subscription.url]; |
956 | |
957 if (subscription.url == acceptableAdsUrl || subscription.recommended) | 930 if (subscription.url == acceptableAdsUrl || subscription.recommended) |
958 { | 931 { |
959 subscription.disabled = true; | 932 subscription.disabled = true; |
960 onSubscriptionMessage("disabled", subscription); | 933 onSubscriptionMessage("disabled", subscription); |
961 } | 934 } |
962 else | 935 else |
963 { | 936 { |
964 collections.custom.removeItem(knownSubscription); | 937 collections.custom.removeItem(knownSubscription); |
965 delete subscriptionsMap[subscription.url]; | 938 delete subscriptionsMap[subscription.url]; |
966 } | 939 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 }); | 1171 }); |
1199 ext.backgroundPage.sendMessage( | 1172 ext.backgroundPage.sendMessage( |
1200 { | 1173 { |
1201 type: "subscriptions.listen", | 1174 type: "subscriptions.listen", |
1202 filter: ["added", "disabled", "homepage", "lastDownload", "removed", | 1175 filter: ["added", "disabled", "homepage", "lastDownload", "removed", |
1203 "title", "downloadStatus", "downloading"] | 1176 "title", "downloadStatus", "downloading"] |
1204 }); | 1177 }); |
1205 | 1178 |
1206 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); | 1179 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); |
1207 })(); | 1180 })(); |
OLD | NEW |