MediaWiki:Common.js

/*BEGIN UTC CLOCK

Modifications: Added timerTimezoneLabel, timer now displays (TIMEZONE UTC-X) if this is set. - RJackson, Aug 19th 2011



/** additional monobook scripts **/ hookEvent( 'load', displayTimer );

/**** function displayTimer.js * by Patrick Westerhoff [poke] */ function displayTimer { if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false ) return; /* Time-zone settings */ var timerTimezone = -5;       /* Leave blank for UTC */ var timerTimezoneLabel = "CDT"; /* Leave blank to display "(UTC)" or "(UTC-X)". Fill in to display "(TIMEZONE UTC-X)" */

var date; 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                 = 'pt-timer'; timerObj.style.textTransform = 'none'; timerObj.appendChild( timerLink ); timerParent.insertBefore( timerObj, timerParent.firstChild ); function actualizeUTC {   timerDate           = new Date; timerLink.innerHTML = ( 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.getHours  < 10 ? '0' : '' ) + timerDate.getHours   + ':' + ( timerDate.getMinutes < 10 ? '0' : '' ) + timerDate.getMinutes + ':' + ( timerDate.getSeconds < 10 ? '0' : '' ) + timerDate.getSeconds + ' (' + ( timerTimezoneLabel != null ? timerTimezoneLabel + ', ' : '' ) + 'UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')'; } // start if ( typeof( timerTimezone ) !== 'number' ) {   actualizeUTC; setInterval( actualizeUTC, 1000 ); } else {   actualizeCustom; setInterval( actualizeCustom, 1000 ); } } /*END UTC CLOCK*/

// Start overly-complicated collapsible tables // Todo: jQuery this thing /** Collapsible tables ********************************************************* * *  Description: Allows tables to be collapsed, showing only the header. See *              NavFrame. * Maintainers: User:R. Koot */ var hasClass = (function {    var reCache = {};    return function (element, className) {        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);   }; });

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"; 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 ); }    } } $(createCollapseButtons);

// End collapsible tables

// Mouseover trick for multi-image item infoboxes $("#itemsmallimages img").mouseover(function {          $("#itemmainimage img:first").attr('src', $(this).attr('src'));       }   );

// Fancy diffs var fancyDiffs = { isBigDiff: false, isBigDiffThreshold: 72, toggle: function(element) { var expanded = element.hasClass('diff-expanded'); var contents = element.parent.children('.diff-contents'); if(expanded) { // Just collapse then element.removeClass('diff-expanded'); if(fancyDiffs.isBigDiff) { contents.hide; } else { contents.slideUp('fast'); }		} else if(element.hasClass('diff-data-loaded')) { // Stuff is already loaded, expand element.addClass('diff-expanded'); contents.slideDown('fast'); } else if(!element.hasClass('diff-data-requested')) { // Stuff is not loaded element.addClass('diff-data-requested'); var fileName = element.find('span').text.replace(/^\s+|\s+$/g); var patchName = element.closest('.diffname'); var diffName = wgPageName; if(patchName && patchName.length && patchName.attr('class')) { diffName = patchName.attr('class').substr(9); }			$.get('/?title=Template:PatchDiff/' + encodeURIComponent(diffName.replace(/^Template:PatchDiff\//, '')) + '/' + encodeURIComponent(fileName) + '&action=raw', function(data) {				contents.html(data);				if(fancyDiffs.isBigDiff) {					contents.show;				} else {					contents.slideDown('fast');				}				element.removeClass('diff-data-requested').addClass('diff-data-loaded').addClass('diff-expanded');			}); }	},	init: function { var diffText = $('.diff-name-text'); if(diffText.length) { // Preload leetle gif $('body').append($(' ').attr('src', '/images/4/43/Patch_diff_loading.gif').css('display', 'none')); diffText.find('span').each(function {				$(this).text($(this).find('a').text.replace(/^\s+|\s+$/g));			}); diffText.click(function {				fancyDiffs.toggle($(this));				return false;			}); fancyDiffs.isBigDiff = $('.diff-file').length > fancyDiffs.isBigDiffThreshold; }	} }; $(fancyDiffs.init);

// End fancy diffs

// Wiki-logo correct lang links var languages = ["ar", "cs", "da", "de", "el", "es", "fi", "fr", "hu", "it", "ja", "ko", "nl", "no", "pl", "pt", "pt-br", "ro", "ru", "sv", "th", "tr", "zh-hans", "zh-hant"];

var lang = /\/([a-z-]+)\/?$/.exec(location.href)[1];

if (lang && languages.indexOf(lang) != -1) { var logolink = $("#p-logo a"); logolink.attr("href", logolink.attr("href") + "/" + lang); } // End Wiki-logo correct lang links