User:Dodoïste/vector.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. |
![]() | The accompanying .css page for this skin is at User:Dodoïste/vector.css. |
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia:NavFrame]].
* Maintainers: [[User:R. Koot]]
* Changed for better usability by [[User:Cacycle]]
*/
var autoCollapse = 2; // present on the page before the autocollapsible
// table initially appear collapsed.
var collapseCaption = "hide";
var expandCaption = "show";
var collapseTitle = "Hide the contents of this table."
var expandTitle = "Show the contents of this table."
var collapseImage = null; // Change to a string containing an URL to use
var expandImage = null; // images for collapsing and expanding tables.
var collapseImage = "/media/wikipedia/commons/thumb/5/5e/Symbol_oppose_vote_oversat.svg/16px-Symbol_oppose_vote_oversat.svg.png";
var expandImage = "/media/wikipedia/commons/thumb/9/94/Symbol_support_vote.svg/16px-Symbol_support_vote.svg.png";
function collapseTable( tableIndex ) {
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
var ButtonText = Button.firstChild;
if ( ( collapseImage ? ButtonText.alt : ButtonText.data ) == collapseCaption ) {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
if ( collapseImage ) {
ButtonText.alt = expandCaption;
ButtonText.title = expandTitle;
ButtonText.src = expandImage;
} else {
ButtonText.data = expandCaption;
ButtonText.title = expandTitle;
}
} else {
for ( var i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
if ( collapseImage ) {
ButtonText.alt = collapseCaption;
ButtonText.title = collapseTitle;
ButtonText.src = collapseImage;
} else {
ButtonText.data = collapseCaption;
ButtonText.title = collapseTitle;
}
}
}
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = new Object();
var Tables = document.getElementsByTagName( "table" );
for ( var i = 0; i < Tables.length; i++ ) {
if ( hasClass( Tables[i], "collapsible" ) ) {
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if ( !HeaderRow ) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if ( !Header ) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
Button.className = "collapseButton"; //Styles are declared in Common.css
var ButtonLink = document.createElement( "a" );
ButtonLink.id = "collapseButton" + tableIndex;
ButtonLink.href = "javascript:collapseTable(" + tableIndex + ");";
ButtonLink.style.color = Header.style.color; // Fix up the colour
var ButtonText = null;
if ( collapseImage ) {
ButtonText = document.createElement( "img" );
ButtonText.alt = collapseCaption;
ButtonText.title = collapseTitle;
ButtonText.src = collapseImage;
} else {
ButtonText = document.createTextNode( collapseCaption );
}
ButtonLink.appendChild( ButtonText );
if ( !collapseImage ) Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
if ( !collapseImage ) Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.childNodes[0] );
tableIndex++;
}
}
for ( var i = 0; i < tableIndex; i++ ) {
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
collapseTable( i );
}
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
var element = NavigationBoxes[i];
while (element = element.parentNode) {
if ( hasClass( element, "outercollapse" ) ) {
collapseTable ( i );
break;
}
}
}
}
}
addOnloadHook( createCollapseButtons );