MediaWiki:Common.js

/*Imports - Full credits on imported pages*/

/* http://dev.wikia.com/wiki/RevealAnonIP This must be placed above all imports. */ window.RevealAnonIP = { permissions : ['user'] }; importArticles({   type: "script",    articles: [        "w:c:dev:RevealAnonIP/code.js",        "MediaWiki:Common.js/navfix.js", /*Fix wiki navigation ~Jgjake2*/        "w:c:deadisland:User:Jgjake2/js/ElderScrolls/Popups.js", /*Popup script  ~Jgjake2*/        "MediaWiki:Common.js/countdown.js", /*Countdown timer ~Splarkle*/        "MediaWiki:Common.js/sliders.js", /*Jquery sliders ~Tierrie*/        "MediaWiki:Common.js/title.js", /*  ~CoDWiki*/        "MediaWiki:Common.js/collapse.js", /*Collapsibles ~HaLo2FrEeEk*/        "MediaWiki:Functions.js",        "MediaWiki:Gadget-Edittools.js",        "MediaWiki:Common.js/summaries.js", /*Standard edit summaries*/        "MediaWiki:Common.js/masthead.js",        "MediaWiki:Common.js/autolock.js", /*30day blog lock*/        "MediaWiki:Gadget-SigReminder.js"    ] });

/*End imports*/

//=============================================================================================

