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

Delta Between Two Patch Sets: options.js

Issue 29339314: Issue 3870 - Rewrite legacy options page to use async messages (Closed)
Left Patch Set: Addressed initial feedback Created April 3, 2016, 3:48 p.m.
Right Patch Set: Avoid another race condition Created April 7, 2016, 1:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/notificationHelper.js ('k') | safari/ext/background.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 var getPref = wrapper({type: "prefs.get"}, "key"); 65 var getPref = wrapper({type: "prefs.get"}, "key");
66 var togglePref = wrapper({type: "prefs.toggle"}, "key"); 66 var togglePref = wrapper({type: "prefs.toggle"}, "key");
67 var getSubscriptions = wrapper({type: "subscriptions.get"}, 67 var getSubscriptions = wrapper({type: "subscriptions.get"},
68 "downloadable", "special"); 68 "downloadable", "special");
69 var removeSubscription = wrapper({type: "subscriptions.remove"}, "url"); 69 var removeSubscription = wrapper({type: "subscriptions.remove"}, "url");
70 var addSubscription = wrapper({type: "subscriptions.add"}, 70 var addSubscription = wrapper({type: "subscriptions.add"},
71 "url", "title", "homepage"); 71 "url", "title", "homepage");
72 var toggleSubscription = wrapper({type: "subscriptions.toggle"}, 72 var toggleSubscription = wrapper({type: "subscriptions.toggle"},
73 "url", "keepInstalled"); 73 "url", "keepInstalled");
74 var updateSubscription = wrapper({type: "subscriptions.update"}, "url"); 74 var updateSubscription = wrapper({type: "subscriptions.update"}, "url");
75 var isSubscriptionDownloading = wrapper({type: "subscriptions.isDownloading"}, 75 var importRawFilters = wrapper({type: "filters.importRaw"},
76 "url"); 76 "text", "removeExisting");
77 var importRawFilters = wrapper({type: "filters.importRaw"}, "text");
78 var addFilter = wrapper({type: "filters.add"}, "text"); 77 var addFilter = wrapper({type: "filters.add"}, "text");
79 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl");
80 var removeFilter = wrapper({type: "filters.remove"}, "text"); 79 var removeFilter = wrapper({type: "filters.remove"}, "text");
81 80
82 var i18n = ext.i18n; 81 var i18n = ext.i18n;
83 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/;
84 var delayedSubscriptionSelection = null; 83 var delayedSubscriptionSelection = null;
85 84
85 var acceptableAdsUrl;
86
86 // Loads options and sets UI elements accordingly 87 // Loads options and sets UI elements accordingly
87 function loadOptions() 88 function loadOptions()
88 { 89 {
89 // Set page title to i18n version of "Adblock Plus Options" 90 // Set page title to i18n version of "Adblock Plus Options"
90 document.title = i18n.getMessage("options"); 91 document.title = i18n.getMessage("options");
91 92
92 // Set links 93 // Set links
93 getPref("subscriptions_exceptionsurl", function (url) 94 getPref("subscriptions_exceptionsurl", function(url)
94 { 95 {
95 $("#acceptableAdsLink").attr("href", url); 96 acceptableAdsUrl = url;
96 }); 97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl);
97 getDocLink("acceptable_ads", function (url) 98 });
99 getDocLink("acceptable_ads", function(url)
98 { 100 {
99 $("#acceptableAdsDocs").attr("href", url); 101 $("#acceptableAdsDocs").attr("href", url);
100 }); 102 });
101 getDocLink("filterdoc", function (url) 103 getDocLink("filterdoc", function(url)
102 { 104 {
103 setLinks("filter-must-follow-syntax", url); 105 setLinks("filter-must-follow-syntax", url);
104 }); 106 });
105 getInfo("application", function (application) 107 getInfo("application", function(application)
106 { 108 {
107 getInfo("platform", function (platform) 109 getInfo("platform", function(platform)
108 { 110 {
109 if (platform == "chromium" && application != "opera") 111 if (platform == "chromium" && application != "opera")
110 application = "chrome"; 112 application = "chrome";
111 113
112 getDocLink(application + "_support", function (url) 114 getDocLink(application + "_support", function(url)
113 { 115 {
114 setLinks("found-a-bug", url); 116 setLinks("found-a-bug", url);
115 }); 117 });
116 }); 118 });
117 }); 119 });
118 120
119 // Add event listeners 121 // Add event listeners
120 $("#updateFilterLists").click(updateFilterLists); 122 $("#updateFilterLists").click(updateFilterLists);
121 $("#startSubscriptionSelection").click(startSubscriptionSelection); 123 $("#startSubscriptionSelection").click(startSubscriptionSelection);
122 $("#subscriptionSelector").change(updateSubscriptionSelection); 124 $("#subscriptionSelector").change(updateSubscriptionSelection);
(...skipping 22 matching lines...) Expand all
145 { 147 {
146 return ignoredcategories.indexOf("*") == -1; 148 return ignoredcategories.indexOf("*") == -1;
147 } 149 }
148 }); 150 });
149 151
150 getInfo("features", function(features) 152 getInfo("features", function(features)
151 { 153 {
152 if (!features.devToolsPanel) 154 if (!features.devToolsPanel)
153 document.getElementById("showDevtoolsPanelContainer").hidden = true; 155 document.getElementById("showDevtoolsPanelContainer").hidden = true;
154 }); 156 });
155 getPref("notifications_showui", function (notifications_showui) 157 getPref("notifications_showui", function(notifications_showui)
156 { 158 {
157 if (!notifications_showui) 159 if (!notifications_showui)
158 document.getElementById("shouldShowNotificationsContainer").hidden = true; 160 document.getElementById("shouldShowNotificationsContainer").hidden = true;
159 }); 161 });
160 162
161 // Register listeners in the background message responder 163 // Register listeners in the background message responder
162 ext.backgroundPage.sendMessage({ 164 ext.backgroundPage.sendMessage({
163 type: "app.listen", 165 type: "app.listen",
164 filter: ["addSubscription", "switchToOptionsSection"] 166 filter: ["addSubscription", "focusSection"]
165 }); 167 });
166 ext.backgroundPage.sendMessage( 168 ext.backgroundPage.sendMessage(
167 { 169 {
168 type: "filters.listen", 170 type: "filters.listen",
169 filter: ["added", "loaded", "removed"] 171 filter: ["added", "loaded", "removed"]
170 }); 172 });
171 ext.backgroundPage.sendMessage( 173 ext.backgroundPage.sendMessage(
172 { 174 {
173 type: "prefs.listen", 175 type: "prefs.listen",
174 filter: ["notifications_ignoredcategories", "notifications_showui", 176 filter: ["notifications_ignoredcategories", "notifications_showui",
175 "safari_contentblocker", "show_devtools_panel", 177 "safari_contentblocker", "show_devtools_panel",
176 "shouldShowBlockElementMenu"] 178 "shouldShowBlockElementMenu"]
177 }); 179 });
178 ext.backgroundPage.sendMessage( 180 ext.backgroundPage.sendMessage(
179 { 181 {
180 type: "subscriptions.listen", 182 type: "subscriptions.listen",
181 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 183 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
182 "title"] 184 "title", "downloadStatus", "downloading"]
183 }); 185 });
184 186
185 // Load recommended subscriptions 187 // Load recommended subscriptions
186 loadRecommendations(); 188 loadRecommendations();
187 189
188 // Show user's filters 190 // Show user's filters
189 reloadFilters(); 191 reloadFilters();
190 } 192 }
191 $(loadOptions); 193 $(loadOptions);
192 194
193 // Reloads the displayed subscriptions and filters 195 // Reloads the displayed subscriptions and filters
194 function reloadFilters() 196 function reloadFilters()
195 { 197 {
196 // Load user filter URLs 198 // Load user filter URLs
197 var container = document.getElementById("filterLists"); 199 var container = document.getElementById("filterLists");
198 while (container.lastChild) 200 while (container.lastChild)
199 container.removeChild(container.lastChild); 201 container.removeChild(container.lastChild);
200 202
201 getPref("subscriptions_exceptionsurl", function (acceptableAdsUrl) 203 getSubscriptions(true, false, function(subscriptions)
202 { 204 {
203 getSubscriptions(true, false, function(subscriptions) 205 for (var i = 0; i < subscriptions.length; i++)
204 { 206 {
205 for (var i = 0; i < subscriptions.length; i++) 207 var subscription = subscriptions[i];
206 { 208 if (subscription.url == acceptableAdsUrl)
207 var subscription = subscriptions[i]; 209 $("#acceptableAds").prop("checked", !subscription.disabled);
208 if (subscription.url == acceptableAdsUrl) 210 else
209 $("#acceptableAds").prop("checked", !subscription.disabled); 211 addSubscriptionEntry(subscription);
210 else 212 }
211 addSubscriptionEntry(subscription);
212 }
213 });
214 }); 213 });
215 214
216 // User-entered filters 215 // User-entered filters
217 getSubscriptions(false, true, function(subscriptions) 216 getSubscriptions(false, true, function(subscriptions)
218 { 217 {
219 clearListBox("userFiltersBox"); 218 clearListBox("userFiltersBox");
220 clearListBox("excludedDomainsBox"); 219 clearListBox("excludedDomainsBox");
221 220
222 for (var i = 0; i < subscriptions.length; i++) 221 for (var i = 0; i < subscriptions.length; i++)
223 getFilters(subscriptions[i].url, function(filters) 222 getFilters(subscriptions[i].url, function(filters)
224 { 223 {
225 for (var j = 0; j < filters.length; j++) 224 for (var j = 0; j < filters.length; j++)
226 { 225 {
227 var filter = filters[j].text; 226 var filter = filters[j].text;
228 if (whitelistedDomainRegexp.test(filter)) 227 if (whitelistedDomainRegexp.test(filter))
229 appendToListBox("excludedDomainsBox", RegExp.$1); 228 appendToListBox("excludedDomainsBox", RegExp.$1);
230 else 229 else
231 appendToListBox("userFiltersBox", filter); 230 appendToListBox("userFiltersBox", filter);
232 } 231 }
233 }); 232 });
234 }); 233 });
235 } 234 }
236 235
237 function initCheckbox(id, descriptor) 236 function initCheckbox(id, descriptor)
238 { 237 {
239 var checkbox = document.getElementById(id); 238 var checkbox = document.getElementById(id);
240 var key = descriptor && descriptor.key || id; 239 var key = descriptor && descriptor.key || id;
241 getPref(key, function (value) 240 getPref(key, function(value)
242 { 241 {
243 if (descriptor && descriptor.get) 242 if (descriptor && descriptor.get)
244 checkbox.checked = descriptor.get(value); 243 checkbox.checked = descriptor.get(value);
245 else 244 else
246 checkbox.checked = value; 245 checkbox.checked = value;
247 }); 246 });
248 247
249 checkbox.addEventListener("click", function() 248 checkbox.addEventListener("click", function()
250 { 249 {
251 if (descriptor && descriptor.toggle) 250 if (descriptor && descriptor.toggle)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 addSubscription(url, title, null); 385 addSubscription(url, title, null);
387 } 386 }
388 387
389 $("#addSubscriptionContainer").hide(); 388 $("#addSubscriptionContainer").hide();
390 $("#customSubscriptionContainer").hide(); 389 $("#customSubscriptionContainer").hide();
391 $("#addSubscriptionButton").show(); 390 $("#addSubscriptionButton").show();
392 } 391 }
393 392
394 function toggleAcceptableAds() 393 function toggleAcceptableAds()
395 { 394 {
396 getPref("subscriptions_exceptionsurl", function (url) 395 toggleSubscription(acceptableAdsUrl, true);
397 {
398 toggleSubscription(url, true);
399 });
400 } 396 }
401 397
402 function findSubscriptionElement(subscription) 398 function findSubscriptionElement(subscription)
403 { 399 {
404 var children = document.getElementById("filterLists").childNodes; 400 var children = document.getElementById("filterLists").childNodes;
405 for (var i = 0; i < children.length; i++) 401 for (var i = 0; i < children.length; i++)
406 if (children[i]._subscription.url == subscription.url) 402 if (children[i]._subscription.url == subscription.url)
407 return children[i]; 403 return children[i];
408 return null; 404 return null;
409 } 405 }
(...skipping 12 matching lines...) Expand all
422 title.href = subscription.homepage; 418 title.href = subscription.homepage;
423 else 419 else
424 title.href = subscription.url; 420 title.href = subscription.url;
425 421
426 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 422 var enabled = element.getElementsByClassName("subscriptionEnabled")[0];
427 enabled.checked = !subscription.disabled; 423 enabled.checked = !subscription.disabled;
428 424
429 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0]; 425 var lastUpdate = element.getElementsByClassName("subscriptionUpdate")[0];
430 lastUpdate.classList.remove("error"); 426 lastUpdate.classList.remove("error");
431 427
432 if (subscription.downloadStatus && 428 var downloadStatus = subscription.downloadStatus;
433 subscription.downloadStatus != "synchronize_ok") 429 if (subscription.isDownloading)
430 {
431 lastUpdate.textContent = i18n.getMessage("filters_subscription_lastDownload_ inProgress");
432 }
433 else if (downloadStatus && downloadStatus != "synchronize_ok")
434 { 434 {
435 var map = 435 var map =
436 { 436 {
437 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" , 437 "synchronize_invalid_url": "filters_subscription_lastDownload_invalidURL" ,
438 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError", 438 "synchronize_connection_error": "filters_subscription_lastDownload_connec tionError",
439 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a", 439 "synchronize_invalid_data": "filters_subscription_lastDownload_invalidDat a",
440 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch" 440 "synchronize_checksum_mismatch": "filters_subscription_lastDownload_check sumMismatch"
441 }; 441 };
442 if (subscription.downloadStatus in map) 442 if (downloadStatus in map)
443 lastUpdate.textContent = i18n.getMessage(map[subscription.downloadStatus] ); 443 lastUpdate.textContent = i18n.getMessage(map[downloadStatus]);
444 else 444 else
445 lastUpdate.textContent = subscription.downloadStatus; 445 lastUpdate.textContent = downloadStatus;
446 lastUpdate.classList.add("error"); 446 lastUpdate.classList.add("error");
447 } 447 }
448 else if (subscription.lastDownload > 0) 448 else if (subscription.lastDownload > 0)
449 { 449 {
450 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000); 450 var timeDate = i18n_timeDateStrings(subscription.lastDownload * 1000);
451 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today"); 451 var messageID = (timeDate[1] ? "last_updated_at" : "last_updated_at_today");
452 lastUpdate.textContent = i18n.getMessage(messageID, timeDate); 452 lastUpdate.textContent = i18n.getMessage(messageID, timeDate);
453 } 453 }
454 } 454 }
455 455
456 function onSubscriptionMessage(action, subscription) 456 function onSubscriptionMessage(action, subscription)
457 { 457 {
458 var element = findSubscriptionElement(subscription);
459
458 switch (action) 460 switch (action)
459 { 461 {
460 case "title":
461 case "disabled": 462 case "disabled":
463 case "downloading":
464 case "downloadStatus":
462 case "homepage": 465 case "homepage":
463 case "lastDownload": 466 case "lastDownload":
464 case "downloadStatus": 467 case "title":
465 var element = findSubscriptionElement(subscription);
466 if (element) 468 if (element)
467 updateSubscriptionInfo(element, subscription); 469 updateSubscriptionInfo(element, subscription);
468 break; 470 break;
469 case "added": 471 case "added":
470 getPref("subscriptions_exceptionsurl", function (acceptableAdsUrl) 472 if (subscription.url == acceptableAdsUrl)
471 { 473 $("#acceptableAds").prop("checked", true);
472 if (subscription.url == acceptableAdsUrl) 474 else if (!element)
473 $("#acceptableAds").prop("checked", true); 475 addSubscriptionEntry(subscription);
474 else if (!findSubscriptionElement(subscription))
475 addSubscriptionEntry(subscription);
476 });
477 break; 476 break;
478 case "removed": 477 case "removed":
479 getPref("subscriptions_exceptionsurl", function (acceptableAdsUrl) 478 if (subscription.url == acceptableAdsUrl)
480 { 479 $("#acceptableAds").prop("checked", false);
481 if (subscription.url == acceptableAdsUrl) 480 else if (element)
482 { 481 element.parentNode.removeChild(element);
483 $("#acceptableAds").prop("checked", false);
484 }
485 else
486 {
487 var element = findSubscriptionElement(subscription);
488 if (element)
489 element.parentNode.removeChild(element);
490 }
491 });
492 break; 482 break;
493 } 483 }
494 } 484 }
495 485
496 function onPrefMessage(key, value) 486 function onPrefMessage(key, value)
497 { 487 {
498 switch (key) 488 switch (key)
499 { 489 {
500 case "notifications_showui": 490 case "notifications_showui":
501 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; 491 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 var filterText = "@@||" + domain + "^$document"; 561 var filterText = "@@||" + domain + "^$document";
572 addFilter(filterText); 562 addFilter(filterText);
573 } 563 }
574 564
575 // Adds filter text that user typed to the selection box 565 // Adds filter text that user typed to the selection box
576 function addTypedFilter(event) 566 function addTypedFilter(event)
577 { 567 {
578 event.preventDefault(); 568 event.preventDefault();
579 569
580 var element = document.getElementById("newFilter"); 570 var element = document.getElementById("newFilter");
581 addFilter(element.value, function (errors) 571 addFilter(element.value, function(errors)
582 { 572 {
583 if (errors.length > 0) 573 if (errors.length > 0)
584 alert(errors.join("\n")); 574 alert(errors.join("\n"));
585 else 575 else
586 element.value = ""; 576 element.value = "";
587 }); 577 });
588 } 578 }
589 579
590 // Removes currently selected whitelisted domains 580 // Removes currently selected whitelisted domains
591 function removeSelectedExcludedDomain(event) 581 function removeSelectedExcludedDomain(event)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 text += userFiltersBox.options[i].value + "\n"; 623 text += userFiltersBox.options[i].value + "\n";
634 document.getElementById("rawFiltersText").value = text; 624 document.getElementById("rawFiltersText").value = text;
635 } 625 }
636 } 626 }
637 627
638 // Imports filters in the raw text box 628 // Imports filters in the raw text box
639 function importRawFiltersText() 629 function importRawFiltersText()
640 { 630 {
641 var text = document.getElementById("rawFiltersText").value; 631 var text = document.getElementById("rawFiltersText").value;
642 632
643 importRawFilters(text, function (errors) 633 importRawFilters(text, true, function(errors)
644 { 634 {
645 if (errors.length > 0) 635 if (errors.length > 0)
646 alert(errors.join("\n")); 636 alert(errors.join("\n"));
647 else 637 else
648 $("#rawFilters").hide(); 638 $("#rawFilters").hide();
649 }); 639 });
650 } 640 }
651 641
652 // Called when user explicitly requests filter list updates 642 // Called when user explicitly requests filter list updates
653 function updateFilterLists() 643 function updateFilterLists()
654 { 644 {
655 // Without the URL parameter this will update all subscriptions 645 // Without the URL parameter this will update all subscriptions
656 updateSubscription(); 646 updateSubscription();
657
658 // Display a message for any subscriptions that are currently being downloaded
659 getSubscriptions(true, false, function(subscriptions)
660 {
661 var inProgressMessage = i18n.getMessage(
662 "filters_subscription_lastDownload_inProgress"
663 );
664
665 for (var i = 0; i < subscriptions.length; i += 1)
666 {
667 var element = findSubscriptionElement(subscriptions[i]);
668 if (element)
669 {
670 var label = element.getElementsByClassName("subscriptionUpdate")[0];
671 isSubscriptionDownloading(subscriptions[i].url, function(isDownloading)
672 {
673 if (isDownloading)
674 label.textContent = inProgressMessage;
675 });
676 }
677 }
678 });
679 } 647 }
680 648
681 // Adds a subscription entry to the UI. 649 // Adds a subscription entry to the UI.
682 function addSubscriptionEntry(subscription) 650 function addSubscriptionEntry(subscription)
683 { 651 {
684 var template = document.getElementById("subscriptionTemplate"); 652 var template = document.getElementById("subscriptionTemplate");
685 var element = template.cloneNode(true); 653 var element = template.cloneNode(true);
686 element.removeAttribute("id"); 654 element.removeAttribute("id");
687 element._subscription = subscription; 655 element._subscription = subscription;
688 656
689 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0]; 657 var removeButton = element.getElementsByClassName("subscriptionRemoveButton")[ 0];
690 removeButton.setAttribute("title", removeButton.textContent); 658 removeButton.setAttribute("title", removeButton.textContent);
691 removeButton.textContent = "\xD7"; 659 removeButton.textContent = "\xD7";
692 removeButton.addEventListener("click", function() 660 removeButton.addEventListener("click", function()
693 { 661 {
694 if (!confirm(i18n.getMessage("global_remove_subscription_warning"))) 662 if (!confirm(i18n.getMessage("global_remove_subscription_warning")))
695 return; 663 return;
696 664
697 removeSubscription(subscription.url); 665 removeSubscription(subscription.url);
698 }, false); 666 }, false);
699 667
700 getPref("additional_subscriptions", function (additionalSubscriptions) 668 getPref("additional_subscriptions", function(additionalSubscriptions)
701 { 669 {
702 if (additionalSubscriptions.indexOf(subscription.url) != -1) 670 if (additionalSubscriptions.indexOf(subscription.url) != -1)
703 removeButton.style.visibility = "hidden"; 671 removeButton.style.visibility = "hidden";
704 }); 672 });
705 673
706 var enabled = element.getElementsByClassName("subscriptionEnabled")[0]; 674 var enabled = element.getElementsByClassName("subscriptionEnabled")[0];
707 enabled.addEventListener("click", function() 675 enabled.addEventListener("click", function()
708 { 676 {
709 subscription.disabled = !subscription.disabled; 677 subscription.disabled = !subscription.disabled;
710 toggleSubscription(subscription.url, true); 678 toggleSubscription(subscription.url, true);
(...skipping 30 matching lines...) Expand all
741 { 709 {
742 switch (message.type) 710 switch (message.type)
743 { 711 {
744 case "app.respond": 712 case "app.respond":
745 switch (message.action) 713 switch (message.action)
746 { 714 {
747 case "addSubscription": 715 case "addSubscription":
748 var subscription = message.args[0]; 716 var subscription = message.args[0];
749 startSubscriptionSelection(subscription.title, subscription.url); 717 startSubscriptionSelection(subscription.title, subscription.url);
750 break; 718 break;
751 case "switchToOptionsSection": 719 case "focusSection":
752 var tabs = document.getElementsByClassName("ui-tabs-panel"); 720 var tabs = document.getElementsByClassName("ui-tabs-panel");
753 for (var i = 0; i < tabs.length; i++) 721 for (var i = 0; i < tabs.length; i++)
754 { 722 {
755 var found = tabs[i].querySelector( 723 var found = tabs[i].querySelector(
756 "[data-section='" + message.section + "']" 724 "[data-section='" + message.args[0] + "']"
757 ); 725 );
758 if (!found) 726 if (!found)
759 continue; 727 continue;
760 728
761 var previous = document.getElementsByClassName("focused"); 729 var previous = document.getElementsByClassName("focused");
762 if (previous.length > 0) 730 if (previous.length > 0)
763 previous[0].classList.remove("focused"); 731 previous[0].classList.remove("focused");
764 732
765 var tab = $("[href='#" + tabs[i].id + "']"); 733 var tab = $("[href='#" + tabs[i].id + "']");
766 $("#tabs").tabs("select", tab.parent().index()); 734 $("#tabs").tabs("select", tab.parent().index());
767 found.classList.add("focused"); 735 found.classList.add("focused");
768 } 736 }
769 break; 737 break;
770 } 738 }
771 break; 739 break;
772 case "filters.respond": 740 case "filters.respond":
773 onFilterMessage(message.action, message.args[0]); 741 onFilterMessage(message.action, message.args[0]);
774 break; 742 break;
775 case "prefs.respond": 743 case "prefs.respond":
776 onPrefMessage(message.action, message.args[0]); 744 onPrefMessage(message.action, message.args[0]);
777 break; 745 break;
778 case "subscriptions.respond": 746 case "subscriptions.respond":
779 onSubscriptionMessage(message.action, message.args[0]); 747 onSubscriptionMessage(message.action, message.args[0]);
780 break; 748 break;
781 } 749 }
782 }); 750 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld