مدیاویکی:Gadget-UTCLiveClock.js: تفاوت بین نسخهها
از پژوهشکده امر به معروف
(صفحهای تازه حاوی «// Warning! Global gadget file! ( function ( mw, $ ) { var $target; function showTime( $target ) { var dateNode = UTCLiveClockConfig.nod...» ایجاد کرد) |
|||
| سطر ۱: | سطر ۱: | ||
| − | / | + | /* Warning! Global gadget file! */ |
| − | ( function ( | + | ( function( $, undefined ) { |
| − | + | ||
var $target; | 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 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 ); | ||
| + | time = time .replace(/1/g, "۱").replace(/2/g, "۲").replace(/3/g, "۳").replace(/4/g, "۴").replace(/5/g, "۵"); | ||
| + | time = time .replace(/6/g, "۶").replace(/7/g, "۷").replace(/8/g, "۸").replace(/9/g, "۹").replace(/0/g, "۰")+'ساعت جهانی'; | ||
$target.text( time ); | $target.text( time ); | ||
| − | + | ||
| − | + | setTimeout( function(){ | |
| − | + | showTime( $target ); | |
| − | setTimeout( function () { | + | }, 1000 ); |
| − | showTime( $target ); | + | |
| − | }, | + | |
} | } | ||
| − | + | ||
function liveClock() { | function liveClock() { | ||
| − | + | //appendCSS( '#utcdate a { font-weight:bolder; }' ); | |
| − | + | ||
if ( window.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 ) : ( document.getElementById( 'pt-flyout' ) || undefined ); |
UTCLiveClockConfig.node = mw.util.addPortletLink( | UTCLiveClockConfig.node = mw.util.addPortletLink( | ||
portletId, | portletId, | ||
| − | mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( mw.config.get( 'wgPageName' ) ) + '&action=purge', | + | mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( mw.config.get('wgPageName') ) + '&action=purge', |
'', | '', | ||
'utcdate', | 'utcdate', | ||
| − | + | undefined, | |
| − | + | undefined, | |
nextNode | nextNode | ||
); | ); | ||
| − | if ( !UTCLiveClockConfig.node ) { | + | if( !UTCLiveClockConfig.node ) { |
return; | return; | ||
} | } | ||
| − | + | ||
showTime(); | showTime(); | ||
} | } | ||
| − | $( liveClock ); | + | $( document ).ready( liveClock ); |
| − | + | ||
| − | } )( | + | } )( jQuery ); |
نسخهٔ کنونی تا ۱۱ اسفند ۱۳۹۴، ساعت ۱۲:۱۴
/* Warning! Global gadget file! */
( function( $, undefined ) {
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 );
time = time .replace(/1/g, "۱").replace(/2/g, "۲").replace(/3/g, "۳").replace(/4/g, "۴").replace(/5/g, "۵");
time = time .replace(/6/g, "۶").replace(/7/g, "۷").replace(/8/g, "۸").replace(/9/g, "۹").replace(/0/g, "۰")+'ساعت جهانی';
$target.text( time );
setTimeout( function(){
showTime( $target );
}, 1000 );
}
function liveClock() {
//appendCSS( '#utcdate a { font-weight:bolder; }' );
if ( window.UTCLiveClockConfig === undefined ) {
window.UTCLiveClockConfig = {};
}
var portletId = UTCLiveClockConfig.portletId || 'p-personal';
var nextNode = UTCLiveClockConfig.nextNodeId ? document.getElementById( UTCLiveClockConfig.nextNodeId ) : ( document.getElementById( 'pt-flyout' ) || undefined );
UTCLiveClockConfig.node = mw.util.addPortletLink(
portletId,
mw.config.get( 'wgScript' ) + '?title=' + encodeURIComponent( mw.config.get('wgPageName') ) + '&action=purge',
'',
'utcdate',
undefined,
undefined,
nextNode
);
if( !UTCLiveClockConfig.node ) {
return;
}
showTime();
}
$( document ).ready( liveClock );
} )( jQuery );






