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

Unified Diff: chrome/content/ui/typo.js

Issue 8559070: Integrated URL Fixer into Adblock Plus (Closed)
Patch Set: Created Oct. 12, 2012, 2:18 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 | « chrome/content/ui/filters.xul ('k') | chrome/locale/en-US/filters.dtd » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/ui/typo.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/chrome/content/ui/typo.js
@@ -0,0 +1,78 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+let {Prefs} = require("prefs");
+
+let TypoActions =
+{
+ onPrefChange: function(name)
+ {
+ if (name == "whitelist")
+ TypoActions.updateList();
+ },
+
+ onItemSelected: function(list)
+ {
+ let button = E(list.getAttribute("_removeButton"));
+ let items = list.selectedItems;
+ button.disabled = (items.length == 0 || (items.length == 1 && !items[0].value));
+ },
+
+ removeRule: function(btn, pref)
+ {
+ let list = E(btn.getAttribute("_list"));
+ let items = list.selectedItems;
+
+ let {onWhitelistEntryRemoved} = require("typoRules");
+
+ for (let i = items.length - 1; i >= 0; i--)
+ {
+ let searchString = items[i].getAttribute("value");
+ delete Prefs[pref][searchString];
+
+ if (pref == "whitelist")
+ onWhitelistEntryRemoved(searchString);
+ }
+ Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref]));
+ },
+
+ updateList: function()
+ {
+ let whitelistElement = E("typo_whitelist");
+
+ // Remove existing list entries
+ for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
+ whitelistElement.removeItemAt(i);
+
+ // Build a list of exceptions and sort it alphabetically
+ let whitelist = Object.keys(Prefs.whitelist);
+ whitelist.sort();
+
+ // Add the rules to the list
+ if (whitelist.length > 0)
+ {
+ for (let i = 0; i < whitelist.length; i++)
+ {
+ let option = document.createElement("listitem");
+ option.setAttribute("value", whitelist[i]);
+ option.setAttribute("label", whitelist[i]);
+
+ whitelistElement.appendChild(option);
+ }
+ }
+ else
+ {
+ let option = document.createElement("listitem");
+ option.setAttribute("class", "auto-entry");
+ option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel"));
+
+ whitelistElement.appendChild(option);
+ }
+ }
+};
+
+Prefs.addListener(TypoActions.onPrefChange);
+window.addEventListener("unload", function() Prefs.removeListener(TypoActions.onPrefChange), false);
« no previous file with comments | « chrome/content/ui/filters.xul ('k') | chrome/locale/en-US/filters.dtd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld