MediaWiki:ShowHide.js

/* */

/* ============== SHOW AND HIDE =============================== author:       User:Slepi date:         06/2011, last update 03/2012 documentation: MediaWiki:ShowHide.js/documentation description:  show and hide portal sections or parts of other pages ==========================================================

var portalShowHide = { portalHideText : "hide", portalShowText : "show", portalTitleClass : "portaltitle", portalContentClass : "portalcontent", portalHiddenClass : "portalhidden",

showPortalToggle : function { if (document.createTextNode) { var portalTitle = getElementsByClass(portalShowHide.portalTitleClass); if (portalTitle.length == 0) { return; }

for(j in portalTitle) { var portalOuterSpan = document.createElement('span'); portalOuterSpan.className = 'portaltoggle';

var togglePortalLink = document.createElement('a'); togglePortalLink.id = 'togglePortalLink' + j;       togglePortalLink.className = 'internal'; togglePortalLink.href = 'javascript:portalShowHide.togglePortal(' + j + ')'; togglePortalLink.appendChild(document.createTextNode(portalShowHide.portalHideText));

portalOuterSpan.appendChild(document.createTextNode('[')); portalOuterSpan.appendChild(togglePortalLink); portalOuterSpan.appendChild(document.createTextNode(']'));

portalTitle[j].appendChild(document.createTextNode(' ')); portalTitle[j].appendChild(portalOuterSpan);

nazevCookie = "hideportal" + "_" + wgPageName + j + "="; var cookiePos = document.cookie.indexOf(nazevCookie);

if (cookiePos > -1 && document.cookie.charAt(cookiePos + nazevCookie.length) == 1) { portalShowHide.togglePortal(j); } else if (portalTitle[j].className.indexOf(portalShowHide.portalHiddenClass) != -1) { portalShowHide.togglePortal(j); }     }    }  },

togglePortal : function(toHide) { var portal = getElementsByClass(portalShowHide.portalContentClass);

portalX = portal[toHide]; var idToggle = 'togglePortalLink' + toHide; var togglePortalLink = document.getElementById(idToggle);

if (portalX && togglePortalLink && portalX.style.display == 'none') { changeText(togglePortalLink, portalShowHide.portalHideText); portalX.style.display = 'block'; document.cookie = "hideportal" + "_" + wgPageName + toHide + "=0"; } else { changeText(togglePortalLink, portalShowHide.portalShowText); portalX.style.display = 'none'; document.cookie = "hideportal" + "_" + wgPageName + toHide + "=1"; } } }

$(portalShowHide.showPortalToggle);