1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-23 19:03:02 +01:00
This commit is contained in:
gorhill 2016-01-24 10:15:32 -05:00
parent 58838ce4c5
commit 1f5b9b0e13

View File

@ -37,44 +37,43 @@ var resizeFrame = function() {
/******************************************************************************/
var loadDashboardPanel = function(tab, q) {
var tabButton = uDom('[href="#' + tab + '"]');
if ( !tabButton ) {
var loadDashboardPanel = function() {
var pane = window.location.hash.slice(1);
if ( pane === '' ) {
pane = 'settings.html';
}
var tabButton = uDom('[href="#' + pane + '"]');
if ( !tabButton || tabButton.hasClass('selected') ) {
return;
}
q = q || '';
uDom('iframe').attr('src', tab + q);
uDom('.tabButton').toggleClass('selected', false);
uDom('.tabButton.selected').toggleClass('selected', false);
uDom('iframe').attr('src', pane);
tabButton.toggleClass('selected', true);
};
/******************************************************************************/
var onTabClickHandler = function(e) {
loadDashboardPanel(this.hash.slice(1));
var url = window.location.href,
pos = url.indexOf('#');
if ( pos !== -1 ) {
url = url.slice(0, pos);
}
url += this.hash;
if ( url !== window.location.href ) {
window.location.replace(url);
loadDashboardPanel();
}
e.preventDefault();
};
/******************************************************************************/
uDom.onLoad(function() {
window.addEventListener('resize', resizeFrame);
resizeFrame();
var matches = window.location.search.slice(1).match(/\??(tab=([^&]+))?(.*)$/);
var tab = '', q = '';
if ( matches && matches.length === 4 ) {
tab = matches[2];
q = matches[3];
if ( q !== '' && q.charAt(0) === '&' ) {
q = '?' + q.slice(1);
}
}
if ( !tab ) {
tab = 'settings';
}
loadDashboardPanel(tab + '.html', q);
window.addEventListener('resize', resizeFrame);
uDom('.tabButton').on('click', onTabClickHandler);
loadDashboardPanel();
});
/******************************************************************************/