Changes

Jump to: navigation, search

Dive into Mozilla Modifying Firefox using an Extension Lab

1,872 bytes added, 16:19, 13 March 2007
no edit summary
However, unlike last time where we modified tabbrowser.xml directly, this time we will '''overlay''' our changes onto the browser at runtime, and alleviate the need for any direct changes to the code. This is possible using '''extensions'''.
 
 
 
 
'''overlay.js'''
 
var AddTabBeside = {
// State info on the last tab to be selected.
mPreviousIndex: 0,
onLoad: function() {
// Add a listener for the TabOpen event, which gets called as part of addTab in tabbrowser.xml
var container = gBrowser.tabContainer;
container.addEventListener("TabOpen", this.onTabOpen, false);
 
// Also add a listener for TabSelect so we know when focus changes to a new tab
container.addEventListener("TabSelect", this.onTabSelect, false);
 
// Finally, add a listener for shutdown
window.addEventListener("unload", this.onUnload, false);
},
onUnload: function() {
var container = gBrowser.tabContainer;
container.removeEventListener("TabOpen", this.onTabOpen, false);
container.removeEventListener("TabSelect", this.onTabSelect, false);
},
onTabSelect: function (e) {
// when a different tab is selected, remember which one. This is
// necessary because when a new tab is created, it will get pushed
// to the end of the list, but we need to know where to put it.
this.mPreviousIndex = gBrowser.tabContainer.selectedIndex;
},
onTabOpen: function (e) {
// Get the newly created tab, which will be last in the list
var newTab = e.target;
// Move this new tab to the right of the previously selected tab,
// checking to see how many tabs there are currently. By default
// there is 1 tab, and the first time onTabOpen is called, there will
// be 2 (the default plus the newly created tab). In this case, don't
// move the new tab, since it is already in the right spot. In all
// other cases, move the tab to the right of the current tab.
if (gBrowser.tabContainer.childNodes.length > 2) {
gBrowser.moveTabTo(newTab, this.mPreviousIndex + 1);
}
},
};
window.addEventListener("load", function(e) { AddTabBeside.onLoad(e); }, false);
 
 
 
 
 
 
 
 
 
 
=The 'Where': finding the right spot to make the changes=

Navigation menu