Чемпион Южной Америки 1916 Чемпион Южной Америки 1917 Чемпион Южной Америки 1920 Чемпион Южной Америки 1923 Олимпийский чемпион и чемпион мира среди любителей 1924 Чемпион Южной Америки 1924 Чемпион Южной Америки 1926 Олимпийский чемпион и чемпион мира среди любителей 1928 Чемпион мира 1930 Чемпион Южной Америки 1935 Чемпион Южной Америки 1942 Чемпион мира 1950 Чемпион Южной Америки 1956 Чемпион Южной Америки 1959 (Эквадор) Чемпион Южной Америки 1967 Победитель Мундиалито 1980-81 Победитель Кубка Америки 1983 Победитель Кубка Америки 1987 Победитель Кубка Америки 1995 Победитель Кубка Америки 2011

MediaWiki:Gadget-UTCLiveClock.js — различия между версиями

Материал из CelestePedia
Перейти к: навигация, поиск
Строка 1: Строка 1:
 
/**
 
/**
  * Warning! Global gadget file!
+
  * Это гаджет из Русской Википедии, список авторов см. на соответствующей странице.
*
+
  * Глобальная версия этого гаджета расположена на [[mw:MediaWiki:Gadget-UTCLiveClock.js]],
* This gadget adds a clock in the personal toolbar that shows the current time
+
  * туда можно заглядывать за обновлениями (но там на 12 октября 2017 года не было некоторых
* in UTC, and also provides a link to purge the current page.
+
  * возможностей, которые есть в РВП и там код рассчитан на загрузку без зависимостей и стилей).
*
 
* Revision: November 2017
 
* Source: https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js
 
*
 
* Installation:
 
*
 
* 1. Copy the JS page at https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.js
 
  * to the page [[MediaWiki:Gadget-UTCLiveClock.js]] on your wiki.
 
  *  
 
  * 2. Copy the CSS page at https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock.css
 
* to the page [[MediaWiki:Gadget-UTCLiveClock.css]] on your wiki.
 
*
 
* 3. Copy the CSS page at https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock-pagestyles.css
 
* to the page [[MediaWiki:Gadget-UTCLiveClock-pagestyles.css]] on your wiki.
 
*
 
* 4. Add a description of the gadget to the page [[MediaWiki:Gadget-UTCLiveClock]]
 
* on your wiki. You can use https://www.mediawiki.org/wiki/MediaWiki:Gadget-UTCLiveClock
 
* as a template.
 
*
 
* 5. Add the following code to your wiki's [[MediaWiki:Gadgets-definition]]:
 
*
 
*    * UTCLiveClock[ResourceLoader|type=general|dependencies=mediawiki.util,mediawiki.api,mediawiki.notify|peers=UTCLiveClock-pagestyles]|UTCLiveClock.js|UTCLiveClock.css
 
*    * UTCLiveClock-pagestyles[hidden|skins=vector,monobook]|UTCLiveClock-pagestyles.css
 
*
 
 
  */
 
  */
