Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 } | 74 } |
75 }; | 75 }; |
76 | 76 |
77 | 77 |
78 /* Tabs */ | 78 /* Tabs */ |
79 | 79 |
80 Tab = function(tab) | 80 Tab = function(tab) |
81 { | 81 { |
82 this._tab = tab; | 82 this._tab = tab; |
83 | 83 |
84 this.browserAction = new TabBrowserAction(this); | 84 this.browserAction = new BrowserAction(this); |
85 | 85 |
86 this.onLoading = new LoadingTabEventTarget(tab); | 86 this.onLoading = new LoadingTabEventTarget(tab); |
87 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); | 87 this.onBeforeNavigate = new TabEventTarget(tab, "beforeNavigate", false); |
88 this.onCompleted = new TabEventTarget(tab, "navigate", false); | 88 this.onCompleted = new TabEventTarget(tab, "navigate", false); |
89 this.onActivated = new TabEventTarget(tab, "activate", false); | 89 this.onActivated = new TabEventTarget(tab, "activate", false); |
90 this.onRemoved = new TabEventTarget(tab, "close", false); | 90 this.onRemoved = new TabEventTarget(tab, "close", false); |
91 }; | 91 }; |
92 Tab.prototype = { | 92 Tab.prototype = { |
93 get url() | 93 get url() |
94 { | 94 { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 onLoading: new LoadingTabEventTarget(safari.application), | 182 onLoading: new LoadingTabEventTarget(safari.application), |
183 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue), | 183 onBeforeNavigate: new TabEventTarget(safari.application, "beforeNavigate", t rue), |
184 onCompleted: new TabEventTarget(safari.application, "navigate", true), | 184 onCompleted: new TabEventTarget(safari.application, "navigate", true), |
185 onActivated: new TabEventTarget(safari.application, "activate", true), | 185 onActivated: new TabEventTarget(safari.application, "activate", true), |
186 onRemoved: new TabEventTarget(safari.application, "close", true) | 186 onRemoved: new TabEventTarget(safari.application, "close", true) |
187 }; | 187 }; |
188 | 188 |
189 | 189 |
190 /* Browser actions */ | 190 /* Browser actions */ |
191 | 191 |
192 var toolbarItemProperites = {}; | 192 var toolbarItemProperties = {}; |
Wladimir Palant
2014/01/16 09:10:05
toolbarItemProperites => toolbarItemProperties?
Sebastian Noack
2014/01/16 12:45:02
Done.
| |
193 | 193 |
194 var getToolbarItemProperty = function(name) | 194 var getToolbarItemProperty = function(name) |
195 { | 195 { |
196 var property = toolbarItemProperites[name]; | 196 var property = toolbarItemProperties[name]; |
197 if (!property) | 197 if (!property) |
198 { | 198 { |
199 property = {global: safari.extension.toolbarItems[0][name], tabs: new TabM ap()}; | 199 property = {tabs: new TabMap()}; |
Wladimir Palant
2014/01/16 09:10:05
Will there always be at least one toolbar item? Wh
Sebastian Noack
2014/01/16 12:45:02
Done.
| |
200 toolbarItemProperites[name] = property; | 200 toolbarItemProperties[name] = property; |
201 } | 201 } |
202 return property; | 202 return property; |
203 }; | 203 }; |
204 | 204 |
205 var getToolbarItemForWindow = function(win) | 205 var getToolbarItemForWindow = function(win) |
206 { | 206 { |
207 for (var i = 0; i < safari.extension.toolbarItems.length; i++) | 207 for (var i = 0; i < safari.extension.toolbarItems.length; i++) |
208 { | 208 { |
209 var toolbarItem = safari.extension.toolbarItems[i]; | 209 var toolbarItem = safari.extension.toolbarItems[i]; |
210 | 210 |
211 if (toolbarItem.browserWindow == win) | 211 if (toolbarItem.browserWindow == win) |
212 return toolbarItem; | 212 return toolbarItem; |
213 } | 213 } |
214 | 214 |
215 return null; | 215 return null; |
216 }; | 216 }; |
217 | 217 |
218 var BrowserAction = function() {}; | 218 var BrowserAction = function(tab) |
219 { | |
220 this._tab = tab; | |
221 }; | |
219 BrowserAction.prototype = { | 222 BrowserAction.prototype = { |
223 _set: function(name, value) | |
224 { | |
225 var currentWindow = this._tab._tab.browserWindow; | |
226 var toolbarItem = getToolbarItemForWindow(currentWindow); | |
227 | |
228 if (toolbarItem) | |
229 { | |
230 var property = getToolbarItemProperty(name); | |
231 property.tabs.set(this._tab, value); | |
232 | |
233 if (!("global" in property)) | |
234 property.global = toolbarItem[name]; | |
235 | |
236 if (this._tab._tab == currentWindow.activeTab) | |
237 toolbarItem[name] = value; | |
238 } | |
239 }, | |
220 setIcon: function(path) | 240 setIcon: function(path) |
221 { | 241 { |
222 this._set("image", safari.extension.baseURI + path); | 242 this._set("image", safari.extension.baseURI + path); |
223 }, | 243 }, |
224 setTitle: function(title) | 244 setTitle: function(title) |
225 { | 245 { |
226 this._set("label", title); | 246 this._set("label", title); |
227 this._set("toolTip", title); | 247 this._set("toolTip", title); |
228 }, | 248 }, |
229 setBadge: function(badge) | 249 setBadge: function(badge) |
230 { | 250 { |
231 if (!badge) | 251 if (!badge) |
232 this._set("badge", 0); | 252 this._set("badge", 0); |
233 else if ("number" in badge) | 253 else if ("number" in badge) |
234 this._set("badge", badge.number); | 254 this._set("badge", badge.number); |
235 } | 255 } |
236 }; | 256 }; |
237 | 257 |
238 var GlobalBrowserAction = function() {}; | |
239 GlobalBrowserAction.prototype = { | |
240 __proto__: BrowserAction.prototype, | |
241 _set: function(name, value) | |
242 { | |
243 var property = getToolbarItemProperty(name); | |
244 property.global = value; | |
245 property.tabs.clear(); | |
246 | |
247 for (var i = 0; i < safari.extension.toolbarItems.length; i++) | |
248 safari.extension.toolbarItems[i][name] = value; | |
249 } | |
250 }; | |
251 | |
252 ext.browserAction = new GlobalBrowserAction(); | |
253 | |
254 var TabBrowserAction = function(tab) | |
255 { | |
256 this._tab = tab; | |
257 }; | |
258 TabBrowserAction.prototype = { | |
259 __proto__: BrowserAction.prototype, | |
260 _set: function(name, value) | |
261 { | |
262 getToolbarItemProperty(name).tabs.set(this._tab, value); | |
263 | |
264 var currentWindow = this._tab._tab.browserWindow; | |
265 var toolbarItem = getToolbarItemForWindow(currentWindow); | |
266 if (toolbarItem && this._tab._tab == currentWindow.activeTab) | |
Wladimir Palant
2014/01/16 09:10:05
Nit: It seems that |this._tab._tab == currentWindo
| |
267 toolbarItem[name] = value; | |
268 } | |
269 }; | |
270 | |
271 ext.tabs.onActivated.addListener(function(tab) | 258 ext.tabs.onActivated.addListener(function(tab) |
272 { | 259 { |
273 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow); | 260 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow); |
274 | 261 |
275 if (!toolbarItem) | 262 if (!toolbarItem) |
276 return; | 263 return; |
277 | 264 |
278 for (var name in toolbarItemProperites) | 265 for (var name in toolbarItemProperties) |
279 { | 266 { |
280 var property = toolbarItemProperites[name]; | 267 var property = toolbarItemProperties[name]; |
281 | 268 |
282 if (property.tabs.has(tab)) | 269 if (property.tabs.has(tab)) |
283 toolbarItem[name] = property.tabs.get(tab); | 270 toolbarItem[name] = property.tabs.get(tab); |
284 else | 271 else |
285 toolbarItem[name] = property.global; | 272 toolbarItem[name] = property.global; |
286 } | 273 } |
287 }); | 274 }); |
288 | 275 |
289 | 276 |
290 /* Windows */ | 277 /* Windows */ |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
639 }; | 626 }; |
640 | 627 |
641 ext.onMessage = new BackgroundMessageEventTarget(); | 628 ext.onMessage = new BackgroundMessageEventTarget(); |
642 | 629 |
643 // TODO: Implement context menu | 630 // TODO: Implement context menu |
644 ext.contextMenus = { | 631 ext.contextMenus = { |
645 create: function(title, contexts, onclick) {}, | 632 create: function(title, contexts, onclick) {}, |
646 removeAll: function(callback) {} | 633 removeAll: function(callback) {} |
647 }; | 634 }; |
648 })(); | 635 })(); |
LEFT | RIGHT |