MediaWiki:Gadget-hideSidebar.js
Перейти до навігації
Перейти до пошуку
Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.
- Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
- Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
- Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
- Opera: натисніть Ctrl-F5
// Додає скрипт зі сторінки: [[Wikipedysta:Nux/hideSidebar.js]]
/*
---------------------------------------------------------------------------
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.5
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#mw-panel' : 'float:left; position:static;',
'div#mw-head' : 'margin-left: 0px; ; z-index: 101;',
'body .suggestions' : 'z-index: 105;',
'div#p-logo' : 'display: none;',
'div#left-navigation' : 'left: 0px;',
}
}
,'monobook' : {
'hide' : {
'div#content' : 'margin-left: 0px; z-index: 100;',
'div#p-cactions' : 'left: 0px;',
'div#p-cactions a:hover' : 'position:relative !important; z-index:101 !important;',
'div#p-logo' : 'display: none;',
'div#p-search' : 'position:relative; z-index:0;',
}
}
};
// css chooser based on skins
var hideSidebar_skin = 'vector'; // fallback
switch (mw.config.get('skin'))
{
// known
case "vector":
case "monobook":
hideSidebar_skin = mw.config.get('skin');
break;
}
//
// Fast CSS init (faster because not run on load)
//
if (window.hideSidebarByDefault)
{
(function(){
var css_text = '';
var myrules = hideSidebar_css[hideSidebar_skin].hide;
for (var rule in myrules)
{
css_text += ' '+ rule +' {' + myrules[rule] + '}';
}
$(document.body).append('<style id="hideSidebar_css" type="text/css">'+css_text+'</style>');
})();
}
// General CSS
var hideSidebar_classRe = /\s*hidden_sidebar_panel\s*/g;
$(document.body).append('<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)
{
window.userInitHideSidebar();
}
// hide left panel with an additional button
var el_lpanel = document.getElementById('mw-panel');
if (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 = 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Edit_remove.svg/15px-Edit_remove.svg.png';
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 = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Edit_add.svg/15px-Edit_add.svg.png';
this.alt = '[+]';
}
};
// hide
if (window.hideSidebarPanelByDefault)
{
//close_el.lpanel_el.style.display='none';
close_el.lpanel_el.className += ' hidden_sidebar_panel';
close_el.src = 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Edit_add.svg/15px-Edit_add.svg.png';
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 = 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Edit_remove.svg/15px-Edit_remove.svg.png';
}
el_lpanel.insertBefore(close_el, el_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...
var 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
}
} else {
console.error('[hideSidebar] uable to add css');
}
}
// 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();
}
}
}