| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 for (let child of toolbox.palette.children) | 57 for (let child of toolbox.palette.children) |
| 58 if (child.id == id) | 58 if (child.id == id) |
| 59 return child; | 59 return child; |
| 60 | 60 |
| 61 return null; | 61 return null; |
| 62 } | 62 } |
| 63 | 63 |
| 64 function restoreWidget(/**Element*/ toolbox, /**Widget*/ widget) | 64 function restoreWidget(/**Element*/ toolbox, /**Widget*/ widget) |
| 65 { | 65 { |
| 66 // Create node | 66 // Create node |
| 67 let node = toolbox.ownerDocument.createElement("toolbarbutton"); | 67 let node = widget.onBuild(toolbox.ownerDocument); |
| 68 node.setAttribute("id", widget.id); | |
| 69 if (typeof widget.onClick == "function") | 68 if (typeof widget.onClick == "function") |
| 70 node.addEventListener("click", widget.onClick, false); | 69 node.addEventListener("click", widget.onClick, false); |
| 71 if (typeof widget.onCommand == "function") | 70 if (typeof widget.onCommand == "function") |
| 72 node.addEventListener("command", widget.onCommand, false); | 71 node.addEventListener("command", widget.onCommand, false); |
| 73 if (typeof widget.onCreated == "function") | |
| 74 widget.onCreated(node); | |
| 75 | 72 |
| 76 // Insert into the palette first | 73 // Insert into the palette first |
| 77 toolbox.palette.insertBefore(node, toolbox.palette.firstChild); | 74 toolbox.palette.insertBefore(node, toolbox.palette.firstChild); |
| 78 | 75 |
| 79 // Now find out where we should put it | 76 // Now find out where we should put it |
| 80 let position = toolbox.getAttribute(widget.positionAttribute); | 77 let position = toolbox.getAttribute(widget.positionAttribute); |
| 81 if (!/^\S*,\S*,\S*$/.test(position)) | 78 if (!/^\S*,\S*,\S*$/.test(position)) |
| 82 position = null; | 79 position = null; |
| 83 | 80 |
| 84 if (position == null) | 81 if (position == null) |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 saveState(toolbox, widget); | 181 saveState(toolbox, widget); |
| 185 } | 182 } |
| 186 | 183 |
| 187 function saveState(/**Element*/ toolbox, /**Widget*/ widget) | 184 function saveState(/**Element*/ toolbox, /**Widget*/ widget) |
| 188 { | 185 { |
| 189 let node = toolbox.ownerDocument.getElementById(widget.id); | 186 let node = toolbox.ownerDocument.getElementById(widget.id); |
| 190 | 187 |
| 191 let position = toolbox.getAttribute(widget.positionAttribute) || "hidden,,"; | 188 let position = toolbox.getAttribute(widget.positionAttribute) || "hidden,,"; |
| 192 if (node) | 189 if (node) |
| 193 { | 190 { |
| 194 if (typeof widget.onCreated == "function") | 191 if (typeof widget.onAdded == "function") |
| 195 widget.onCreated(node); | 192 widget.onAdded(node) |
| 196 | 193 |
| 197 let toolbar = getToolbar(node); | 194 let toolbar = getToolbar(node); |
| 198 position = "visible," + toolbar.id + "," + (node.nextSibling ? node.nextSibl
ing.id : ""); | 195 position = "visible," + toolbar.id + "," + (node.nextSibling ? node.nextSibl
ing.id : ""); |
| 199 } | 196 } |
| 200 else | 197 else |
| 201 position = position.replace(/^visible,/, "hidden,") | 198 position = position.replace(/^visible,/, "hidden,") |
| 202 | 199 |
| 203 toolbox.setAttribute(widget.positionAttribute, position); | 200 toolbox.setAttribute(widget.positionAttribute, position); |
| 204 toolbox.ownerDocument.persist(toolbox.id, widget.positionAttribute); | 201 toolbox.ownerDocument.persist(toolbox.id, widget.positionAttribute); |
| 205 } | 202 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 return null; | 238 return null; |
| 242 | 239 |
| 243 let widget = window.document.getElementById(id); | 240 let widget = window.document.getElementById(id); |
| 244 if (!widget) | 241 if (!widget) |
| 245 return null; | 242 return null; |
| 246 | 243 |
| 247 let toolbar = getToolbar(widget); | 244 let toolbar = getToolbar(widget); |
| 248 if (!toolbar) | 245 if (!toolbar) |
| 249 return null; | 246 return null; |
| 250 | 247 |
| 251 let items = toolbar.currentSet.split(","); | 248 return {area: toolbar.id}; |
| 252 let index = items.indexOf(id); | 249 }, |
| 253 if (index < 0) | 250 |
| 254 return null; | 251 addWidgetToArea: function(id) |
| 255 else | 252 { |
| 256 return {area: toolbar.id, placement: index}; | 253 // Note: the official API function also has area and position parameters. |
| 257 }, | 254 // We ignore those here and simply restore the previous position instead. |
| 258 | |
| 259 addWidgetToArea: function(id, area, position) | |
| 260 { | |
| 261 let widget = widgets.get(id); | 255 let widget = widgets.get(id); |
| 262 for (let window of UI.applicationWindows) | 256 for (let window of UI.applicationWindows) |
| 263 { | 257 { |
| 264 let toolbox = getToolbox(window, widget); | 258 let toolbox = getToolbox(window, widget); |
| 265 if (!toolbox) | 259 if (!toolbox) |
| 266 continue; | 260 continue; |
| 267 | 261 |
| 268 let position = toolbox.getAttribute(widget.positionAttribute); | 262 let position = toolbox.getAttribute(widget.positionAttribute); |
| 269 if (position) | 263 if (position) |
| 270 position = position.replace(/^hidden,/, "visible,"); | 264 position = position.replace(/^hidden,/, "visible,"); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 for (let [id, widget] of widgets) | 315 for (let [id, widget] of widgets) |
| 322 { | 316 { |
| 323 let toolbox = getToolbox(window, widget); | 317 let toolbox = getToolbox(window, widget); |
| 324 if (toolbox) | 318 if (toolbox) |
| 325 toolbox.removeEventListener("aftercustomization", onToolbarCustomization
, false); | 319 toolbox.removeEventListener("aftercustomization", onToolbarCustomization
, false); |
| 326 | 320 |
| 327 removeWidget(window, widget); | 321 removeWidget(window, widget); |
| 328 } | 322 } |
| 329 } | 323 } |
| 330 }); | 324 }); |
| LEFT | RIGHT |