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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 /** | 18 /** |
19 * @fileOverview This emulates a subset of the CustomizableUI API from Firefox 2
8. | 19 * @fileOverview This emulates a subset of the CustomizableUI API from Firefox 2
8. |
20 */ | 20 */ |
21 | 21 |
22 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", null); | 22 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", null); |
23 | 23 |
24 let {Utils} = require("utils"); | 24 let {Utils} = require("utils"); |
25 | 25 |
26 // UI module has to be referenced lazily to avoid circular references | 26 // UI module has to be referenced lazily to avoid circular references |
27 XPCOMUtils.defineLazyGetter(this, "UI", function() { return require("ui").UI; })
; | 27 XPCOMUtils.defineLazyGetter(this, "UI", () => require("ui").UI); |
28 | 28 |
29 let widgets = Map(); | 29 let widgets = Map(); |
30 | 30 |
31 function getToolbox(/**Window*/ window, /**Widget*/ widget) /**Element*/ | 31 function getToolbox(/**Window*/ window, /**Widget*/ widget) /**Element*/ |
32 { | 32 { |
33 if (!("defaultArea" in widget) || !widget.defaultArea) | 33 if (!("defaultArea" in widget) || !widget.defaultArea) |
34 return null; | 34 return null; |
35 | 35 |
36 let toolbar = UI.findElement(window, widget.defaultArea); | 36 let toolbar = UI.findElement(window, widget.defaultArea); |
37 if (!toolbar) | 37 if (!toolbar) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 let toolbox = event.currentTarget; | 175 let toolbox = event.currentTarget; |
176 for (let [id, widget] of widgets) | 176 for (let [id, widget] of widgets) |
177 saveState(toolbox, widget); | 177 saveState(toolbox, widget); |
178 } | 178 } |
179 | 179 |
180 function saveState(/**Element*/ toolbox, /**Widget*/ widget) | 180 function saveState(/**Element*/ toolbox, /**Widget*/ widget) |
181 { | 181 { |
182 let node = toolbox.ownerDocument.getElementById(widget.id); | 182 let node = toolbox.ownerDocument.getElementById(widget.id); |
183 | 183 |
184 let position = toolbox.getAttribute(widget.positionAttribute) || "hidden,,"; | 184 let position = toolbox.getAttribute(widget.positionAttribute) || "hidden,,"; |
185 if (node) | 185 if (node && node.parentNode.localName != "toolbarpalette") |
186 { | 186 { |
187 if (typeof widget.onAdded == "function") | 187 if (typeof widget.onAdded == "function") |
188 widget.onAdded(node) | 188 widget.onAdded(node) |
189 | 189 |
190 let toolbar = getToolbar(node); | 190 let toolbar = getToolbar(node); |
191 position = "visible," + toolbar.id + "," + (node.nextSibling ? node.nextSibl
ing.id : ""); | 191 position = "visible," + toolbar.id + "," + (node.nextSibling ? node.nextSibl
ing.id : ""); |
192 } | 192 } |
193 else | 193 else |
194 position = position.replace(/^visible,/, "hidden,") | 194 position = position.replace(/^visible,/, "hidden,") |
195 | 195 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 for (let [id, widget] of widgets) | 311 for (let [id, widget] of widgets) |
312 { | 312 { |
313 let toolbox = getToolbox(window, widget); | 313 let toolbox = getToolbox(window, widget); |
314 if (toolbox) | 314 if (toolbox) |
315 toolbox.removeEventListener("aftercustomization", onToolbarCustomization
, false); | 315 toolbox.removeEventListener("aftercustomization", onToolbarCustomization
, false); |
316 | 316 |
317 removeWidget(window, widget); | 317 removeWidget(window, widget); |
318 } | 318 } |
319 } | 319 } |
320 }); | 320 }); |
LEFT | RIGHT |