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. 16, 2012, 2:16 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') | update_locales.py » ('J')
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,78 @@
};
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/17 10:17:14 What happens if the file doesn't exist? Won't this
Felix Dahlke 2012/10/18 08:08:46 Yes, you're right. Done.
+ 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);
+ for (var i in messages)
+ i18nMessages[i] = messages[i];
+}
+
+function loadI18nMessages()
Wladimir Palant 2012/10/17 10:17:14 From the look of it, this function will never load
Felix Dahlke 2012/10/18 08:08:46 It does, that's the locale I use.
+{
+ i18nMessages = {};
+
+ var baseLocale = "en";
Wladimir Palant 2012/10/17 10:17:14 Is there an easy way to get the default locale fro
Felix Dahlke 2012/10/18 08:08:46 Oh, didn't notice it was specified there. I have j
+ var language = locale.split("-")[0];
Wladimir Palant 2012/10/17 10:17:14 locale is undefined?
Felix Dahlke 2012/10/18 08:08:46 No, it's a global. It's defined in a locale-specif
+
+ if (baseLocale !== language)
+ loadMessagesForLocale(baseLocale);
+
+ if (locale !== language)
Wladimir Palant 2012/10/17 10:17:14 What's the point of this check? Shouldn't we alway
Felix Dahlke 2012/10/18 08:08:46 "language" is just the language part, without the
+ loadMessagesForLocale(language);
+
+ loadMessagesForLocale();
Wladimir Palant 2012/10/17 10:17:14 Locale-independent messages.json? Sounds pointless
Felix Dahlke 2012/10/18 08:08:46 messages.json exists once for each locale and is l
+}
+
+setDefaultOptions();
+createToolbarButton();
+refreshToolbarButton();
+loadI18nMessages();
« no previous file with comments | « no previous file | button.js » ('j') | update_locales.py » ('J')

Powered by Google App Engine
This is Rietveld