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

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

Issue 8559070: Integrated URL Fixer into Adblock Plus (Closed)
Patch Set: Added ability to opt-in and opt-out Created Oct. 19, 2012, 9:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 let enabled = Prefs.correctTypos;
14 E("typo_enable").checked = enabled;
15 E("typo_whitelist_container").style.visibility = (enabled) ? "visible" : "hi dden";
16
17 TypoActions.updateList();
18 },
19
20 onPrefChange: function(name)
21 {
22 if (name == "whitelist")
23 TypoActions.updateList();
24 },
25
26 toggleEnable: function(checked)
27 {
28 E("typo_whitelist_container").style.visibility = (checked) ? "visible" : "hi dden";
29 Prefs.correctTypos = checked;
30 },
31
32 onItemSelected: function(list)
33 {
34 let button = E(list.getAttribute("_removeButton"));
35 let items = list.selectedItems;
36 button.disabled = (items.length == 0 || (items.length == 1 && !items[0].valu e));
37 },
38
39 removeRule: function(btn, pref)
40 {
41 let list = E(btn.getAttribute("_list"));
42 let items = list.selectedItems;
43
44 let {onWhitelistEntryRemoved} = require("typoRules");
45
46 for (let i = items.length - 1; i >= 0; i--)
47 {
48 let searchString = items[i].getAttribute("value");
49 delete Prefs[pref][searchString];
50
51 if (pref == "whitelist")
52 onWhitelistEntryRemoved(searchString);
53 }
54 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref]));
55 },
56
57 updateList: function()
58 {
59 let whitelistElement = E("typo_whitelist");
60
61 // Remove existing list entries
62 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
63 whitelistElement.removeItemAt(i);
64
65 // Build a list of exceptions and sort it alphabetically
66 let whitelist = Object.keys(Prefs.whitelist);
67 whitelist.sort();
68
69 // Add the rules to the list
70 if (whitelist.length > 0)
71 {
72 for (let i = 0; i < whitelist.length; i++)
73 {
74 let option = document.createElement("listitem");
75 option.setAttribute("value", whitelist[i]);
76 option.setAttribute("label", whitelist[i]);
77
78 whitelistElement.appendChild(option);
79 }
80 }
81 else
82 {
83 let option = document.createElement("listitem");
84 option.setAttribute("class", "auto-entry");
85 option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel")) ;
86
87 whitelistElement.appendChild(option);
88 }
89 }
90 };
91
92 Prefs.addListener(TypoActions.onPrefChange);
93 window.addEventListener("unload", function() Prefs.removeListener(TypoActions.on PrefChange), false);
OLDNEW
« 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