Difference between revisions of "MediaWiki:Gadget-UTCLiveClock.js"

From translatewiki.net
Jump to navigation Jump to search
(almost forgot: imported fromhttp://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js)
(jQuery- and RL-compliant version :))
Line 1: Line 1:
function liveClock() {
+
(function( $ ) {
  +
$( document ).ready( function() {
appendCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
 
  +
appendCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
   
if ( typeof( UTCLiveClockConfig ) == 'undefined' ) {
+
if ( typeof( window.UTCLiveClockConfig ) == 'undefined' ) {
UTCLiveClockConfig = {};
+
window.UTCLiveClockConfig = {};
}
+
}
  +
window.liveClock = {};
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
 
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
+
var portletId = window.UTCLiveClockConfig.portletId || 'p-personal';
  +
var nextNode = window.UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
liveClock.node = addPortletLink(
 
  +
window.liveClock.node = addPortletLink(
portletId,
 
  +
portletId,
wgScript + '?title=' + encodeURIComponent( wgPageName ) + '&action=purge',
 
  +
wgScript + '?title=' + encodeURIComponent( wgPageName ) + '&action=purge',
'',
 
'utcdate',
+
'',
undefined,
+
'utcdate',
undefined,
+
undefined,
  +
undefined,
nextNode
 
  +
nextNode
);
 
  +
);
if( !liveClock.node ) {
 
  +
if( !window.liveClock.node ) {
return;
 
  +
return;
}
 
  +
}
   
showTime();
+
window.showTime();
}
+
});
  +
})( jQuery );
addOnloadHook( liveClock );
 
   
function showTime() {
+
window.showTime = function() {
var dateNode = liveClock.node;
+
var dateNode = window.liveClock.node;
 
if( !dateNode ) {
 
if( !dateNode ) {
 
return;
 
return;
Line 37: Line 39:
 
dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );
 
dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );
   
window.setTimeout( showTime, 1000 );
+
window.setTimeout( window.showTime, 1000 );
 
}
 
}

Revision as of 20:01, 11 November 2010

(function( $ ) {
	$( document ).ready( function() {
		appendCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );

		if ( typeof( window.UTCLiveClockConfig ) == 'undefined' ) {
			window.UTCLiveClockConfig = {};
		}
		window.liveClock = {};
		var portletId = window.UTCLiveClockConfig.portletId || 'p-personal';
		var nextNode = window.UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
		window.liveClock.node = addPortletLink(
			portletId,
			wgScript + '?title=' + encodeURIComponent( wgPageName ) + '&action=purge',
			'',
			'utcdate',
			undefined,
			undefined,
			nextNode
		);
		if( !window.liveClock.node ) {
			return;
		}

		window.showTime();
	});
})( jQuery );

window.showTime = function() {
	var dateNode = window.liveClock.node;
	if( !dateNode ) {
		return;
	}

	var now = new Date();
	var hh = now.getUTCHours();
	var mm = now.getUTCMinutes();
	var ss = now.getUTCSeconds();
	var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
	dateNode.firstChild.replaceChild( document.createTextNode( time ), dateNode.firstChild.firstChild );

	window.setTimeout( window.showTime, 1000 );
}