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

Unified Diff: background.js

Issue 8560083: adblockplusopera: Port UI code from Chrome (Closed)
Patch Set: Created Oct. 18, 2012, 1:26 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | button.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -1,8 +1,12 @@
+var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscription;
+var WhitelistFilter = require("filterClasses").WhitelistFilter;
var FilterNotifier = require("filterNotifier").FilterNotifier;
var FilterStorage = require("filterStorage").FilterStorage;
+var Prefs = require("prefs").Prefs;
var Synchronizer = require("synchronizer").Synchronizer;
var Subscription = require("subscriptionClasses").Subscription;
-var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscription;
+var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
+var Utils = require("utils").Utils;
var isFirstRun = false;
FilterNotifier.addListener(function(action)
@@ -19,6 +23,9 @@
}
});
+var toolbarButton;
+var i18nMessages;
+
function importOldData()
{
// TODO: Remove this once most people have the update
@@ -144,3 +151,82 @@
};
request.send(null);
}
+
+function setDefaultOptions()
+{
+ function defaultOptionValue(opt, val)
+ {
+ if(!(opt in localStorage))
+ localStorage[opt] = val;
+ }
+
+ defaultOptionValue("shouldShowIcon", "true");
+}
+
+function createToolbarButton()
+{
+ var properties = {
+ disabled: false,
+ title: "Adblock Plus",
+ icon: "icons/abp-18.png"
+ };
+
+ toolbarButton = opera.contexts.toolbar.createItem(properties);
+}
+
+function refreshToolbarButton()
+{
+ var toolbar = opera.contexts.toolbar;
+ if (localStorage["shouldShowIcon"] === "true")
+ toolbar.addItem(toolbarButton);
+ else
+ toolbar.removeItem(toolbarButton);
+}
+
+function getJson(url)
+{
+ var request = new XMLHttpRequest();
+ request.open("GET", url, false);
+ request.responseType = "json";
+ request.send();
Wladimir Palant 2012/10/19 15:47:41 There is still a potential unhandled exception her
Felix Dahlke 2012/10/19 16:07:27 Yes, it will return an undefined value. My first a
Wladimir Palant 2012/10/22 08:57:51 Ok, it seems that the widget:// protocol behaves d
+ return request.response;
+}
+
+function loadMessagesForLocale(locale)
+{
+ var messagesFileName = "messages.json";
+ var messagesPath;
+ if (locale)
+ messagesPath = "locales/" + locale + "/" + messagesFileName;
+ else
+ messagesPath = messagesFileName;
+
+ var messages = getJson(messagesPath);
+ if (!messages)
+ {
+ console.error("Failed to load messages for locale "
+ + (locale ? locale : "default"));
+ return;
+ }
+
+ for (var i in messages)
+ i18nMessages[i] = messages[i];
+}
+
+function loadI18nMessages()
+{
+ i18nMessages = {};
+
+ // Could be parsed from config.xml
+ var defaultLocale = "en";
+
+ if (locale !== defaultLocale)
Wladimir Palant 2012/10/19 15:47:41 I'm not really happy with the hack you use to defi
Felix Dahlke 2012/10/19 16:07:27 Done. It's not necessary anymore and I'm frankly h
+ loadMessagesForLocale(defaultLocale);
+
+ loadMessagesForLocale();
+}
+
+setDefaultOptions();
+createToolbarButton();
+refreshToolbarButton();
+loadI18nMessages();
« no previous file with comments | « no previous file | button.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld