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

Side by Side Diff: options.js

Issue 8432019: Added acceptable ads list to the options UI (Closed)
Patch Set: Created Sept. 25, 2012, 2:18 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 | « options.html ('k') | update_locales.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var backgroundPage = chrome.extension.getBackgroundPage(); 1 var backgroundPage = chrome.extension.getBackgroundPage();
2 var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscr iption", 2 var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscr iption",
3 "DownloadableSubscription", "Filter", "WhitelistFilter", 3 "DownloadableSubscription", "Filter", "WhitelistFilter",
4 "Synchronizer", "require"]; 4 "Synchronizer", "Prefs", "Utils", "require"];
5 for (var i = 0; i < imports.length; i++) 5 for (var i = 0; i < imports.length; i++)
6 window[imports[i]] = backgroundPage[imports[i]]; 6 window[imports[i]] = backgroundPage[imports[i]];
7 7
8 // Loads options from localStorage and sets UI elements accordingly 8 // Loads options from localStorage and sets UI elements accordingly
9 function loadOptions() 9 function loadOptions()
10 { 10 {
11 loadI18nStrings(); 11 loadI18nStrings();
12 12
13 // Set page title to i18n version of "Adblock Plus Options" 13 // Set page title to i18n version of "Adblock Plus Options"
14 document.title = chrome.i18n.getMessage("options"); 14 document.title = chrome.i18n.getMessage("options");
15 15
16 // Set links
17 $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl);
18 $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/ g, "acceptable_ads").replace(/%LANG%/g, Utils.appLocale));
19
16 // Add event listeners 20 // Add event listeners
17 window.addEventListener("unload", unloadOptions, false); 21 window.addEventListener("unload", unloadOptions, false);
18 $("#updateFilterLists").click(updateFilterLists); 22 $("#updateFilterLists").click(updateFilterLists);
19 $("#startSubscriptionSelection").click(startSubscriptionSelection); 23 $("#startSubscriptionSelection").click(startSubscriptionSelection);
20 $("#subscriptionSelector").change(updateSubscriptionSelection); 24 $("#subscriptionSelector").change(updateSubscriptionSelection);
21 $("#addSubscription").click(addSubscription); 25 $("#addSubscription").click(addSubscription);
26 $("#acceptableAds").click(allowAcceptableAds);
22 $("#whitelistForm").submit(addWhitelistDomain); 27 $("#whitelistForm").submit(addWhitelistDomain);
23 $("#removeWhitelist").click(removeSelectedExcludedDomain); 28 $("#removeWhitelist").click(removeSelectedExcludedDomain);
24 $("#customFilterForm").submit(addTypedFilter); 29 $("#customFilterForm").submit(addTypedFilter);
25 $("#removeCustomFilter").click(removeSelectedFilters); 30 $("#removeCustomFilter").click(removeSelectedFilters);
26 $("#rawFiltersButton").click(toggleFiltersInRawFormat); 31 $("#rawFiltersButton").click(toggleFiltersInRawFormat);
27 $("#importRawFilters").click(importRawFiltersText); 32 $("#importRawFilters").click(importRawFiltersText);
28 FilterNotifier.addListener(onFilterChange); 33 FilterNotifier.addListener(onFilterChange);
29 34
30 // Display jQuery UI elements 35 // Display jQuery UI elements
31 $("#tabs").tabs(); 36 $("#tabs").tabs();
(...skipping 17 matching lines...) Expand all
49 $(loadOptions); 54 $(loadOptions);
50 55
51 // Reloads the displayed subscriptions and filters 56 // Reloads the displayed subscriptions and filters
52 function reloadFilters() 57 function reloadFilters()
53 { 58 {
54 // Load user filter URLs 59 // Load user filter URLs
55 var container = document.getElementById("filterLists"); 60 var container = document.getElementById("filterLists");
56 while (container.lastChild) 61 while (container.lastChild)
57 container.removeChild(container.lastChild); 62 container.removeChild(container.lastChild);
58 63
64 var hasAcceptable = false;
59 for (var i = 0; i < FilterStorage.subscriptions.length; i++) 65 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
60 { 66 {
61 var subscription = FilterStorage.subscriptions[i]; 67 var subscription = FilterStorage.subscriptions[i];
62 if (subscription instanceof SpecialSubscription) 68 if (subscription instanceof SpecialSubscription)
63 continue; 69 continue;
64 70
71 if (subscription.url == Prefs.subscriptions_exceptionsurl)
72 {
73 hasAcceptable = true;
74 continue;
75 }
76
65 addSubscriptionEntry(subscription); 77 addSubscriptionEntry(subscription);
66 } 78 }
67 79
80 $("#acceptableAds").prop("checked", hasAcceptable);
81
68 // User-entered filters 82 // User-entered filters
69 showUserFilters(); 83 showUserFilters();
70 } 84 }
71 85
72 // Cleans up when the options window is closed 86 // Cleans up when the options window is closed
73 function unloadOptions() 87 function unloadOptions()
74 { 88 {
75 FilterNotifier.removeListener(onFilterChange); 89 FilterNotifier.removeListener(onFilterChange);
76 } 90 }
77 91
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 266
253 subscription.title = title; 267 subscription.title = title;
254 if (homepage) 268 if (homepage)
255 subscription.homepage = homepage; 269 subscription.homepage = homepage;
256 FilterStorage.addSubscription(subscription); 270 FilterStorage.addSubscription(subscription);
257 271
258 if (subscription instanceof DownloadableSubscription && !subscription.lastDown load) 272 if (subscription instanceof DownloadableSubscription && !subscription.lastDown load)
259 Synchronizer.execute(subscription); 273 Synchronizer.execute(subscription);
260 } 274 }
261 275
276 function allowAcceptableAds(event)
277 {
278 var subscription = Subscription.fromURL(Prefs.subscriptions_exceptionsurl);
279 if (!subscription)
280 return;
281
282 subscription.disabled = false;
283 subscription.title = "Allow non-intrusive advertising";
284 if ($("#acceptableAds").prop("checked"))
285 {
286 FilterStorage.addSubscription(subscription);
287 if (subscription instanceof DownloadableSubscription && !subscription.lastDo wnload)
288 Synchronizer.execute(subscription);
289 }
290 else
291 FilterStorage.removeSubscription(subscription);
292 }
293
262 function findSubscriptionElement(subscription) 294 function findSubscriptionElement(subscription)
263 { 295 {
264 var children = document.getElementById("filterLists").childNodes; 296 var children = document.getElementById("filterLists").childNodes;
265 for (var i = 0; i < children.length; i++) 297 for (var i = 0; i < children.length; i++)
266 if (children[i]._subscription == subscription) 298 if (children[i]._subscription == subscription)
267 return children[i]; 299 return children[i];
268 return null; 300 return null;
269 } 301 }
270 302
271 function updateSubscriptionInfo(element) 303 function updateSubscriptionInfo(element)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 case "subscription.disabled": 353 case "subscription.disabled":
322 case "subscription.homepage": 354 case "subscription.homepage":
323 case "subscription.lastDownload": 355 case "subscription.lastDownload":
324 case "subscription.downloadStatus": 356 case "subscription.downloadStatus":
325 var element = findSubscriptionElement(item); 357 var element = findSubscriptionElement(item);
326 if (element) 358 if (element)
327 updateSubscriptionInfo(element); 359 updateSubscriptionInfo(element);
328 break; 360 break;
329 case "subscription.added": 361 case "subscription.added":
330 if (!(item instanceof SpecialSubscription) && !findSubscriptionElement(ite m)) 362 if (!(item instanceof SpecialSubscription) && !findSubscriptionElement(ite m))
331 addSubscriptionEntry(item); 363 {
364 if (item.url == Prefs.subscriptions_exceptionsurl)
365 $("#acceptableAds").prop("checked", true);
366 else
367 addSubscriptionEntry(item);
368 }
332 break; 369 break;
333 case "subscription.removed": 370 case "subscription.removed":
334 var element = findSubscriptionElement(item); 371 if (item.url == Prefs.subscriptions_exceptionsurl)
335 if (element) 372 $("#acceptableAds").prop("checked", false);
336 element.parentNode.removeChild(element); 373 else
374 {
375 var element = findSubscriptionElement(item);
376 if (element)
377 element.parentNode.removeChild(element);
378 }
337 break; 379 break;
338 case "filter.added": 380 case "filter.added":
339 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes t(item.text)) 381 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes t(item.text))
340 appendToListBox("excludedDomainsBox", RegExp.$1); 382 appendToListBox("excludedDomainsBox", RegExp.$1);
341 else 383 else
342 appendToListBox("userFiltersBox", item.text); 384 appendToListBox("userFiltersBox", item.text);
343 break; 385 break;
344 case "filter.removed": 386 case "filter.removed":
345 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes t(item.text)) 387 if (item instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/.tes t(item.text))
346 removeFromListBox("excludedDomainsBox", RegExp.$1); 388 removeFromListBox("excludedDomainsBox", RegExp.$1);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 if (subscription.disabled == !enabled.checked) 579 if (subscription.disabled == !enabled.checked)
538 return; 580 return;
539 581
540 subscription.disabled = !enabled.checked; 582 subscription.disabled = !enabled.checked;
541 }, false); 583 }, false);
542 584
543 updateSubscriptionInfo(element); 585 updateSubscriptionInfo(element);
544 586
545 document.getElementById("filterLists").appendChild(element); 587 document.getElementById("filterLists").appendChild(element);
546 } 588 }
OLDNEW
« no previous file with comments | « options.html ('k') | update_locales.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld