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: Created Oct. 12, 2012, 2:18 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
« 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 onPrefChange: function(name)
12 {
13 if (name == "whitelist")
14 TypoActions.updateList();
15 },
16
17 onItemSelected: function(list)
18 {
19 let button = E(list.getAttribute("_removeButton"));
20 let items = list.selectedItems;
21 button.disabled = (items.length == 0 || (items.length == 1 && !items[0].valu e));
22 },
23
24 removeRule: function(btn, pref)
25 {
26 let list = E(btn.getAttribute("_list"));
27 let items = list.selectedItems;
28
29 let {onWhitelistEntryRemoved} = require("typoRules");
30
31 for (let i = items.length - 1; i >= 0; i--)
32 {
33 let searchString = items[i].getAttribute("value");
34 delete Prefs[pref][searchString];
35
36 if (pref == "whitelist")
37 onWhitelistEntryRemoved(searchString);
38 }
39 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref]));
40 },
41
42 updateList: function()
43 {
44 let whitelistElement = E("typo_whitelist");
45
46 // Remove existing list entries
47 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--)
48 whitelistElement.removeItemAt(i);
49
50 // Build a list of exceptions and sort it alphabetically
51 let whitelist = Object.keys(Prefs.whitelist);
52 whitelist.sort();
53
54 // Add the rules to the list
55 if (whitelist.length > 0)
56 {
57 for (let i = 0; i < whitelist.length; i++)
58 {
59 let option = document.createElement("listitem");
60 option.setAttribute("value", whitelist[i]);
61 option.setAttribute("label", whitelist[i]);
62
63 whitelistElement.appendChild(option);
64 }
65 }
66 else
67 {
68 let option = document.createElement("listitem");
69 option.setAttribute("class", "auto-entry");
70 option.setAttribute("label", whitelistElement.getAttribute("_emptyLabel")) ;
71
72 whitelistElement.appendChild(option);
73 }
74 }
75 };
76
77 Prefs.addListener(TypoActions.onPrefChange);
78 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