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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | |
236 }; | |
237 | |
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 var currentWindow = this._tab._tab.browserWindow; | |
263 var toolbarItem = getToolbarItemForWindow(currentWindow); | |
264 | |
265 if (toolbarItem) | |
266 { | |
267 var property = getToolbarItemProperty(name); | |
268 property.tabs.set(this._tab, value); | |
269 | |
270 if (!("global" in property)) | |
271 property.global = toolbarItem[name]; | |
272 | |
273 if (this._tab._tab == currentWindow.activeTab) | |
274 toolbarItem[name] = value; | |
275 } | |
276 } | 255 } |
277 }; | 256 }; |
278 | 257 |
279 ext.tabs.onActivated.addListener(function(tab) | 258 ext.tabs.onActivated.addListener(function(tab) |
280 { | 259 { |
281 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow); | 260 var toolbarItem = getToolbarItemForWindow(tab._tab.browserWindow); |
282 | 261 |
283 if (!toolbarItem) | 262 if (!toolbarItem) |
284 return; | 263 return; |
285 | 264 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 }; | 626 }; |
648 | 627 |
649 ext.onMessage = new BackgroundMessageEventTarget(); | 628 ext.onMessage = new BackgroundMessageEventTarget(); |
650 | 629 |
651 // TODO: Implement context menu | 630 // TODO: Implement context menu |
652 ext.contextMenus = { | 631 ext.contextMenus = { |
653 create: function(title, contexts, onclick) {}, | 632 create: function(title, contexts, onclick) {}, |
654 removeAll: function(callback) {} | 633 removeAll: function(callback) {} |
655 }; | 634 }; |
656 })(); | 635 })(); |
LEFT | RIGHT |