/* -Adds edit links to WLH page -- * * -Final-Fantasy-wiki */ function addEditLinksToWLH { if(wgCanonicalSpecialPageName=='Whatlinkshere') {   var links = document.getElementById("mw-whatlinkshere-list").getElementsByTagName('li'); for(var i = 0; i(edit) '; links[i].insertBefore(editLinkSpan,tools[0]); } } }

addOnloadHook(addEditLinksToWLH);

/** * JavaScript below copied from http://starwars.wikia.com/wiki/MediaWiki:Common.js * Check there for updates if something breaks **/

// onload stuff var firstRun = true;

function loadFunc { if( firstRun ) { firstRun = false; } else { return; }

window.pageName = wgPageName; window.storagePresent = (typeof(globalStorage) != 'undefined');

// DEPRECATED if( document.getElementById('infoboxinternal') != null && document.getElementById('infoboxend') != null ) { document.getElementById('infoboxend').innerHTML = '[Hide]'; }

// Upload form - need to run before adding hide buttons if ( wgCanonicalSpecialPageName === 'Upload' ) { setupUploadForm; }

addHideButtons;

if( document.getElementById('mp3-navlink') !== null ) { document.getElementById('mp3-navlink').onclick = onArticleNavClick; document.getElementById('mp3-navlink').getElementsByTagName('a')[0].href = 'javascript:void(0)'; }

if( window.storagePresent ) { initVisibility; }

fillEditSummaries; fillPreloads;

substUsername; substUsernameTOC; rewriteTitle; showEras('title-eraicons'); showEras('title-shortcut'); rewriteHover; addAlternatingRowColors; // replaceSearchIcon; this is now called from MediaWiki:Monobook.js	fixSearch;

var body = document.getElementsByTagName('body')[0]; var bodyClass = body.className;

if( !bodyClass || (bodyClass.indexOf('page-') === -1) ) { var page = window.pageName.replace(/\W/g, '_'); body.className += ' page-' + page; }

if( typeof(onPageLoad) != "undefined" ) { onPageLoad; } }

function infoboxToggle { var page = window.pageName.replace(/\W/g, '_'); var nowShown;

if(document.getElementById('infoboxtoggle').innerHTML == '[Hide]') { document.getElementById('infoboxinternal').style.display = 'none'; document.getElementById('infoboxtoggle').innerHTML = '[Show]'; nowShown = false; } else { document.getElementById('infoboxinternal').style.display = 'block'; document.getElementById('infoboxtoggle').innerHTML = '[Hide]'; nowShown = true; }

if(window.storagePresent) { var storage = globalStorage[window.location.hostname]; storage.setItem('infoboxshow-' + page, nowShown); } }

/** * jQuery version of fillEditSummaries * @author Grunny */ function fillEditSummaries {

if( !$( '#wpSummaryLabel' ).length ) { return; }	var	summaryOptionsHtml = '', $summaryOptionsList;

$.get( wgScript, { title: 'Template:Stdsummaries', action: 'raw', ctype: 'text/plain' }, function( data ) {		var lines = data.split( '\n' );		for( var i = 0; i < lines.length; i++ ) {			var value = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : "";			summaryOptionsHtml += '' + lines[i] + ' ';		}		$summaryOptionsList = $( ' ' ).attr( 'id', 'stdEditSummaries' ).html( summaryOptionsHtml ).change( function { var value = $( this ).val; if ( value !== '' ) { if( skin === 'oasis' ) { $( '#wpSummary' ).text( value ); } else { $( '#wpSummary' ).val( value ); }			}		} );

$( '#wpSummaryLabel' ).prepend( 'Standard summaries: ', $summaryOptionsList, ' ' ); } );

}

/** * jQuery version of fillPreloads * @author Grunny */ function fillPreloads {

if( !$( '#lf-preload' ).length ) { return; }	var	preloadOptionsHtml = '', $preloadOptionsList;

$( '#lf-preload' ).attr( 'style', 'display: block' );

$.get( wgScript, { title: 'Template:Stdpreloads', action: 'raw', ctype: 'text/plain' }, function( data ) {		var lines = data.split( '\n' );		for( var i = 0; i < lines.length; i++ ) {			var value = ( lines[i].indexOf( '-- ' ) === 0 ) ? lines[i].substring(3) : "";			preloadOptionsHtml += '' + lines[i] + ' ';		}		$preloadOptionsList = $( ' ' ).attr( 'id', 'stdSummaries' ).html( preloadOptionsHtml ).change( function { var value = $( this ).val; if ( value !== '' ) { value = 'Template:' + value + '/preload'; value = value.replace( ' ', '_' ); $.get( wgScript, { title: value, action: 'raw', ctype: 'text/plain' }, function( data ) {					insertAtCursor( document.getElementById( 'wpTextbox1' ), data );				} ); }		} );

$( '#lf-preload-cbox' ).html( $preloadOptionsList ); } );

$( '#lf-preload-pagename' ).html( '' ); $( '#lf-preload-button' ).html( '' );

}

function doCustomPreload { var value = $( '#lf-preload-pagename > input' ).val; value = value.replace( ' ', '_' ); $.get( wgScript, { title: value, action: 'raw', ctype: 'text/plain' }, function( data ) {		insertAtCursor( document.getElementById( 'wpTextbox1' ), data );	} ); }

// ============================================================ // BEGIN JavaScript title rewrite -- jQuery version and new wikia skin fixes by Grunny

function rewriteTitle { if( typeof( window.SKIP_TITLE_REWRITE ) != 'undefined' && window.SKIP_TITLE_REWRITE ) { return; }

if( $('#title-meta').length == 0 ) { return; }

var newTitle = $('#title-meta').html; if( skin == "oasis" ) { $('header.WikiaPageHeader > h1').html(' ' + newTitle + ' '); $('header.WikiaPageHeader > h1').attr('style','text-align:' + $('#title-align').html + ';'); } else { $('.firstHeading').html(' ' + newTitle + ' '); $('.firstHeading').attr('style','text-align:' + $('#title-align').html + ';'); } }

function showEras(className) { if( skin == 'oasis' ) { return; }

if( typeof( SKIP_ERAS ) != 'undefined' && SKIP_ERAS ) return;

var titleDiv = document.getElementById( className );

if( titleDiv == null || titleDiv == undefined ) return;

var cloneNode = titleDiv.cloneNode(true); var firstHeading = getFirstHeading; firstHeading.insertBefore(cloneNode, firstHeading.childNodes[0]); cloneNode.style.display = "block"; } // END JavaScript title rewrite

function initVisibility { var storage = globalStorage[window.location.hostname];

var page = window.pageName.replace(/\W/g,'_'); var show = storage.getItem('infoboxshow-' + page);

if( show == 'false' ) { infoboxToggle; }

var hidables = getElementsByClass('hidable');

for(var i = 0; i < hidables.length; i++) { show = storage.getItem('hidableshow-' + i + '_' + page);

if( show == 'false' ) { var content = getElementsByClass('hidable-content', hidables[i]); var button = getElementsByClass('hidable-button', hidables[i]);

if( content != null && content.length > 0 &&				button != null && button.length > 0 && content[0].style.display != 'none' ) {				button[0].onclick('bypass'); }		} else if( show == 'true' ) { var content = getElementsByClass('hidable-content', hidables[i]); var button = getElementsByClass('hidable-button', hidables[i]);

if( content != null && content.length > 0 &&				button != null && button.length > 0 && content[0].style.display == 'none' ) {				button[0].onclick('bypass'); }		}	} }

function onArticleNavClick { var div = document.getElementById('mp3-nav');

if( div.style.display == 'block' ) div.style.display = 'none'; else div.style.display = 'block'; }

function addAlternatingRowColors { var infoboxes = getElementsByClass('infobox', document.getElementById('content'));

if( infoboxes.length == 0 ) return;

for( var k = 0; k < infoboxes.length; k++ ) { var infobox = infoboxes[k];

var rows = infobox.getElementsByTagName('tr'); var changeColor = false;

for( var i = 0; i < rows.length; i++ ) { if(rows[i].className.indexOf('infoboxstopalt') != -1) break;

var ths = rows[i].getElementsByTagName('th');

if( ths.length > 0 ) { continue; }

if(changeColor) rows[i].style.backgroundColor = '#111111'; changeColor = !changeColor; }	} }

function addHideButtons { var hidables = getElementsByClass('hidable');

for( var i = 0; i < hidables.length; i++ ) { var box = hidables[i]; var button = getElementsByClass('hidable-button', box, 'span');

if( button != null && button.length > 0 ) { button = button[0];

button.onclick = toggleHidable; button.appendChild( document.createTextNode('[Hide]') );

if( new ClassTester('start-hidden').isMatch(box) ) button.onclick('bypass'); }	} }

function toggleHidable(bypassStorage) { var parent = getParentByClass('hidable', this); var content = getElementsByClass('hidable-content', parent); var nowShown;

if( content != null && content.length > 0 ) { content = content[0];

if( content.style.display == 'none' ) { content.style.display = content.oldDisplayStyle; this.firstChild.nodeValue = '[Hide]'; nowShown = true; } else { content.oldDisplayStyle = content.style.display; content.style.display = 'none'; this.firstChild.nodeValue = '[Show]'; nowShown = false; }

if( window.storagePresent && ( typeof( bypassStorage ) == 'undefined' || bypassStorage != 'bypass' ) ) { var page = window.pageName.replace(/\W/g, '_'); var items = getElementsByClass('hidable'); var item = -1;

for( var i = 0; i < items.length; i++ ) { if( items[i] == parent ) { item = i;					break; }			}

if( item == -1 ) { return; }

var storage = globalStorage[window.location.hostname]; storage.setItem('hidableshow-' + item + '_' + page, nowShown); }	} }

/*   Replaces  with the name of the user browsing the page. Requires copying Template:USERNAME. function substUsername { if ( wgUserName != null ) { $('.insertusername').html(wgUserName); } }

function substUsernameTOC { var toc = $('#toc'); var userpage = $('#pt-userpage');

if( !userpage || !toc ) return;

var username = $('#pt-userpage').children(':first-child').html; $('span.toctext:not(:has(*)), span.toctext i', toc).each(function	{		$(this).html($(this).html.replace(' ', username));	}); }

// Reskin parser script from Uncyclopedia:MediaWiki:Uncyclopedia.js skinjs = { "Logout": "Logout.js" }

var re = RegExp("(.*) - Wookieepedia, the Star Wars Wiki"); var matches = re.exec(document.title);

var skinNamejs;

if (matches) { if (skinjs[matches[1]] != undefined) { skinNamejs = (skinjs[matches[1]].length > 0) ? skinjs[matches[1]] : matches[1] + '.js'; document.write(' '); } }

function fixSearch { var button = document.getElementById('searchSubmit');

if( button ) button.name = 'go'; }

/************************************************************ * Functions.js stuff * Deprecated, most of these functions will be removed slowly ************************************************************/

/*   Source: http://www.dustindiaz.com/getelementsbyclass/ getElementsByClass, which complements getElementById and getElementsByTagName, returns an array of all subelements of node that are tagged with a specific CSS class (searchClass) and are of the tag name tag. If tag is null, it searches for any suitable elements regardless of the tag name. Example: getElementsByClass('infobox', document.getElementById('content'), 'div') selects the same elements as the CSS declaration #content div.infobox function getElementsByClass(searchClass, node, tag) {	var classElements = new Array;

if(node == null) node = document;

if(tag == null) tag = '*';

var els = node.getElementsByTagName(tag); var elsLen = els.length; var tester = new ClassTester(searchClass);

for(i = 0, j = 0; i < elsLen; i++) {		if(tester.isMatch(els[i])) {			classElements[j] = els[i]; j++; }	}	return classElements; }

function ClassTester(className) {	this.regex = new RegExp("(^|\\s)" + className + "(\\s|$)"); }

ClassTester.prototype.isMatch = function(element) {	return this.regex.test(element.className); } /*   end getElementsByClass

function insertAtCursor(myField, myValue) { //IE support if (document.selection) {		myField.focus; sel = document.selection.createRange; sel.text = myValue; }	//MOZILLA/NETSCAPE support else if(myField.selectionStart || myField.selectionStart == '0') {		var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); }	else {		myField.value += myValue; } }

function getFirstHeading { var elements = getElementsByClass('firstHeading', document.getElementById('content'), 'h1'); return (elements != null && elements.length > 0) ? elements[0] : null; }

/*   Returns the element's nearest parent that has the specified CSS class. function getParentByClass(className, element) { var tester = new ClassTester(className); var node = element.parentNode;

while(node != null && node != document) {		if(tester.isMatch(node)) return node;

node = node.parentNode; }

return null; }

/*   Performs dynamic hover class rewriting to work around the IE6 :hover bug (needs CSS changes as well) function rewriteHover { var gbl = document.getElementById("hover-global");

if(gbl == null) return;

var nodes = getElementsByClass("hoverable", gbl);

for (var i = 0; i < nodes.length; i++) { nodes[i].onmouseover = function { this.className += " over"; }		nodes[i].onmouseout = function { this.className = this.className.replace(new RegExp(" over\\b"), ""); }	} } /************************************************************ * End old Functions.js stuff * Deprecated, most of these functions will be removed slowly ************************************************************/

$( loadFunc );