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