MediaWiki:Common.js

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

/*############################################################################*/ /*########################## Import Script Pages #############################*/ /*############################################################################*/

importScriptPage('ShowHide2/code.js', 'dev');

PurgeButtonText = 'Refresh'; importScriptPage('PurgeButton/code.js', 'dev');

importScriptPage('ArchiveTool/code.js', 'dev');

/*############################################################################*/ /*######################### End Import Script Pages ##########################*/ /*############################################################################*/

/*############################################################################*/ /*################################ Contribs ##################################*/ /*############################################################################*/

/* add contribs to user menu - 2/1/11 */

function UserContribsMenuItem { $('ul.AccountNavigation li:first-child ul.subnav li:first-child').after('Contributions'); } addOnloadHook(UserContribsMenuItem);

/*############################################################################*/ /*############################## End Contribs ################################*/ /*############################################################################*/

/*############################################################################*/ /*########################## History Dropdown Menu ###########################*/ /*############################################################################*/

/* add history to the dropdown menu for pages - 3/8/11 */ function HistoryDropdownMenuItem { if ($('ul.wikia-menu-button').length === 0) { $('#WikiaPageHeader a.wikia-button').removeClass('wikia-button').wrap('').wrap(''); $('ul.wikia-menu-button').append(''); }		$('ul.wikia-menu-button ul').append('History'); } addOnloadHook(HistoryDropdownMenuItem);

/*############################################################################*/ /*####################### End History Dropdown Menu ##########################*/ /*############################################################################*/

/*############################################################################*/ /*########################## Custom Edit Buttons #############################*/ /*############################################################################*/

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/__cb20090417031658/central/images/e/ea/Button_align_left.png", "speedTip": "Align Left", "tagOpen": " ", "tagClose": " ", "sampleText": "Insert text here"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images1.wikia.nocookie.net/__cb20110320004360/toontown/images/5/5f/Button_center.png", "speedTip": "Center", "tagOpen": " ", "tagClose": " ", "sampleText": "Insert text here"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images1.wikia.nocookie.net/__cb20081020112020/central/images/a/a5/Button_align_right.png", "speedTip": "Align Right", "tagOpen": " ", "tagClose": " ", "sampleText": "Insert text here"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images4.wikia.nocookie.net/__cb20070329064322/central/images/8/88/Btn_toolbar_enum.png", "speedTip": "Number Listing", "tagOpen": "#", "tagClose": " ", "sampleText": "Number Listing(Steps)"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/__cb20070329064828/central/images/1/11/Btn_toolbar_liste.png", "speedTip": "Bullet Points", "tagOpen": "*", "tagClose": " ", "sampleText": "Bullet Points"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/toontown/images/8/8e/Button_shifting.png", "speedTip": "Indent", "tagOpen": ":", "tagClose": " ", "sampleText": "Insert Text Here"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/__cb20070329064959/central/images/e/e9/Button_headline2.png", "speedTip": "Headline 2", "tagOpen": "==", "tagClose": "==", "sampleText": "Headline 2"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/__cb20070329064925/central/images/3/3a/Button_headline3.png", "speedTip": "Headline 3", "tagOpen": "===", "tagClose": "===", "sampleText": "Headline 3"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images4.wikia.nocookie.net/__cb20070329065007/central/images/0/08/Button_headline4.png", "speedTip": "Headline 4", "tagOpen": "====", "tagClose": "====", "sampleText": "Headline 4"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/__cb20100328145146/central/images/c/c1/Button_Bold_Italic.PNG", "speedTip": "Bold-Italics", "tagOpen": "'", "tagClose": "'", "sampleText": "Bold-Italics"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images4.wikia.nocookie.net/toontown/images/8/89/Button_bigger.png", "speedTip": "Large Text", "tagOpen": " ", "tagClose": " ", "sampleText": "Big Text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images1.wikia.nocookie.net/toontown/images/0/0d/Button_smaller.png", "speedTip": "Small Text", "tagOpen": " ", "tagClose": " ", "sampleText": "Small Text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/central/images/f/fd/Button_underline.png", "speedTip": " Underline Selected Text ", "tagOpen": " ", "tagClose": " ", "sampleText": "Text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/c/c9/Button_strike.png", "speedTip": "Strike", "tagOpen": " ", "tagClose": " ", "sampleText": "Strike-through"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/__cb20091011135213/central/images/3/31/HighlightButton.png", "speedTip": "Highlight", "tagOpen": " ", "tagClose": " ", "sampleText": "Highlighted text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/__cb20081020115414/central/images/0/0c/Button_Link_DifferentName.png", "speedTip": "Different Name", "tagOpen": "",    "tagClose": "", "sampleText": "Different Name"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/__cb20080208025054/central/images/2/29/Button_user.png", "speedTip": "User", "tagOpen": "User:",    "tagClose": "", "sampleText": "User"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/__cb20090511022919/central/images/f/fc/Button_user_talk.png", "speedTip": "User talk", "tagOpen": "User talk:",    "tagClose": "", "sampleText": "User Talk"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images1.wikia.nocookie.net/toontown/images/b/b4/Button_category03.png", "speedTip": "Category", "tagOpen": "[[Category:",    "tagClose": "]]", "sampleText": "Category"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images4.wikia.nocookie.net/toontown/images/b/b0/Button_category02.png", "speedTip": "Category Link", "tagOpen": "Category:",    "tagClose": "", "sampleText": "Category"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/toontown/images/e/eb/Button_plantilla.png", "speedTip": "Template", "tagOpen": "", "sampleText": "Template"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/toontown/images/9/96/Button_interwiki.png", "speedTip": "Interwiki", "tagOpen": "w:c:",    "tagClose": "", "sampleText": "Interwiki link"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/7/74/Button_comment.png", "speedTip": "Comment visible only for editors", "tagOpen": "", "sampleText": "Insert comment here"}

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images3.wikia.nocookie.net/central/images/a/a7/ButtonYouTube.png", "speedTip": "Embed a YouTube Video", "tagOpen": " ", "tagClose": " ", "sampleText": "Video File"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/central/images/4/47/Button_redir.png", "speedTip": "Redirect", "tagOpen": "#REDIRECT ",    "tagClose": "", "sampleText": "Insert text"};

