diff --git a/content/treestyletab/group.js b/content/treestyletab/group.js index 7a15c597..af160942 100644 --- a/content/treestyletab/group.js +++ b/content/treestyletab/group.js @@ -147,14 +147,47 @@ function getTabById(aId) function onItemClick(aEvent) { + var gBrowser = getOwnerTabBrowser(); + if (!gBrowser) + return; + var tab = getTabById(aEvent.getData('id')); - if (tab) + if (!tab) + return; + + var button = aEvent.getData('button'); + var altKey = aEvent.getData('altKey'); + var ctrlKey = aEvent.getData('ctrlKey'); + var metaKey = aEvent.getData('metaKey'); + var shiftKey = aEvent.getData('shiftKey'); + var isMiddleClick = ( + ( + button == 1 && + !altKey && + !ctrlKey && + !metaKey && + !shiftKey + ) || + ( + button == 0 && + !altKey && + (ctrlKey || metaKey) && + !shiftKey + ) + ); + + if (isMiddleClick) + gBrowser.removeTab(tab); + else if (button != 2) gBrowser.selectedTab = tab; } function updateTree() { + if (window.closed) + return; + var tree = document.getElementById('tree'); var range = document.createRange(); @@ -162,13 +195,18 @@ function updateTree() range.deleteContents(); range.detach(); - tree.appendChild(PseudoTreeBuilder.build(getOwnerTab())); + var contents = PseudoTreeBuilder.build(getOwnerTab()); + if (contents) + tree.appendChild(contents); } function checkUpdateTreeNow() { if (getOwnerTab().selected) - window.setTimeout(onTabSelect, 0); + window.setTimeout(function() { + if (!window.closed) + onTabSelect(); + }, 0); } var gShouldUpdate = false; diff --git a/modules/pseudoTreeBuilder.js b/modules/pseudoTreeBuilder.js index cd7fc33a..442aa924 100644 --- a/modules/pseudoTreeBuilder.js +++ b/modules/pseudoTreeBuilder.js @@ -58,8 +58,11 @@ var PseudoTreeBuilder = { var tree = this.createTabItem(aTab); - tree.querySelector("."+this.kTREEROW) - .className += " "+this.kROOTITEM; + var row = tree.querySelector("."+this.kTREEROW); + if (!row) + return; + + row.className += " "+this.kROOTITEM; tree.setAttribute('onclick', .toString().replace('%EVENT_TYPE%', this.kTAB_LINK_CLICK.quote()));