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

Powered by Google App Engine
This is Rietveld