Changes

Jump to: navigation, search

Dive into Mozilla Modifying Firefox using an Extension Lab

2,113 bytes added, 14:29, 14 March 2007
Success, and some bugs
Luckily we've already stumbled upon the solution to this problem--the '''TabMove''' event. Here is the updated version of '''overlay.js''', with the change in bold:
 
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);
'''// And a listener for TabMove to fix an edge case'''
'''container.addEventListener("TabMove", this.onTabSelect, false);'''
// Finally, add a listener for shutdown
window.addEventListener("unload", this.onUnload, false);
},
onUnload: function() {
// Remove our listeners
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);
}
},
};
// Insure that our code gets loaded at start-up
window.addEventListener("load", function(e) { AddTabBeside.onLoad(e); }, false);
=Reflections=

Navigation menu