Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 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 | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 Cu.import("resource://gre/modules/Services.jsm"); | 7 Cu.import("resource://gre/modules/Services.jsm"); |
8 | 8 |
9 let {Prefs} = require("prefs"); | 9 let {Prefs} = require("prefs"); |
10 let {WindowObserver} = require("windowObserver"); | 10 let {WindowObserver} = require("windowObserver"); |
11 | 11 |
12 var isAustralis = false; | |
13 try | |
14 { | |
15 Cu.import("resource:///modules/CustomizableUI.jsm", null); | |
16 isAustralis = true; | |
17 } catch(e) {} | |
18 | |
12 var WindowFeature = | 19 var WindowFeature = |
13 { | 20 { |
14 observer: null, | 21 observer: null, |
15 | 22 |
16 init: function() | 23 init: function() |
17 { | 24 { |
18 if (!this.observer) | 25 if (!this.observer) |
19 this.observer = new WindowObserver(this, "ready"); | 26 this.observer = new WindowObserver(this, "ready"); |
20 }, | 27 }, |
21 | 28 |
(...skipping 11 matching lines...) Expand all Loading... | |
33 this._applyToWindow(window); | 40 this._applyToWindow(window); |
34 }, | 41 }, |
35 | 42 |
36 removeFromWindow: function(window) | 43 removeFromWindow: function(window) |
37 { | 44 { |
38 if (window.location.href != this.windowUrl) | 45 if (window.location.href != this.windowUrl) |
39 return; | 46 return; |
40 this._removeFromWindow(window); | 47 this._removeFromWindow(window); |
41 } | 48 } |
42 } | 49 } |
43 | |
44 /** | |
45 * Object initializing add-on options, observes add-on manager notifications | |
46 * about add-on options being opened. | |
47 * @type nsIObserver | |
48 */ | |
49 let optionsObserver = | |
50 { | |
51 init: function() | |
52 { | |
53 Services.obs.addObserver(this, "addon-options-displayed", true); | |
54 onShutdown.add(function() | |
55 { | |
56 Services.obs.removeObserver(this, "addon-options-displayed"); | |
57 }.bind(this)); | |
58 }, | |
59 | |
60 initOptionsDoc: function(/**Document*/ doc) | |
61 { | |
62 function hideElement(id, hide) | |
63 { | |
64 let element = doc.getElementById(id); | |
65 if (element) | |
66 element.collapsed = hide; | |
67 } | |
Wladimir Palant
2014/07/30 07:45:40
No point to have a generic function here, we only
saroyanm
2014/07/30 09:18:32
Will keep in mind.
| |
68 | |
69 try | |
70 { | |
71 let {CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm", null); | |
72 if (CustomizableUI) | |
Wladimir Palant
2014/07/30 07:45:40
This check is pointless, if the module fails to lo
| |
73 hideElement("abpcustomization-icondisplay", true); | |
74 } catch (e) {} | |
75 }, | |
76 | |
77 observe: function(subject, topic, data) | |
78 { | |
79 let {addonID} = require("info") | |
80 if (data != addonID) | |
81 return; | |
82 | |
83 this.initOptionsDoc(subject.QueryInterface(Ci.nsIDOMDocument)); | |
84 }, | |
85 | |
86 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]) | |
Wladimir Palant
2014/07/30 07:45:40
Please import XPCOMUtils in this file. The fact th
saroyanm
2014/07/30 09:18:32
Done.
| |
87 }; | |
88 optionsObserver.init(); | |
89 | 50 |
90 var VerticalPreferencesLayout = | 51 var VerticalPreferencesLayout = |
91 { | 52 { |
92 __proto__: WindowFeature, | 53 __proto__: WindowFeature, |
93 windowUrl: "chrome://adblockplus/content/ui/filters.xul", | 54 windowUrl: "chrome://adblockplus/content/ui/filters.xul", |
94 | 55 |
95 _applyToWindow: function(window) | 56 _applyToWindow: function(window) |
96 { | 57 { |
97 let content = window.document.getElementById("content"); | 58 let content = window.document.getElementById("content"); |
98 let splitter = window.document.getElementById("filtersSplitter"); | 59 let splitter = window.document.getElementById("filtersSplitter"); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 __proto__: StylesheetFeature, | 124 __proto__: StylesheetFeature, |
164 stylesheet: "chrome://abpcustomization/content/oneLineSubscriptions.css" | 125 stylesheet: "chrome://abpcustomization/content/oneLineSubscriptions.css" |
165 }; | 126 }; |
166 | 127 |
167 var RemoveActionsButton = | 128 var RemoveActionsButton = |
168 { | 129 { |
169 __proto__: StylesheetFeature, | 130 __proto__: StylesheetFeature, |
170 stylesheet: "chrome://abpcustomization/content/noActionButton.css" | 131 stylesheet: "chrome://abpcustomization/content/noActionButton.css" |
171 }; | 132 }; |
172 | 133 |
134 var AddonPageAustralisStyles = | |
135 { | |
136 __proto__: StylesheetFeature, | |
137 stylesheet: "chrome://abpcustomization/content/addonPageAustralisStyles.css" | |
138 }; | |
139 | |
173 var ToolbarIconDisplay = | 140 var ToolbarIconDisplay = |
174 { | 141 { |
175 __proto__: StylesheetFeature, | 142 __proto__: StylesheetFeature, |
176 get template() | 143 get template() |
177 { | 144 { |
178 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(C i.nsIXMLHttpRequest); | 145 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(C i.nsIXMLHttpRequest); |
179 request.open("GET", "chrome://abpcustomization/content/toolbarIconDisplay.cs s", false); | 146 request.open("GET", "chrome://abpcustomization/content/toolbarIconDisplay.cs s", false); |
180 request.overrideMimeType("text/plain"); | 147 request.overrideMimeType("text/plain"); |
181 request.send(); | 148 request.send(); |
182 let result = request.responseText; | 149 let result = request.responseText; |
(...skipping 28 matching lines...) Expand all Loading... | |
211 stylesheet: "chrome://abpcustomization/content/hideMenus.css" | 178 stylesheet: "chrome://abpcustomization/content/hideMenus.css" |
212 }; | 179 }; |
213 | 180 |
214 let features = | 181 let features = |
215 { | 182 { |
216 "addon-page-styles": AddonPageStyles, | 183 "addon-page-styles": AddonPageStyles, |
217 "vertical-preferences-layout": VerticalPreferencesLayout, | 184 "vertical-preferences-layout": VerticalPreferencesLayout, |
218 "preferences-one-line-subscriptions": OneLineSubscriptions, | 185 "preferences-one-line-subscriptions": OneLineSubscriptions, |
219 "preferences-remove-actions-button": RemoveActionsButton, | 186 "preferences-remove-actions-button": RemoveActionsButton, |
220 "toolbar-icon-display": ToolbarIconDisplay, | 187 "toolbar-icon-display": ToolbarIconDisplay, |
188 "addon-page-australis-styles": AddonPageAustralisStyles, | |
221 "green-icon": GreenIcon, | 189 "green-icon": GreenIcon, |
222 "remove-menus": RemoveMenus | 190 "remove-menus": RemoveMenus |
223 }; | 191 }; |
224 | 192 |
225 function updateFeature(name) | 193 function updateFeature(name) |
226 { | 194 { |
227 if (name in features) | 195 if (name in features) |
228 { | 196 { |
229 let enabled; | 197 let enabled; |
230 if (name == "addon-page-styles") | 198 if (name == "addon-page-styles") |
231 enabled = true; | 199 enabled = true; |
200 else if (name == "toolbar-icon-display" && isAustralis) | |
201 enabled = false; | |
202 else if (name == "addon-page-australis-styles") | |
203 enabled = isAustralis; | |
232 else | 204 else |
233 enabled = Prefs[name]; | 205 enabled = Prefs[name]; |
234 | 206 |
235 if (enabled) | 207 if (enabled) |
236 features[name].init(); | 208 features[name].init(); |
237 else | 209 else |
238 features[name].shutdown(); | 210 features[name].shutdown(); |
239 } | 211 } |
240 } | 212 } |
241 | 213 |
242 // Initialize features and make sure to update them on changes | 214 // Initialize features and make sure to update them on changes |
243 for (let feature in features) | 215 for (let feature in features) |
244 updateFeature(feature); | 216 updateFeature(feature); |
245 | 217 |
246 Prefs.addListener(updateFeature); | 218 Prefs.addListener(updateFeature); |
LEFT | RIGHT |