[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
DerBrowserTimer,

http://derbrowsertimer.mozdev.org/

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

Charles

========================

contents.rdf

<?xml version="1.0"?>


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


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

  <RDF:Description about="urn:mozilla:package:derbrowsertimer"
        chrome:displayName="Der Browser Timer"
        chrome:packageVersion="0.4"
        chrome:author="Charles Melhorn"
        chrome:name="derbrowsertimer">
  </RDF:Description>

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

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

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


</RDF:RDF>


And the overlay, dbtOverlayCT.xul

<?xml version="1.0"?>

<overlay id="dbt-ctOverlay"
                 xmlns:html="http://www.w3.org/TR/REC-html40"
                 
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">


<!-- 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")
      opener.clearDerBrowserTimer();
  }


  // 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")
      opener.initDerBrowserTimer();
  }


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

</script>


</overlay>





More information about the Project_owners mailing list