[Project_owners] Re: FF toolbar palette-to-toolbar notification

Charles Melhorn melodious at mindspring.com
Sun Jan 23 11:09:17 EST 2005

Charles Melhorn wrote:

> Is there any way for a Firefox toolbar item to receive a notification
> upon being moved from the toolbar palette to a toolbar?

I thought I'd post the solution I came up with in case anyone finds
it useful or can improve upon it.

The objective here was to obtain a notification when my toolbar
item was dragged from the "Customize Toolbar" dialog palette to
a toolbar, and vice versa, in order to be able to initialize and
cleanup (respectively) my extension just as it would be upon
browser load and unload. I was unable to discover an existing hook
for doing this, so I used an overlay onto "customizeToolbar.xul"
to add event listeners for "DOMNodeInserted" and
"DOMNodeRemoved" as follows below.

You can see this in action in the most recent release of


though I'm still in the process of checking the code into CVS.




<?xml version="1.0"?>

<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

  <RDF:Seq about="urn:mozilla:package:root">
    <RDF:li resource="urn:mozilla:package:derbrowsertimer"/>

  <RDF:Description about="urn:mozilla:package:derbrowsertimer"
        chrome:displayName="Der Browser Timer"
        chrome:author="Charles Melhorn"

  <!-- overlay information -->
    <RDF:Seq about="urn:mozilla:overlays">
      <RDF:li resource="chrome://browser/content/browser.xul"/>
      <RDF:li resource="chrome://global/content/customizeToolbar.xul"/>

  <!-- Firebird Browser-->
  <RDF:Seq about="chrome://browser/content/browser.xul">

  <!-- Customize Toolbar Dialog-->
  <RDF:Seq about="chrome://global/content/customizeToolbar.xul">


And the overlay, dbtOverlayCT.xul

<?xml version="1.0"?>

<overlay id="dbt-ctOverlay"

<!-- Javascript includes -->

<script type="application/x-javascript">

  function addDBTEventListeners()
    var palette_box = document.getElementById("palette-box");
    palette_box.addEventListener("DOMNodeInserted", dbtTbItemAdded, false);
    palette_box.addEventListener("DOMNodeRemoved", dbtTbItemRemoved, false);

  function dbtTbItemAdded(e)
    if (e.target.id == "wrapper-dbt-clock-tbitem")

  // Assumption: this relies on toolbar items being inserted
  // into a toolbar before being removed from the customize
  // toolbar window palette

  function dbtTbItemRemoved(e)
    if (e.target.id == "wrapper-dbt-clock-tbitem")

  window.addEventListener("load", addDBTEventListeners, false);



More information about the Project_owners mailing list