User:XDaniX/hideSidebar.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:XDaniX/hideSidebar. |
/* ======================================================================== *\
Adds a link that will allow one to show/hide sidebar
version: 1.7.3
copyright: (C) 2006-2009 Maciej Jaros (pl:User:Nux, en:User:EcceNux)
licence: GNU General Public License v2,
http://opensource.org/licenses/gpl-license.php
\* ======================================================================== */
//
// Cookie hidding + default hidding management
//
// whole sidebar
if (window.hideSidebarByDefault)
{
window.hideSidebarByDefault = (document.cookie.indexOf("js_hideSidebarByDefault=0")==-1);
}
else
{
window.hideSidebarByDefault = (document.cookie.indexOf("js_hideSidebarByDefault=1")!=-1);
}
// left panel (vector only)
if (window.hideSidebarPanelByDefault)
{
window.hideSidebarPanelByDefault = (document.cookie.indexOf("js_hideSidebarPanelByDefault=0")==-1);
}
else
{
window.hideSidebarPanelByDefault = (document.cookie.indexOf("js_hideSidebarPanelByDefault=1")!=-1);
}
//
// CSS settings for skins...
//
/**/
var hideSidebar_css = {
'vector' : {
'hide' : {
'div#content' : 'margin-left: 0px; ; z-index: 100;'
,'div#panel' : 'float:left; position:static; background-image:url(/skins-1.5/vector/images/border.png);background-position:left top;background-repeat:repeat-x;'
,'div#head' : 'margin-left: 0px; ; z-index: 101;'
,'div#head-base' : 'margin-left: 0px;'
,'div#p-logo' : 'display: none;'
,'div#left-navigation' : 'left: 0px;'
}
}
,'monobook' : {
'hide' : {
'#content' : 'margin-left: 0px; z-index: 100;'
,'#p-cactions' : 'left: 0px;'
,'#p-cactions a:hover' : 'position:relative !important; z-index:101 !important;'
,'#p-logo' : 'display: none;'
,'#p-search' : 'position:relative; z-index:0;'
}
}
}
// css skin chooser
switch (skin)
{
// known
case "vector":
case "monobook":
hideSidebar_skin = skin;
break;
// fall back CSS
default:
hideSidebar_skin = 'vector';
break;
}
//
// Fast CSS init (faster because not run on load)
//
if (window.hideSidebarByDefault)
{
var css_text = '';
var myrules = hideSidebar_css[hideSidebar_skin].hide;
for (var rule in myrules)
{
css_text += ' '+ rule +' {' + myrules[rule] + '}';
}
document.write('<style id="hideSidebar_css" type="text/css">'+css_text+'</style>');
}
//
// initialization function
//
function initHideSidebar()
{
var el = document.getElementsByTagName('body')[0];
var elNew = document.createElement('div');
elNew.onclick = hideSidebar;
elNew.style.position = 'absolute'; // for IE.ver<7
elNew.id = 'hideSidebarElement';
elNew.style.cssText= ''
+'cursor:pointer;'
+'color:#696; font-weight:bold; font-size:20px;'
+'padding:2px; display:inline-block;'
+'left:0px; bottom:0px; z-index:2000; position:fixed;'
;
el.appendChild(elNew);
//
// mange hidding by deafault
if (window.hideSidebarByDefault)
{
elNew.innerHTML = '»';
elNew.sbShown = false;
}
else
{
elNew.innerHTML = '«';
elNew.sbShown = true;
}
if (window.userInitHideSidebar != null)
{
userInitHideSidebar();
}
// hide left panel with an additional button
var oel_lpanel = document.getElementById('panel');
if (oel_lpanel)
{
// add parent element for the panel
var nel_lpanel = document.createElement(oel_lpanel.nodeName);
oel_lpanel.parentNode.replaceChild(nel_lpanel, oel_lpanel);
nel_lpanel.id = oel_lpanel.id;
oel_lpanel.id = '';
// move old panel element to new one
nel_lpanel.appendChild(oel_lpanel);
// show/hide button
var close_el = document.createElement('img');
close_el.id = 'hideSidebar_close_lpanel';
close_el.lpanel_el = oel_lpanel;
close_el.style.cssText = 'float:right; margin:1px; padding:1px; cursor:pointer';
// funs for show/hide while sidebar not hidden
close_el.funTmpShowPanel = function()
{
this.lpanel_el_tmp_display = this.lpanel_el.style.display;
this.lpanel_el.style.display = 'block';
this.style.visibility = 'hidden';
}
close_el.funRestoreTmpPanelState = function()
{
this.lpanel_el.style.display = this.lpanel_el_tmp_display;
this.style.visibility = 'visible';
}
// click fun
close_el.onclick = function()
{
// show
if (this.lpanel_el.style.display=='none')
{
document.cookie='js_hideSidebarPanelByDefault=0; path=/';
this.lpanel_el.style.display='block';
this.src = 'http://commons.wikimedia.org/w/thumb.php?f=Edit%20remove.svg&width=15px';
this.alt = '[-]';
}
// hide
else
{
document.cookie='js_hideSidebarPanelByDefault=1; path=/';
this.lpanel_el.style.display='none';
this.src = 'http://commons.wikimedia.org/w/thumb.php?f=Edit%20add.svg&width=15px';
this.alt = '[+]';
}
}
// hide
if (window.hideSidebarPanelByDefault)
{
close_el.lpanel_el.style.display='none';
close_el.src = 'http://commons.wikimedia.org/w/thumb.php?f=Edit%20add.svg&width=15px';
close_el.alt = '[+]';
}
// show
else
{
close_el.lpanel_el.style.display='block';
close_el.alt = '[-]';
close_el.src = 'http://commons.wikimedia.org/w/thumb.php?f=Edit%20remove.svg&width=15px';
}
nel_lpanel.insertBefore(close_el, nel_lpanel.firstChild);
if (!window.hideSidebarByDefault)
{
close_el.funTmpShowPanel();
}
}
}
$(initHideSidebar);
//
// Main show/hide function
//
var hideSidebar_css_el = null;
function hideSidebar()
{
if (this.sbShown)
//
// hidding
//
{
hideSidebar_css_el = (hideSidebar_css_el==null) ? document.getElementById('hideSidebar_css') : undefined;
// style element not availble yet
if (!hideSidebar_css_el)
{
//
// create style element
//
var el = document.createElement('style');
el.id="hideSidebar_css";
document.getElementsByTagName('head')[0].appendChild(el);
hideSidebar_css_el = el;
//
// add rules
//
//el.innerHTML = '...'; // yeah would nice right?... FF and Opera only
// the DOM way...
sheet = (el.sheet) ? el.sheet : el.styleSheet;
if (sheet.insertRule) // nonIE
{
var myrules = hideSidebar_css[hideSidebar_skin].hide;
for (var rule in myrules)
{
sheet.insertRule (' '+ rule +' {' + myrules[rule] + '}', sheet.cssRules.length); // at the end
}
}
else if (sheet.addRule) // IE (+some friends)
{
var myrules = hideSidebar_css[hideSidebar_skin].hide;
for (var rule in myrules)
{
sheet.addRule (rule, myrules[rule]); // at the end
}
}
}
// already created
else
{
document.getElementsByTagName('head')[0].appendChild(hideSidebar_css_el);
}
this.innerHTML = '»';
this.sbShown = false;
document.cookie='js_hideSidebarByDefault=1; path=/';
// restore left panel state
var close_el = document.getElementById('hideSidebar_close_lpanel');
if (close_el)
{
close_el.funRestoreTmpPanelState();
}
}
//
// showing
//
else
{
var el = document.getElementById('hideSidebar_css');
if (el)
{
hideSidebar_css_el = el.parentNode.removeChild(el);
}
this.innerHTML = '«';
this.sbShown = true;
document.cookie='js_hideSidebarByDefault=0; path=/';
// show left panel even if hidden
var close_el = document.getElementById('hideSidebar_close_lpanel');
if (close_el)
{
close_el.funTmpShowPanel();
}
}
}