/*global mw, $ */
+
( function( mw, $ ) {
mw.loader.using( ['mediawiki.util', 'mediawiki.api', 'mediawiki.notify'] ).then( function () {
+
function padWithZeroes( num ) {
 
+
// Отбить число нулями. Число должно быть натуральным, где 0 <= num < 100.
function padWithZeroes( num ) {
+
return num < 10 ? '0' + num.toString() : num.toString();  
// Pad a number with zeroes. The number must be an integer where
+
}
// 0 <= num < 100.
 
return num < 10 ? '0' + num.toString() : num.toString();  
 
}
 
 
 
function showTime( $target ) {
 
var now = new Date();
 
 
 
// Set the time.
 
var hh = now.getUTCHours();
 
var mm = now.getUTCMinutes();
 
var ss = now.getUTCSeconds();
 
var time = padWithZeroes( hh ) + ':' + padWithZeroes( mm ) + ':' + padWithZeroes( ss );
 
$target.text( time );
 
 
 
// Schedule the next time change.
 
//
 
// We schedule the change for 100 ms _after_ the next clock tick. The delay
 
// from setTimeout is not precise, and if we aim exactly for the tick, there
 
// is a chance that the function will run slightly before it. If this
 
// happens, we will display the same time for two seconds in a row - not
 
// good. By scheduling 100 ms after the tick, we will always be about 100 ms
 
// late, but we are also very likely to display a new time every second.
 
var ms = now.getUTCMilliseconds();
 
setTimeout( function () {
 
showTime( $target );
 
}, 1100 - ms );
 
}
 
 
 
function liveClock() {
 
// Set CSS styles. We do this here instead of on the CSS page because some
 
// wikis load this page directly, without loading the accompanying CSS.
 
mw.util.addCSS( '#utcdate a { font-weight:bolder; font-size:120%; }' );
 
 
 
// Reset whitespace that was set in the peer CSS gadget; this prevents the
 
// effect of the p-personal menu jumping to the left when the JavaScript
 
// loads.
 
$( '.client-js > body.skin-vector #p-personal ul' ).css( 'margin-right', 'initial' );
 
$( '.client-js > body.skin-monobook #p-personal ul' ).css( 'margin-right', 'initial' );
 
  
// Add the portlet link.
+
function showTime( $target ) {
var node = mw.util.addPortletLink(
+
var now = new Date(),
'p-personal',
+
hh = now.getUTCHours(),
mw.util.getUrl( null, { action: 'purge' } ),
+
mm = now.getUTCMinutes(),
'',
+
ss = now.getUTCSeconds(),
'utcdate'
+
time = padWithZeroes( hh ) + ':' + padWithZeroes( mm ) + ':' + padWithZeroes( ss );
);
+
$target.text( time );
if ( !node ) {
 
return;
 
 
}
 
}
  
// Purge the page when the clock is clicked. We have to do this through the
+
runAsEarlyAsPossible( function liveClock() {
// API, as purge URLs now make people click through a confirmation screen.
+
var node = mw.util.addPortletLink(
$( node ).on( 'click', function ( e ) {
+
'p-personal',
new mw.Api().post( { action: 'purge', titles: mw.config.get( 'wgPageName' ) } ).then( function () {
+
mw.util.getUrl( null, { action: 'purge' } ),
location.reload();
+
'',
}, function () {
+
'utcdate'
mw.notify( 'Purge failed', { type: 'error' } );
+
);
 +
if ( !node ) return;
 +
 +
var $link = $( node ).find( 'a:first' );
 +
$link.on( 'click', function ( e ) {
 +
new mw.Api().post( {
 +
action: 'purge',
 +
titles: mw.config.get( 'wgPageName' )
 +
} ).then( function () {
 +
var url = mw.util.getUrl();
 +
if ( e.ctrlKey ) {
 +
if ( !window.open( url ) ) {
 +
location.assign( url );
 +
}
 +
} else {
 +
location.assign( url );
 +
}
 +
}, function () {
 +
mw.notify( 'Не удалось очистить кэш.', { type: 'error' } );
 +
} );
 +
e.preventDefault();
 
} );
 
} );
e.preventDefault();
 
} );
 
 
// Show the clock.
 
showTime( $( node ).find( 'a:first' ) );
 
}
 
  
$( liveClock );
+
showTime( $link );
} );
+
$( '#pt-logout' ).addClass( 'utcdate-added' );
 +
var interval = setInterval( function() {
 +
try {
 +
showTime( $link );
 +
} catch(e) {
 +
clearInterval( interval );
 +
}
 +
}, 1000 );
 +
}, $( '#pt-logout' ) );
 +
}( mediaWiki, jQuery ) );

Версия 16:01, 22 апреля 2018

/**
 * Это гаджет из Русской Википедии, список авторов см. на соответствующей странице.
 * Глобальная версия этого гаджета расположена на [[mw:MediaWiki:Gadget-UTCLiveClock.js]],
 * туда можно заглядывать за обновлениями (но там на 12 октября 2017 года не было некоторых
 * возможностей, которые есть в РВП и там код рассчитан на загрузку без зависимостей и стилей).
 */
( function( mw, $ ) {
	function padWithZeroes( num ) {
		// Отбить число нулями. Число должно быть натуральным, где 0 <= num < 100.
		return num < 10 ? '0' + num.toString() : num.toString(); 
	}

	function showTime( $target ) {
		var now = new Date(),
			hh = now.getUTCHours(),
			mm = now.getUTCMinutes(),
			ss = now.getUTCSeconds(),
			time = padWithZeroes( hh ) + ':' + padWithZeroes( mm ) + ':' + padWithZeroes( ss );
		$target.text( time );
	}

	runAsEarlyAsPossible( function liveClock() {
		var node = mw.util.addPortletLink(
			'p-personal',
			mw.util.getUrl( null, { action: 'purge' } ),
			'',
			'utcdate'
		);
		if ( !node ) return;
		
		var $link = $( node ).find( 'a:first' );
		$link.on( 'click', function ( e ) {
			new mw.Api().post( {
				action: 'purge',
				titles: mw.config.get( 'wgPageName' )
			} ).then( function () {
				var url = mw.util.getUrl();
				if ( e.ctrlKey ) {
					if ( !window.open( url ) ) {
						location.assign( url );
					}
				} else {
					location.assign( url );
				}
			}, function () {
				mw.notify( 'Не удалось очистить кэш.', { type: 'error' } );
			} );
			e.preventDefault();
		} );

		showTime( $link );
		$( '#pt-logout' ).addClass( 'utcdate-added' );
		var interval = setInterval( function() {
			try {
				showTime( $link );
			} catch(e) {
				clearInterval( interval );
			}
		}, 1000 );
	}, $( '#pt-logout' ) );
}( mediaWiki, jQuery ) );