/*############################################################################*/ /*######################### End Custom Edit Buttons###########################*/ /*############################################################################*/

// ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // ************************************************** // // Usage example: // //  Only January 01 2007 00:00:00 PST until New years. // //  Javascript disabled.

function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000);

// catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; }

// determine plus/minus if(diff<0) { diff = -diff; var tpm = ' '; } else { var tpm = ' '; }

// calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = tpm + left;

// a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); }

function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for(var i in nocountdowns) nocountdowns[i].style.display = 'none' var countdowns = getElementsByClassName(document, 'span', 'countdown'); for(var i in countdowns) countdowns[i].style.display = 'inline'

//set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if(timers.length == 0) return; for(var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up  } } addOnloadHook(checktimers);

// ************************************************** // - end -  Experimental javascript countdown timer // **************************************************

// ============================================================ // displayTimer - 2/1/11 // ============================================================ //Add a clock to the WikiHeader //Modified from work by Patrick Westerhoff [poke]: //http://bulbapedia.bulbagarden.net/wiki/MediaWiki:Monobook.js hookEvent( 'load', displayTimer ); function displayTimer {   if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false ) return; var date; if (skin == 'oasis') {   var timerParent = document.getElementById( 'WikiHeader' ).getElementsByTagName( 'div' )[0]; }   if (skin == 'monobook') {   var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0]; }   var timerLink   = document.createElement( 'a' ); var timerObj   = document.createElement( 'li' ); timerLink.href              = '/wiki/' + wgPageName + '?action=purge'; timerLink.title             = 'Purge the server cache and update the contents of this page.' timerObj.id                 = 'displayTimer'; timerObj.style.textTransform = 'none'; timerObj.style.fontWeight   = 'bold'; timerObj.style.fontSize     = '100%'; timerObj.appendChild( timerLink ); timerParent.insertBefore( timerObj, timerParent.firstChild ); if (skin == 'oasis') {       $('#displayTimer').css({'position': "inherit", 'right': "0px", 'top': "-28px"}); }   var month = new Array(12); month[0] = "Jan"; month[1] = "Feb"; month[2] = "Mar"; month[3] = "Apr"; month[4] = "May"; month[5] = "Jun"; month[6] = "Jul"; month[7] = "Aug"; month[8] = "Sep"; month[9] = "Oct"; month[10] = "Nov"; month[11] = "Dec"; function actualizeUTC {       timerDate           = new Date; timerLink.innerHTML = ( timerDate.getUTCDate    < 10 ? '0' : '' ) + timerDate.getUTCDate     + ' ' + ( timerDate.getUTCMonth   < 10 ?  :   ) + month[timerDate.getUTCMonth] + ' ' + ( timerDate.getUTCFullYear < 10 ? '0' : '' ) + timerDate.getUTCFullYear + ' ' + ( timerDate.getUTCHours   < 10 ? '0' : '' ) + timerDate.getUTCHours    + ':' + ( timerDate.getUTCMinutes < 10 ? '0' : '' ) + timerDate.getUTCMinutes  + ':' + ( timerDate.getUTCSeconds < 10 ? '0' : '' ) + timerDate.getUTCSeconds  + ' (UTC)'; }   function actualizeCustom {       timerDate           = new Date; timerDate.setMinutes ( timerDate.getMinutes + timerDate.getTimezoneOffset + timerTimezone * 60 ); timerLink.innerHTML = ( timerDate.getDate    < 10 ? '0' : '' ) + timerDate.getDate     + ' ' + ( timerDate.getMonth   < 10 ?  :   ) + month[timerDate.getMonth] + ' ' + ( timerDate.getFullYear < 10 ? '0' : '' ) + timerDate.getFullYear + ' ' + ( timerDate.getHours   < 10 ? '0' : '' ) + timerDate.getHours    + ':' + ( timerDate.getMinutes < 10 ? '0' : '' ) + timerDate.getMinutes  + ':' + ( timerDate.getSeconds < 10 ? '0' : '' ) + timerDate.getSeconds + ' (UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')'; }   // start if ( typeof( timerTimezone ) !== 'number' ) {       actualizeUTC; setInterval( actualizeUTC, 1000 ); }   else {       actualizeCustom; setInterval( actualizeCustom, 1000 ); } }

/* End */

/** 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); }; });

/** Collapsible tables (From wikipedia:MediaWiki:Common.js ******************************* * * Description: Allows tables to be collapsed, showing only the header. See *               NavFrame. *  Maintainers: User:R. Koot */ 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.className = "collapseButton"; //Styles are declared in Common.css ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); addHandler( ButtonLink, "click", new Function( "evt", "collapseTable(" + tableIndex + " ); return killEvt( evt );") ); 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 ); }        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) { var element = NavigationBoxes[i]; while (element = element.parentNode) { if ( hasClass( element, "outercollapse" ) ) { collapseTable ( i ); break; }           }        }    } } addOnloadHook( createCollapseButtons );