| Index: options.js |
| =================================================================== |
| --- a/options.js |
| +++ b/options.js |
| @@ -1,9 +1,21 @@ |
| var backgroundPage = opera.extension.bgProcess; |
| -var imports = ["FilterStorage", "FilterNotifier", "Subscription", "SpecialSubscription", |
| - "DownloadableSubscription", "Filter", "WhitelistFilter", |
| - "Synchronizer", "Prefs", "Utils", "require"]; |
| -for (var i = 0; i < imports.length; i++) |
| - window[imports[i]] = backgroundPage[imports[i]]; |
| +var require = backgroundPage.require; |
| + |
| +with(require("filterClasses")) |
| +{ |
| + this.Filter = Filter; |
| + this.WhitelistFilter = WhitelistFilter; |
| +} |
| +with(require("subscriptionClasses")) |
| +{ |
| + this.Subscription = Subscription; |
| + this.SpecialSubscription = SpecialSubscription; |
| + this.DownloadableSubscription = DownloadableSubscription; |
| +} |
| +var FilterStorage = require("filterStorage").FilterStorage; |
| +var FilterNotifier = require("filterNotifier").FilterNotifier; |
| +var Prefs = require("prefs").Prefs; |
| +var Synchronizer = require("synchronizer").Synchronizer; |
| // Loads options from localStorage and sets UI elements accordingly |
| function loadOptions() |
| @@ -13,7 +25,7 @@ |
| // Set links |
| $("#acceptableAdsLink").attr("href", Prefs.subscriptions_exceptionsurl); |
| - $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/g, "acceptable_ads").replace(/%LANG%/g, Utils.appLocale)); |
| + $("#acceptableAdsDocs").attr("href", Prefs.documentation_link.replace(/%LINK%/g, "acceptable_ads").replace(/%LANG%/g, require("utils").Utils.appLocale)); |
| // Add event listeners |
| window.addEventListener("unload", unloadOptions, false); |
| @@ -136,7 +148,7 @@ |
| for (var i = 0; i < elements.length; i++) |
| { |
| var element = elements[i]; |
| - var option = document.createElement("option"); |
| + var option = new Option(); |
| option.text = element.getAttribute("title") + " (" + element.getAttribute("specialization") + ")"; |
| option._data = { |
| title: element.getAttribute("title"), |
| @@ -174,7 +186,7 @@ |
| list.appendChild(option); |
| } |
| - var option = document.createElement("option"); |
| + var option = new Option(); |
| option.text = i18n.getMessage("filters_addSubscriptionOther_label") + "\u2026"; |
| option._data = null; |
| list.appendChild(option); |
| @@ -355,16 +367,23 @@ |
| updateSubscriptionInfo(element); |
| break; |
| case "subscription.added": |
| - if (!(item instanceof SpecialSubscription) && !findSubscriptionElement(item)) |
| + if (item instanceof SpecialSubscription) |
| { |
| - if (item.url == Prefs.subscriptions_exceptionsurl) |
| - $("#acceptableAds").prop("checked", true); |
| - else |
| - addSubscriptionEntry(item); |
| + for (var i = 0; i < item.filters.length; i++) |
| + onFilterChange("filter.added", item.filters[i]); |
| } |
| + else if (item.url == Prefs.subscriptions_exceptionsurl) |
| + $("#acceptableAds").prop("checked", true); |
| + else if (!findSubscriptionElement(item)) |
| + addSubscriptionEntry(item); |
| break; |
| case "subscription.removed": |
| - if (item.url == Prefs.subscriptions_exceptionsurl) |
| + if (item instanceof SpecialSubscription) |
| + { |
| + for (var i = 0; i < item.filters.length; i++) |
| + onFilterChange("filter.removed", item.filters[i]); |
| + } |
| + else if (item.url == Prefs.subscriptions_exceptionsurl) |
| $("#acceptableAds").prop("checked", false); |
| else |
| { |
| @@ -398,7 +417,7 @@ |
| entries.sort(); |
| for (var i = 0; i < entries.length; i++) |
| { |
| - var option = document.createElement("option"); |
| + var option = new Option(); |
| option.text = entries[i]; |
| option.value = entries[i]; |
| list.appendChild(option); |
| @@ -408,7 +427,7 @@ |
| // Add a filter string to the list box. |
| function appendToListBox(boxId, text) |
| { |
| - var elt = document.createElement("option"); |
| + var elt = new Option(); /* Note: document.createElement("option") is unreliable in Opera */ |
| elt.text = text; |
| elt.value = text; |
| document.getElementById(boxId).appendChild(elt); |
| @@ -417,9 +436,6 @@ |
| // Remove a filter string from a list box. |
| function removeFromListBox(boxId, text) |
| { |
| - var elt = document.createElement("option"); |
| - elt.text = text; |
| - elt.value = text; |
| var list = document.getElementById(boxId); |
| for (var i = 0; i < list.length; i++) |
| if (list.options[i].value == text) |