MediaWiki:Gadget-hideSidebar.js
Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
- Opera: Naciśnij klawisze Ctrl+F5.
/*
---------------------------------------------------------------------------
Instrukcja:
http://pl.wikipedia.org/wiki/Wikipedia:Narz%C4%99dzia/Schowaj_menu_boczne
---------------------------------------------------------------------------
/* ======================================================================== *\
Adds a link that will allow one to show/hide sidebar
version: 1.8.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; position:relative;'
,'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#mw-head' : 'margin-left: 0px; ; z-index: 101;'
,'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>');
}
// General CSS
var hideSidebar_classRe = /\s*hidden_sidebar_panel\s*/g
document.write('<style id="hideSidebar_css2" type="text/css">div.hidden_sidebar_panel div {display:none} </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 el_lpanel = document.getElementById('panel');
if (el_lpanel)
{
el_lpanel = el_lpanel;
// show/hide button
var close_el = document.createElement('img');
close_el.id = 'hideSidebar_close_lpanel';
close_el.lpanel_el = el_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.className;
//this.lpanel_el.style.display = 'block';
this.lpanel_el.className = this.lpanel_el.className.replace(hideSidebar_classRe, ' ');
this.style.visibility = 'hidden';
}
close_el.funRestoreTmpPanelState = function()
{
//this.lpanel_el.style.display = this.lpanel_el_tmp_display;
this.lpanel_el.className = this.lpanel_el_tmp_display;
this.style.visibility = 'visible';
}
// click fun
close_el.onclick = function()
{
// show
//if (this.lpanel_el.style.display=='none')
if (this.lpanel_el.className.search(hideSidebar_classRe)!=-1)
{
document.cookie='js_hideSidebarPanelByDefault=0; path=/';
//this.lpanel_el.style.display='block';
this.lpanel_el.className = this.lpanel_el.className.replace(hideSidebar_classRe, ' ');
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.lpanel_el.className += ' hidden_sidebar_panel';
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.lpanel_el.className += ' hidden_sidebar_panel';
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.lpanel_el.className = close_el.lpanel_el.className.replace(hideSidebar_classRe, ' ');
close_el.alt = '[-]';
close_el.src = 'http://commons.wikimedia.org/w/thumb.php?f=Edit%20remove.svg&width=15px';
}
el_lpanel.insertBefore(close_el, el_lpanel.firstChild);
if (!window.hideSidebarByDefault)
{
close_el.funTmpShowPanel();
}
}
}
addOnloadHook(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();
}
}
}