Toolbar Button On Install

Talk about add-ons and extension development.
Ihoss
Posts: 376
Joined: July 4th, 2004, 11:11 am

Post by Ihoss »

So this will add it to the nav-bar. I kow that chatZilla and the extension maker adds the buttons to the customize menu so you can add them later. Anyone know how to do that?
asqueella
Posts: 4019
Joined: November 16th, 2003, 3:05 am
Location: Russia, Moscow

Post by asqueella »

konstantinr
Posts: 5
Joined: August 10th, 2005, 6:34 pm

Complete solution

Post by konstantinr »

Here's the complete solution that allows to put the button in any location in the toolbar and does not screw up the address bar:
<code>
var beforeElement = document.getElementById(beforeId);
tb.insertItem(buttonId, beforeElement);
document.persist("nav-bar", "currentset");
</code>
The key is that second parameter of insertItem is an Element, and not an Id string.
dr.evil
Posts: 1
Joined: November 5th, 2008, 8:08 am

Re: Toolbar Button On Install

Post by dr.evil »

is there a .xpi file. I tried making install.rdf, chrome.manifest and the xul file for this but couldn't have it work.
max1million
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Re: Toolbar Button On Install

Post by max1million »

https://developer.mozilla.org/En/Code_s ... by_default
has to be done after first window load
ghoulardi
Posts: 52
Joined: January 20th, 2005, 2:16 am

Re: Toolbar Button On Install

Post by ghoulardi »

max1million wrote:https://developer.mozilla.org/En/Code_snippets:Toolbar#Adding_button_by_default
has to be done after first window load


Can someone plese tell me what I am missing?
The button itself works perfect but nothing I try makes it add automaticly.

here's what I have...

common.js

Code: Select all

window.addEventListener("load", em_myextensionLoad, true);

function em_myextensionLoad() {

 try {
   var firefoxnav = document.getElementById("nav-bar");
   var curSet = firefoxnav.currentSet;
   if (curSet.indexOf("main-button-container") == -1)
   {
     var set;
     // Place the button before the urlbar
     if (curSet.indexOf("urlbar-container") != -1)
       set = curSet.replace(/urlbar-container/, "main-button-container,urlbar-container");
     else  // at the end
       set = curSet + ",main-button-container";
     firefoxnav.setAttribute("currentset", set);
     firefoxnav.currentSet = set;
     document.persist("nav-bar", "currentset");
     // If you don't do the following call, funny things happen
     try {
       BrowserToolboxCustomizeDone(true);
     }
     catch (e) { }
   }
 }
 catch(e) { }
}




overlay.xul

Code: Select all

<!-- toolbar button -->
 <toolbarpalette id="BrowserToolbarPalette">
    <toolbaritem id="main-button-container" align="center">
   <toolbarbutton id="main-button"/>
   </toolbaritem>
   </toolbarpalette>
<!-- button details -->
<toolbarbutton id=".......etc...
ghoulardi
Posts: 52
Joined: January 20th, 2005, 2:16 am

Re: Toolbar Button On Install

Post by ghoulardi »

Anybody?

Update:

I got it to work but now if i open "customize" and change the location or remove it it reapears on restart. :(
User avatar
Morac
Posts: 2519
Joined: February 9th, 2004, 8:20 pm
Contact:

Re: Toolbar Button On Install

Post by Morac »

The code above will always add your button to the nav-bar toolbar whenever a window is opened. It doesn't matter whether it's because it was never in the nav-bar toolbar or if the user has removed it or moved it to another toolbar.

If you only want it to be added if it's not there you'll need to do a check for your button before running the code above. For example adding the following line at the beginning of the myextensionLoad function which will allow the user to move the button to another toolbar:

Code: Select all

if (document.getElementById("main-button-container")) return;


If you want the user to be able to remove the button and not have it automatically added, you'll need to set a preference when the button is first added and then not add it again if that preference is set.
ghoulardi
Posts: 52
Joined: January 20th, 2005, 2:16 am

Re: Toolbar Button On Install

Post by ghoulardi »

Ahh, got it. Big Help! Thank you very much Morac!!
Post Reply