User:Manishearth/sidebartoggle.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. |
![]() | This user script seems to have a documentation page at User:Manishearth/sidebartoggle. |
var ml=10;
var stundefined;
var sideHidden=true;
if(readCookie('sidebarconfig')===null){
saveSidebar();
}
sideHidden=(readCookie('sidebarconfig')=="true")?true:false
var tabHide="<a href=\"javascript:toggleShowHide()\" title=\"Toggle the sidebar\">Hide Sidebar</a> <a href=\"javascript:saveSidebar()\" title=\"Save current sidebar configuration\">(s)</a>"
var tabShow="<a href=\"javascript:toggleShowHide()\" title=\"Toggle the sidebar\">Show Sidebar</a> <a href=\"javascript:saveSidebar()\" title=\"Save current sidebar configuration\">(s)</a>"
function hideSide(){
sideHidden=true;
document.getElementById('ca-tSH').innerHTML=tabShow
if(document.getElementById('p-logo').style!==null){document.getElementById('p-logo').style.display='none'}
if(document.getElementById('p-navigation').style!==null){document.getElementById('p-navigation').style.display='none'}
if(document.getElementById('p-search').style!==null){document.getElementById('p-search').style.display='none'}
if(document.getElementById('p-interaction')!==null){document.getElementById('p-interaction').style.display='none'}
if(document.getElementById('p-tb')!==null){document.getElementById('p-tb').style.display='none'}
if(document.getElementById('p-lang')!==null){if(document.getElementById('p-lang').style!==null){document.getElementById('p-lang').style.display='none'}}
if(document.getElementById('p-coll-print_export')!==null){document.getElementById('p-coll-print_export').style.display='none'}
document.getElementById('content').style.marginLeft=0;
}
//hideSide();
//showSide();
function showSide(){
sideHidden=false;
document.getElementById('ca-tSH').innerHTML=tabHide
if(document.getElementById('p-logo').style!==null){document.getElementById('p-logo').style.display=''}
if(document.getElementById('p-navigation').style!==null){document.getElementById('p-navigation').style.display=''}
if(document.getElementById('p-search').style!==null){document.getElementById('p-search').style.display=''}
if(document.getElementById('p-interaction')!==null){document.getElementById('p-interaction').style.display=''}
if(document.getElementById('p-tb')!==null){document.getElementById('p-tb').style.display=''}
if(document.getElementById('p-lang')!==null){if(document.getElementById('p-lang').style!==null){document.getElementById('p-lang').style.display=''}}
if(document.getElementById('p-coll-print_export')!==null){document.getElementById('p-coll-print_export').style.display=''}
document.getElementById('content').style.marginLeft='12.2em';
}
function toggleShowHide(){
if(sideHidden){
showSide()
}else{
hideSide();
}
}
addOnloadHook(
function(){
var tabcont="<span id=tSH> </span>"
mw.util.addPortletLink('p-cactions','javascript:toggleShowHide()',tabcont,'ca-tSH','Toggle the sidebar')
document.getElementById('ca-tSH').innerHTML=tabHide
if(sideHidden){
hideSide();
}
})
function saveSidebar(){
createCookie('sidebarconfig',sideHidden,365)
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}