MediaWiki:Gadget-UTCLiveClock.js: Różnice pomiędzy wersjami

Z Almanach
Nie podano opisu zmian
mNie podano opisu zmian
Linia 1: Linia 1:
/* Warning! Global gadget file! */
// Warning! Global gadget file!
( function( $, undefined ) {
( function ( mw, $ ) {
 
var $target;
 
function showTime( $target ) {
function showTime( $target ) {
var dateNode = UTCLiveClockConfig.node;
var dateNode = UTCLiveClockConfig.node;
if( !dateNode ) {
if ( !dateNode ) {
return;
return;
}
}
 
var now = new Date();
var now = new Date();
var hh = now.getUTCHours();
var hh = now.getUTCHours();
var mm = now.getUTCMinutes();
var mm = now.getUTCMinutes();
var ss = now.getUTCSeconds();
var ss = now.getUTCSeconds();
if ( typeof $target === 'undefined' ) {
if ( $target === undefined ) {
$target = $( dateNode ).find( 'a:first' );
$target = $( dateNode ).find( 'a:first' );
}
}
var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
$target.text( time );
$target.text( time );
 
setTimeout( function(){
        var ms = now.getUTCMilliseconds();
showTime( $target );
 
}, 1000 );
setTimeout( function () {
showTime( $target );
}, 1100 - ms );
}
}
 
function liveClock() {
function liveClock() {
appendCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
mw.util.addCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
 
if ( typeof( UTCLiveClockConfig ) === 'undefined' ) {
if ( window.UTCLiveClockConfig === undefined ) {
window.UTCLiveClockConfig = {};
window.UTCLiveClockConfig = {};
}
}
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : undefined;
UTCLiveClockConfig.node = addPortletLink(
UTCLiveClockConfig.node = mw.util.addPortletLink(
portletId,
portletId,
wgScript + '?title=' + encodeURIComponent( wgPageName ) + '&action=purge',
mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&action=purge',
'',
'',
'utcdate',
'utcdate',
undefined,
null,
undefined,
null,
nextNode
nextNode
);
);
if( !UTCLiveClockConfig.node ) {
if ( !UTCLiveClockConfig.node ) {
return;
return;
}
}
 
showTime();
showTime();
}
}
$( document ).ready( liveClock );
$( liveClock );
 
} )( jQuery );
} )( mediaWiki, jQuery );

Wersja z 00:03, 8 gru 2015

// Warning! Global gadget file!
( function ( mw, $ ) {

var $target;

function showTime( $target ) {
	var dateNode = UTCLiveClockConfig.node;
	if ( !dateNode ) {
		return;
	}

	var now = new Date();
	var hh = now.getUTCHours();
	var mm = now.getUTCMinutes();
	var ss = now.getUTCSeconds();
	if ( $target === undefined ) {
		$target = $( dateNode ).find( 'a:first' );
	}
	var time = ( hh < 10 ? '0' + hh : hh ) + ':' + ( mm < 10 ? '0' + mm : mm ) + ':' + ( ss < 10 ? '0' + ss : ss );
	$target.text( time );

        var ms = now.getUTCMilliseconds();

	setTimeout( function () {
		showTime( $target );
	}, 1100 - ms );
}

function liveClock() {
	mw.util.addCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );

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

	showTime();
}
$( liveClock );

} )( mediaWiki, jQuery );