diff --git a/content/treestyletab/hacks.js b/content/treestyletab/hacks.js index 2ced9b4c..76f52913 100644 --- a/content/treestyletab/hacks.js +++ b/content/treestyletab/hacks.js @@ -258,6 +258,52 @@ TreeStyleTabService.overrideExtensionsOnInitBefore = function TSTService_overrid ); } + // Tabberwocky + // https://addons.mozilla.org/firefox/addon/14439 + if ('tabberwocky' in window) { + TreeStyleTabBrowser.prototype.isMultiRow = function() + { + return this.getPref('tabberwocky.multirow') && !this.isVertical; + }; + + let listener = { + handleEvent : function(aEvent) + { + switch (aEvent.type) + { + case 'TreeStyleTabTabbarPositionChanged': + var b = aEvent.originalTarget; + if (b.treeStyleTab.isVertical) + b.treeStyleTab.setPref('tabberwocky.multirow', false); + break; + + case 'unload': + window.removeEventListener('TreeStyleTabTabbarPositionChanged', this, false); + window.removeEventListener('unload', this, false); + break; + } + } + }; + window.addEventListener('TreeStyleTabTabbarPositionChanged', listener, false); + window.addEventListener('unload', listener, false); + + if ('openSelectedLinks' in tabberwocky) { + eval('tabberwocky.openSelectedLinks = '+ + tabberwocky.openSelectedLinks.toSource().replace( + 'links.forEach(', + + ).replace( + /(\}\)?)$/, + + ) + ); + } + } + }; TreeStyleTabService.overrideExtensionsOnInitAfter = function TSTService_overrideExtensionsOnInitAfter() { @@ -932,36 +978,6 @@ TreeStyleTabService.overrideExtensionsOnInitAfter = function TSTService_override } } - // Tabberwocky - // https://addons.mozilla.org/firefox/addon/14439 - if ('multirow' in window && - 'updateMultiRowTabs' in multirow) { - eval('multirow.updateMultiRowTabs = '+ - multirow.updateMultiRowTabs.toSource().replace( - 'gBrowser.mPrefs.getBoolPref("tabberwocky.multirow")', - '$& && !gBrowser.treeStyleTab.isVertical' - ) - ); - window.setTimeout('multirow.updateMultiRowTabs();', 0); - } - if ('tabberwocky' in window) { - if ('openSelectedLinks' in tabberwocky) { - eval('tabberwocky.openSelectedLinks = '+ - tabberwocky.openSelectedLinks.toSource().replace( - 'links.forEach(', - - ).replace( - /(\}\)?)$/, - - ) - ); - } - } - window.setTimeout(function(aSelf) { aSelf.overrideExtensionsDelayed(); }, 0, this); diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index 8ab9c6dc..35cce488 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -148,6 +148,9 @@ TreeStyleTabBrowser.prototype = { } } + let position = this.currentTabbarPosition; + this.fireTabbarPositionEvent('TreeStyleTabTabbarPositionChanging', 'top', position); /* PUBLIC API */ + this.initTabbar(); b.addEventListener('TabOpen', this, true); @@ -583,6 +586,8 @@ TreeStyleTabBrowser.prototype = { this.autoHide; + this.fireTabbarPositionEvent('TreeStyleTabTabbarPositionChanged', 'top', position); /* PUBLIC API */ + b = null; }, @@ -1059,6 +1064,17 @@ TreeStyleTabBrowser.prototype = { } }, 100); }, + + fireTabbarPositionEvent : function TSTBrowser_fireTabbarPositionEvent(aType, aOldPosition, aNewPosition) + { + if (aOldPosition == aNewPosition) return; + + var event = document.createEvent('Events'); + event.initEvent(aType, true, true); + event.oldPosition = aOldPosition; + event.newPosition = aNewPosition; + this.mTabBrowser.dispatchEvent(event); + }, destroy : function TSTBrowser_destroy() { @@ -1174,14 +1190,7 @@ TreeStyleTabBrowser.prototype = { { case 'extensions.treestyletab.tabbar.position': var oldPosition = b.getAttribute(this.kTABBAR_POSITION); - let (event) { - /* PUBLIC API */ - event = document.createEvent('Events'); - event.initEvent('TreeStyleTabTabbarPositionChanging', true, true); - event.oldPosition = oldPosition; - event.newPosition = value; - this.mTabBrowser.dispatchEvent(event); - } + this.fireTabbarPositionEvent('TreeStyleTabTabbarPositionChanging', oldPosition, value); /* PUBLIC API */ this.initTabbar(); tabs.forEach(function(aTab) { this.initTabAttributes(aTab); @@ -1189,14 +1198,7 @@ TreeStyleTabBrowser.prototype = { tabs.forEach(function(aTab) { this.initTabContents(aTab); }, this); - let (event) { - /* PUBLIC API */ - event = document.createEvent('Events'); - event.initEvent('TreeStyleTabTabbarPositionChanged', true, true); - event.oldPosition = oldPosition; - event.newPosition = value; - this.mTabBrowser.dispatchEvent(event); - } + this.fireTabbarPositionEvent('TreeStyleTabTabbarPositionChanged', oldPosition, value); /* PUBLIC API */ window.setTimeout(function(aSelf) { aSelf.checkTabsIndentOverflow(); }, 0, this); @@ -1698,7 +1700,12 @@ TreeStyleTabBrowser.prototype = { if ( nextFocusedTab && this._tabFocusAllowance.every(function(aFunc) { - return aFunc.call(this, b); + try { + return aFunc.call(this, b); + } + catch(e) { + return false; + } }, this) ) b.selectedTab = nextFocusedTab;