Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: new-options.js

Issue 29338983: issue 3741 - Add "remove" option to list items in new options page (Closed)
Patch Set: Impoved accessibility, removed onclick assignments from the collections Created June 8, 2016, 3:02 p.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 | « new-options.html ('k') | skin/new-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-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 recommendationsMap = Object.create(null); 23 var recommendationsMap = Object.create(null);
24 var filtersMap = Object.create(null); 24 var filtersMap = Object.create(null);
25 var collections = Object.create(null); 25 var collections = Object.create(null);
26 var acceptableAdsUrl = null; 26 var acceptableAdsUrl = null;
27 var maxLabelId = 0; 27 var maxItemId = 0;
28 var getMessage = ext.i18n.getMessage; 28 var getMessage = ext.i18n.getMessage;
29 var filterErrors = 29 var filterErrors =
30 { 30 {
31 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL", 31 "synchronize_invalid_url": "options_filterList_lastDownload_invalidURL",
32 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror", 32 "synchronize_connection_error": "options_filterList_lastDownload_connectionE rror",
33 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData", 33 "synchronize_invalid_data": "options_filterList_lastDownload_invalidData",
34 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch" 34 "synchronize_checksum_mismatch": "options_filterList_lastDownload_checksumMi smatch"
35 }; 35 };
36 36
37 function Collection(details) 37 function Collection(details)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 }.bind(this)); 95 }.bind(this));
96 96
97 for (var j = 0; j < this.details.length; j++) 97 for (var j = 0; j < this.details.length; j++)
98 { 98 {
99 var table = E(this.details[j].id); 99 var table = E(this.details[j].id);
100 var template = table.querySelector("template"); 100 var template = table.querySelector("template");
101 for (var i = 0; i < arguments.length; i++) 101 for (var i = 0; i < arguments.length; i++)
102 { 102 {
103 var item = arguments[i]; 103 var item = arguments[i];
104 var listItem = document.createElement("li"); 104 var listItem = document.createElement("li");
105 var ItemId = "item-" + (++maxItemId);
105 listItem.appendChild(document.importNode(template.content, true)); 106 listItem.appendChild(document.importNode(template.content, true));
106 listItem.setAttribute("data-access", item.url || item.text); 107 listItem.setAttribute("data-access", item.url || item.text);
108 listItem.setAttribute("id", ItemId);
109 listItem.setAttribute("role", "section");
107 110
108 var labelId = "label-" + (++maxLabelId);
109 var label = listItem.querySelector(".display"); 111 var label = listItem.querySelector(".display");
110 label.setAttribute("id", labelId); 112 label.setAttribute("for", ItemId);
111 113
112 var control = listItem.querySelector(".control"); 114 var controls = listItem.querySelectorAll(".control");
113 if (control) 115 for (var k = 0; k < controls.length; k++)
114 { 116 controls[k].setAttribute("aria-labelledby", ItemId);
115 control.setAttribute("aria-labelledby", labelId);
116 control.addEventListener("click", this.details[j].onClick, false);
117
118 var role = control.getAttribute("role");
119 if (role == "checkbox" && !label.hasAttribute("data-action"))
120 {
121 var controlId = "control-" + maxLabelId;
122 control.setAttribute("id", controlId);
123 label.setAttribute("for", controlId);
124 }
125 }
126 117
127 this._setEmpty(table, null); 118 this._setEmpty(table, null);
128 if (table.hasChildNodes()) 119 if (table.hasChildNodes())
129 { 120 {
130 table.insertBefore(listItem, 121 table.insertBefore(listItem,
131 table.childNodes[this.items.indexOf(item)]); 122 table.childNodes[this.items.indexOf(item)]);
132 } 123 }
133 else 124 else
134 table.appendChild(listItem); 125 table.appendChild(listItem);
135 this.updateItem(item); 126 this.updateItem(item);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 var access = (item.url || item.text).replace(/'/g, "\\'"); 173 var access = (item.url || item.text).replace(/'/g, "\\'");
183 for (var i = 0; i < this.details.length; i++) 174 for (var i = 0; i < this.details.length; i++)
184 { 175 {
185 var table = E(this.details[i].id); 176 var table = E(this.details[i].id);
186 var element = table.querySelector("[data-access='" + access + "']"); 177 var element = table.querySelector("[data-access='" + access + "']");
187 if (!element) 178 if (!element)
188 continue; 179 continue;
189 180
190 var title = this._getItemTitle(item, i); 181 var title = this._getItemTitle(item, i);
191 element.querySelector(".display").textContent = title; 182 element.querySelector(".display").textContent = title;
183 element.setAttribute("label", title);
192 if (title) 184 if (title)
saroyanm 2016/06/08 15:21:07 I think we should only specify the "data-search" a
Thomas Greiner 2016/06/16 10:42:22 Ok, feel free to change it so that it's only added
saroyanm 2016/06/16 18:22:59 Done.
193 element.setAttribute("data-search", title.toLowerCase()); 185 element.setAttribute("data-search", title.toLowerCase());
194 var control = element.querySelector(".control[role='checkbox']"); 186 var control = element.querySelector(".control[role='checkbox']");
195 if (control) 187 if (control)
196 { 188 {
197 control.setAttribute("aria-checked", item.disabled == false); 189 control.setAttribute("aria-checked", item.disabled == false);
198 if (item.url == acceptableAdsUrl && this.details[i].onClick == 190 if (item.url == acceptableAdsUrl && this == collections.filterLists)
199 toggleDisableSubscription)
200 control.setAttribute("disabled", true); 191 control.setAttribute("disabled", true);
201 } 192 }
202 193
203 var dateElement = element.querySelector(".date"); 194 var dateElement = element.querySelector(".date");
204 var timeElement = element.querySelector(".time"); 195 var timeElement = element.querySelector(".time");
205 if (dateElement && timeElement) 196 if (dateElement && timeElement)
206 { 197 {
207 var message = element.querySelector(".message"); 198 var message = element.querySelector(".message");
208 if (item.isDownloading) 199 if (item.isDownloading)
209 { 200 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 index += (index == focusables.length - 1) ? -1 : 1; 261 index += (index == focusables.length - 1) ? -1 : 1;
271 262
272 var nextElement = focusables[index]; 263 var nextElement = focusables[index];
273 if (!nextElement) 264 if (!nextElement)
274 return false; 265 return false;
275 266
276 nextElement.focus(); 267 nextElement.focus();
277 return true; 268 return true;
278 } 269 }
279 270
280 function toggleRemoveSubscription(e)
281 {
282 e.preventDefault();
283 var subscriptionUrl = findParentData(e.target, "access", false);
284 if (e.target.getAttribute("aria-checked") == "true")
285 {
286 ext.backgroundPage.sendMessage({
287 type: "subscriptions.remove",
288 url: subscriptionUrl
289 });
290 }
291 else
292 addEnableSubscription(subscriptionUrl);
293 }
294
295 function toggleDisableSubscription(e)
296 {
297 e.preventDefault();
298 var subscriptionUrl = findParentData(e.target, "access", false);
299 ext.backgroundPage.sendMessage(
300 {
301 type: "subscriptions.toggle",
302 keepInstalled: true,
303 url: subscriptionUrl
304 });
305 }
306
307 function onAddLanguageSubscriptionClick(e)
308 {
309 e.preventDefault();
310 var url = findParentData(this, "access", false);
311 addEnableSubscription(url);
312 }
313
314 function onRemoveFilterClick()
315 {
316 var filter = findParentData(this, "access", false);
317 ext.backgroundPage.sendMessage(
318 {
319 type: "filters.remove",
320 text: filter
321 });
322 }
323
324 collections.popular = new Collection( 271 collections.popular = new Collection(
325 [ 272 [
326 { 273 {
327 id: "recommend-list-table", 274 id: "recommend-list-table"
328 onClick: toggleRemoveSubscription
329 } 275 }
330 ]); 276 ]);
331 collections.langs = new Collection( 277 collections.langs = new Collection(
332 [ 278 [
333 { 279 {
334 id: "blocking-languages-table", 280 id: "blocking-languages-table",
335 emptyText: "options_dialog_language_added_empty", 281 emptyText: "options_dialog_language_added_empty"
336 onClick: toggleRemoveSubscription
337 }, 282 },
338 { 283 {
339 id: "blocking-languages-dialog-table", 284 id: "blocking-languages-dialog-table",
340 emptyText: "options_dialog_language_added_empty" 285 emptyText: "options_dialog_language_added_empty"
341 } 286 }
342 ]); 287 ]);
343 collections.allLangs = new Collection( 288 collections.allLangs = new Collection(
344 [ 289 [
345 { 290 {
346 id: "all-lang-table", 291 id: "all-lang-table",
347 emptyText: "options_dialog_language_other_empty", 292 emptyText: "options_dialog_language_other_empty"
348 onClick: onAddLanguageSubscriptionClick
349 } 293 }
350 ]); 294 ]);
351 collections.acceptableAds = new Collection( 295 collections.acceptableAds = new Collection(
352 [ 296 [
353 { 297 {
354 id: "acceptableads-table", 298 id: "acceptableads-table"
355 onClick: toggleRemoveSubscription
356 } 299 }
357 ]); 300 ]);
358 collections.custom = new Collection( 301 collections.custom = new Collection(
359 [ 302 [
360 { 303 {
361 id: "custom-list-table", 304 id: "custom-list-table"
362 onClick: toggleRemoveSubscription
363 } 305 }
364 ]); 306 ]);
365 collections.whitelist = new Collection( 307 collections.whitelist = new Collection(
366 [ 308 [
367 { 309 {
368 id: "whitelisting-table", 310 id: "whitelisting-table",
369 emptyText: "options_whitelisted_empty", 311 emptyText: "options_whitelisted_empty"
370 onClick: onRemoveFilterClick
371 } 312 }
372 ]); 313 ]);
373 collections.customFilters = new Collection( 314 collections.customFilters = new Collection(
374 [ 315 [
375 { 316 {
376 id: "custom-filters-table", 317 id: "custom-filters-table",
377 emptyText: "options_customFilters_empty" 318 emptyText: "options_customFilters_empty"
378 } 319 }
379 ]); 320 ]);
380 collections.filterLists = new Collection( 321 collections.filterLists = new Collection(
381 [ 322 [
382 { 323 {
383 id: "all-filter-lists-table", 324 id: "all-filter-lists-table",
384 onClick: toggleDisableSubscription,
385 useOriginalTitle: true 325 useOriginalTitle: true
386 } 326 }
387 ]); 327 ]);
388 328
389 function updateLanguageCollections(subscription) 329 function updateLanguageCollections(subscription)
390 { 330 {
391 var recommendation = recommendationsMap[subscription.url]; 331 var recommendation = recommendationsMap[subscription.url];
392 332
393 if (recommendation && recommendation.type == "ads") 333 if (recommendation && recommendation.type == "ads")
394 { 334 {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 { 409 {
470 var list = document.getElementById("subscriptionSelector"); 410 var list = document.getElementById("subscriptionSelector");
471 var doc = new DOMParser().parseFromString(text, "application/xml"); 411 var doc = new DOMParser().parseFromString(text, "application/xml");
472 var elements = doc.documentElement.getElementsByTagName("subscription"); 412 var elements = doc.documentElement.getElementsByTagName("subscription");
473 for (var i = 0; i < elements.length; i++) 413 for (var i = 0; i < elements.length; i++)
474 { 414 {
475 var element = elements[i]; 415 var element = elements[i];
476 var subscription = Object.create(null); 416 var subscription = Object.create(null);
477 subscription.originalTitle = element.getAttribute("title"); 417 subscription.originalTitle = element.getAttribute("title");
478 subscription.url = element.getAttribute("url"); 418 subscription.url = element.getAttribute("url");
479 subscription.disabled = null; 419 subscription.disabled = true;
480 subscription.downloadStatus = null; 420 subscription.downloadStatus = null;
481 subscription.homepage = null; 421 subscription.homepage = null;
482 var recommendation = Object.create(null); 422 var recommendation = Object.create(null);
483 recommendation.type = element.getAttribute("type"); 423 recommendation.type = element.getAttribute("type");
484 var prefix = element.getAttribute("prefixes"); 424 var prefix = element.getAttribute("prefixes");
485 if (prefix) 425 if (prefix)
486 { 426 {
487 prefix = prefix.replace(/\W/g, "_"); 427 prefix = prefix.replace(/\W/g, "_");
488 subscription.title = getMessage("options_language_" + prefix); 428 subscription.title = getMessage("options_language_" + prefix);
489 } 429 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 url: findParentData(element, "access", false) 562 url: findParentData(element, "access", false)
623 }); 563 });
624 break; 564 break;
625 case "remove-subscription": 565 case "remove-subscription":
626 ext.backgroundPage.sendMessage( 566 ext.backgroundPage.sendMessage(
627 { 567 {
628 type: "subscriptions.remove", 568 type: "subscriptions.remove",
629 url: findParentData(element, "access", false) 569 url: findParentData(element, "access", false)
630 }); 570 });
631 break; 571 break;
572 case "toggle-remove-subscription":
573 var subscriptionUrl = findParentData(element, "access", false);
574 if (element.getAttribute("aria-checked") == "true")
575 {
576 ext.backgroundPage.sendMessage({
577 type: "subscriptions.remove",
578 url: subscriptionUrl
579 });
580 }
581 else
582 addEnableSubscription(subscriptionUrl);
583 break;
584 case "toggle-disable-subscription":
585 ext.backgroundPage.sendMessage(
586 {
587 type: "subscriptions.toggle",
588 keepInstalled: true,
589 url: findParentData(element, "access", false)
590 });
591 break;
592 case "add-language-subscription":
593 addEnableSubscription(findParentData(element, "access", false));
594 break;
595 case "remove-filter":
596 ext.backgroundPage.sendMessage(
597 {
598 type: "filters.remove",
599 text: findParentData(element, "access", false)
600 });
601 break;
632 } 602 }
633 } 603 }
634 } 604 }
635 605
636 function onDOMLoaded() 606 function onDOMLoaded()
637 { 607 {
638 populateLists(); 608 populateLists();
639 function onFindLanguageKeyUp() 609 function onFindLanguageKeyUp()
640 { 610 {
641 var searchStyle = E("search-style"); 611 var searchStyle = E("search-style");
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 }); 1087 });
1118 ext.backgroundPage.sendMessage( 1088 ext.backgroundPage.sendMessage(
1119 { 1089 {
1120 type: "subscriptions.listen", 1090 type: "subscriptions.listen",
1121 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1091 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1122 "title", "downloadStatus", "downloading"] 1092 "title", "downloadStatus", "downloading"]
1123 }); 1093 });
1124 1094
1125 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1095 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1126 })(); 1096 })();
OLDNEW
« no previous file with comments | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld