Last active
November 24, 2015 04:31
-
-
Save Eccenux/a1e331d02b04debc4b00 to your computer and use it in GitHub Desktop.
Custom Buttons (FF) - smartOpenWebPanel (replacement for openWebPanel)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.smartOpenWebPanel("Translate", "https://translate.google.pl/"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Init*/ | |
/** | |
Opens URL in AiOS web-panel but only if not already loaded. | |
*/ | |
this.smartOpenWebPanel = function (label, url) { | |
// fallback for non-AiOS sidebar | |
if (typeof AiOS_HELPER == 'undefined') { | |
openWebPanel(label, url); | |
} | |
// figure out sidebar state | |
var sidebarDoc = this._getAiosDocument(); | |
if (sidebarDoc) { | |
var webPanel = sidebarDoc.getElementById('web-panels-browser'); | |
var webPanelSelected = false; | |
var webPanelUrl = ''; | |
if(webPanel) { | |
webPanelSelected = true; // not necessarly visble(!) | |
// url that was open in the web-panel | |
webPanelUrl = webPanel.contentDocument.location.href; | |
} | |
// remove (ignore in comparison) query string and hash if URL to be opened doesn't contain one | |
if (url.search(/[#\?]/) < 0) { | |
webPanelUrl = webPanelUrl.replace(/[#\?].+/, ''); | |
} | |
} | |
/** | |
alert("sidebarHref:"+sidebarDoc.location.href);// for web-panel: chrome://browser/content/web-panels.xul | |
alert("webPanelUrl:"+webPanelUrl); | |
alert("aios_isSidebarHidden():"+aios_isSidebarHidden()); | |
/**/ | |
// open if different | |
var openedUrl = false; | |
if (webPanelUrl !== url) { | |
openedUrl = true; | |
openWebPanel(label, url); | |
} | |
// toggle sidebar (force open if opening new URL) | |
if(aios_isSidebarHidden() || openedUrl) { | |
// not sure why but this works better for opening the sidebar after URL change... | |
if (openedUrl) { | |
toggleSidebar('viewPageInfoSidebar'); | |
toggleSidebar('viewWebPanelsSidebar'); | |
} else { | |
aios_toggleSidebar('switch', true); | |
} | |
} else { | |
aios_toggleSidebar('switch', false); | |
} | |
} | |
/* | |
Minor helper functions | |
*/ | |
this._getAiosDocument = function () { | |
return AiOS_HELPER.mostRecentWindow.document.getElementById('sidebar').contentDocument; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment