MediaWiki:Monobook.js: Difference between revisions
From Halopedia, the Halo wiki
No edit summary |
Jack Phoenix (talk | contribs) (coding style tweaks) |
||
Line 55: | Line 55: | ||
// Collapsible Portlets (experimental) | // Collapsible Portlets (experimental) | ||
// ================================================== | // ================================================== | ||
function foldingPortlets() { | |||
var portlets = getElementsByClassName( document.getElementById( 'column-one' ), 'div', 'portlet' ); | |||
var portskip = ['p-personal', 'p-cactions', 'p-logo', 'p-search', 'p-tbx', 'p-lang']; | |||
var first = true; | |||
for( var i = 0; i < portlets.length; i++ ) { | |||
{ | if( portskip.join( ' ' ).indexOf( portlets[i].id ) == -1 ) { | ||
var pd = portlets[i].getElementsByTagName( 'div' )[0]; | |||
var ph = portlets[i].getElementsByTagName( 'h5' )[0]; | |||
ph.className = 'portletCollapsible'; | |||
pd.setAttribute( 'id', 'pbody-' + i ); | |||
pd.style.display = 'none'; | |||
var link = document.createElement( 'a' ); | |||
var head = getAllText( ph ); | |||
while( ph.firstChild ) { | |||
ph.removeChild( ph.firstChild ); | |||
} | |||
link.appendChild( document.createTextNode( head ) ); | |||
link.setAttribute( 'href', 'javascript:showPortlet(\'' + i + '\');' ); | |||
link.setAttribute( 'id', 'plink-' + i ); | |||
var link = document.createElement('a'); | |||
var head = getAllText(ph); | |||
while(ph.firstChild) ph.removeChild(ph.firstChild); | |||
link.appendChild(document.createTextNode(head)); | |||
link.setAttribute('href','javascript:showPortlet(\'' + i + '\');'); | |||
link.setAttribute('id','plink-'+i); | |||
link.className = 'portletClosed'; | link.className = 'portletClosed'; | ||
ph.appendChild(link); | ph.appendChild( link ); | ||
if(first==true) | if( first == true ) { | ||
first = false; | |||
first=false; | showPortlet( i ); | ||
showPortlet(i); | |||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
if(skin=='monobook'&&!window.portletsNormal) addOnloadHook(foldingPortlets) | if( skin == 'monobook' && !window.portletsNormal ) { | ||
addOnloadHook( foldingPortlets ); | |||
} | |||
function getAllText(thing) | function getAllText( thing ) { | ||
{ | if ( thing.nodeType == 3 ) { | ||
if (thing.nodeType == 3) return thing.nodeValue; | return thing.nodeValue; | ||
var text = new Array(); var i=0; | } | ||
while(thing.childNodes[i]) | var text = new Array(); | ||
var i = 0; | |||
text[text.length] = getAllText(thing.childNodes[i]); | while( thing.childNodes[i] ) { | ||
text[text.length] = getAllText( thing.childNodes[i] ); | |||
i++; | i++; | ||
} | } | ||
return text.join(''); | return text.join( '' ); | ||
} | } | ||
function showPortlet(id) | function showPortlet( id ) { | ||
{ | var pd = document.getElementById( 'pbody-' + id ); | ||
var pd = document.getElementById('pbody-'+id); | var pl = document.getElementById( 'plink-' + id ); | ||
var pl = document.getElementById('plink-'+id); | |||
if(pd.style.display=='none') | if( pd.style.display == 'none' ) { | ||
pd.style.display = 'block'; | |||
pd.style.display='block'; | |||
pl.className = 'portletOpened'; | pl.className = 'portletOpened'; | ||
} | } else { | ||
pd.style.display = 'none'; | |||
pd.style.display='none'; | |||
pl.className = 'portletClosed'; | pl.className = 'portletClosed'; | ||
} | } | ||
Line 123: | Line 119: | ||
// End Collapsible Portlets | // End Collapsible Portlets | ||
// ================================================== | // ================================================== | ||
/* </nowiki></pre> */ |