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

Side by Side Diff: chrome/content/ui/typoSettings.js

Issue 8559070: Integrated URL Fixer into Adblock Plus (Closed)
Patch Set: First batch of changes Created Nov. 9, 2012, 1:04 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 let {Prefs} = require("prefs");
8
9 let TypoActions =
10 {
11 init: function()
12 {
13 TypoActions.updateState();
14 TypoActions.updateList();
15
16 Prefs.addListener(TypoActions.onPrefChange);
17 window.addEventListener("unload", function() Prefs.removeListener(TypoAction s.onPrefChange), false);
18 },
19
20 onPrefChange: function(name)
21 {
22 if (name == "whitelist")
23 TypoActions.updateList();
24 else if (name == "correctTypos")
25 TypoActions.updateState();
26 else if (name == "whitelist")
27 TypoActions.updateList();
Wladimir Palant 2012/11/09 13:20:51 Are you making extra sure to handle the whitelist
28 },
29
30 setEnabled: function(checked)
31 {
32 Prefs.correctTypos = checked;
33 },
34
35 onItemSelected: function(list)
36 {
37 let button = E(list.getAttribute("_removeButton"));
38 let items = list.selectedItems;
39 button.disabled = (items.length == 0 || (items.length == 1 && !items[0].valu e));
40 },
41
42 removeRule: function(btn, pref)
43 {
44 let list = E(btn.getAttribute("_list"));
45 let items = list.selectedItems;
46
47 let {onWhitelistEntryRemoved} = require("typoRules");
48
49 for (let i = items.length - 1; i >= 0; i--)
50 {
51 let searchString = items[i].getAttribute("value");
52 delete Prefs[pref][searchString];
53
54 if (pref == "whitelist")
55 onWhitelistEntryRemoved(searchString);
56 }
57 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref]));
58 },
59
60 updateList: function()
61 {
62 let whitelistElement = E("typo_whitelist");
63
64 // Remove existing list entries
65 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
66 whitelistElement.removeItemAt(i);
67
68 // Build a list of exceptions and sort it alphabetically
69 let whitelist = Object.keys(Prefs.whitelist);
70 whitelist.sort();
71
72 // Add the rules to the list
73 if (whitelist.length > 0)
74 {
75 for (let i = 0; i < whitelist.length; i++)
76 {
77 let option = document.createElement("listitem");
78 option.setAttribute("value", whitelist[i]);
79 option.setAttribute("label", whitelist[i]);
80
81 whitelistElement.appendChild(option);
82 }
83 }
84 else
85 {
86 let option = document.createElement("listitem");
87 option.setAttribute("class", "auto-entry");
88 option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel")) ;
89
90 whitelistElement.appendChild(option);
91 }
92 },
93
94 updateState: function()
95 {
96 let enabled = Prefs.correctTypos;
97 E("typo_enable").checked = enabled;
98 E("typo_whitelist_container").style.visibility = (enabled) ? "visible" : "hi dden";
Wladimir Palant 2012/11/09 13:20:51 Please use .hidden property here, forgot to note t
99 }
100 };
101
102 window.addEventListener("load", function()
103 {
104 TypoActions.init();
105 }, false);
OLDNEW
« no previous file with comments | « chrome/content/ui/filters.xul ('k') | chrome/skin/icon16.png » ('j') | defaults/typoRules.json » ('J')

Powered by Google App Engine
This is Rietveld