MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/* ===== Specified Page-Designs ===== */ /* == Main-Page == */ if (wgPageName == 'Main_Page' || wgPageName == 'Talk:Main_Page') addOnloadHook(function {        addPortletLink('p-lang', 'http://facesofwarwiki.referata.com/wiki/Hauptseite', 'Faces of War - Wiki', 'interwiki-fow-wiki', 'Faces of War - Wiki (German)')       var nstab = document.getElementById('ca-nstab-main')        if (nstab && wgUserLanguage=='en') {            while (nstab.firstChild) nstab = nstab.firstChild            nstab.nodeValue = 'Main Page'        }        if (nstab && wgUserLanguage=='de') {            while (nstab.firstChild) nstab = nstab.firstChild            nstab.nodeValue = 'Hauptseite'        }        if (nstab && wgUserLanguage=='fr') {            while (nstab.firstChild) nstab = nstab.firstChild            nstab.nodeValue = 'Accueil'        }        if (nstab && wgUserLanguage=='es') {            while (nstab.firstChild) nstab = nstab.firstChild            nstab.nodeValue = 'Página Principal'        }        if (nstab && wgUserLanguage=='it') {            while (nstab.firstChild) nstab = nstab.firstChild            nstab.nodeValue = 'Pagina principale' }       if (nstab && wgUserLanguage=='ru') { while (nstab.firstChild) nstab = nstab.firstChild nstab.nodeValue = 'Заглавная страница' }       if (nstab && wgUserLanguage=='ch') { while (nstab.firstChild) nstab = nstab.firstChild nstab.nodeValue = 'Fanhaluman' }       if (nstab && wgUserLanguage=='pl') { while (nstab.firstChild) nstab = nstab.firstChild nstab.nodeValue = 'Strona główna' }       if (nstab && wgUserLanguage=='ja') { while (nstab.firstChild) nstab = nstab.firstChild nstab.nodeValue = 'メインページ' }   } )

/* == Other Pages ... == */

if (wgPageName == 'Men_of_War' || wgPageName == 'Talk:Men_of_War') addOnloadHook(function {        var nstab = document.getElementById('ca-nstab-main')            {            while (nstab.firstChild) nstab = nstab.firstChild            nstab.nodeValue = 'Men of War'        }    } )

/* Include script for Special:Upload from MediaWiki:Upload.js */ if (mw.config.get( 'wgCanonicalSpecialPageName' ) == "Upload") { importScript("MediaWiki:Upload.js"); }

/* == Edit Pages == */

if (mwCustomEditButtons) {

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/c/c8/Button_redirect.png", "speedTip": "Redirect (blanc page before!)", "tagOpen": '#REDIRECT ',    "tagClose": '', "sampleText": "Article name"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/f/fd/Button_underline.png", "speedTip": "Underlined text", "tagOpen": ' ', "tagClose": ' ', "sampleText": "Underlined text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/7f/Button_link_to_Wikipedia.png", "speedTip": "Wikipedia link", "tagOpen": 'Wikipedia:',    "tagClose": '', "sampleText": "Article name|Link name"};

if (wgNamespaceNumber == '6' || wgNamespaceNumber == '7') { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/1c/Button_advanced_image.png", "speedTip": "Image standartisation", "tagOpen": '{'+'{Image\n' + '|DESCRIPTION = ', "tagClose": '\n' + '|UPLOADER   = \n' + '|SOURCE     = \n' + '|CREATOR    = \n' + '|LICENSE    = \n' + '}'+'}',     "sampleText": "Image description"}; }

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://farm6.static.flickr.com/5175/5460286194_8a9eaefa7e_t.jpg", "speedTip": "Code-formatted text", "tagOpen": ' ', "sampleText": "Code-formatted text"}; }

/* ===== Collapsible Tables ===== */

var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; function collapseTable( tableIndex ) { var Button = document.getElementById( 'collapseButton' + tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex ); if ( !Table || !Button ) { return false; }	var Rows = Table.rows; if ( Button.firstChild.data == collapseCaption ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none'; }		Button.firstChild.data = expandCaption; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; }		Button.firstChild.data = collapseCaption; } } 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' ) ) { /* only add button and increment count if there is a header row to work with */ 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' ); var ButtonLink = document.createElement( 'a' ); var ButtonText = document.createTextNode( collapseCaption ); Button.style.styleFloat = 'right'; Button.style.cssFloat = 'right'; Button.style.fontWeight = 'normal'; Button.style.textAlign = 'right'; Button.style.width = '6em';

Button.className = 'collapseButton'; // Styles are declared in MediaWiki:Common.css ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); 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 ); }	} } addOnloadHook( createCollapseButtons ); /** Test if an element has a certain class ************************************** * * Description: Uses regular expressions and caching for better performance. * Maintainers: User:Mike Dillon, User:R. Koot, User:SG */ var hasClass = (function {	var reCache = {};	return function( element, className ) {		return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);	}; });