MediaWiki:Gadget-blpEditNotice.js

Материал из Универсал-вики
Перейти к навигации Перейти к поиску

Замечание. Возможно, после сохранения вам придётся очистить кэш своего браузера, чтобы увидеть изменения.

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl-F5 или Ctrl-R (⌘-R на Mac)
  • Google Chrome: Нажмите Ctrl-Shift-R (⌘-Shift-R на Mac)
  • Internet Explorer: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl-F5
  • Opera: Перейдите в Menu → Настройки (Opera → Настройки на Mac), а затем Безопасность → Очистить историю посещений → Кэшированные изображения и файлы
// Magic editintros by [[:en:User:RockMFR]] & [[:ru:User:Jack who built the house]] (VE part)
( function () {

function addVeEditNotice( code ) {
	var target = ve.init.target;
	var actionsToolbar = target.actionsToolbar;
	var wasNoEditNotices = !actionsToolbar.tools.notices;
	if ( wasNoEditNotices ) {
		if ( actionsToolbar.items[ 0 ] &&
			actionsToolbar.items[ 0 ].items &&
			actionsToolbar.items[ 0 ].items[ 1 ] &&
			actionsToolbar.items[ 0 ].items[ 1 ] instanceof ve.ui.MWNoticesPopupTool &&
			actionsToolbar.items[ 0 ].items[ 0 ] &&
			actionsToolbar.items[ 0 ].items[ 0 ] instanceof ve.ui.MWHelpPopupTool
		) {
			var noticesPopupTool = new ve.ui.MWNoticesPopupTool( actionsToolbar.items[ 0 ] );
			actionsToolbar.tools.notices = actionsToolbar.items[ 0 ].items[ 1 ] = noticesPopupTool;
			noticesPopupTool.$element.insertAfter( $( '.oo-ui-tool-name-help' ) );
			actionsToolbar.connect( noticesPopupTool, {
				updateState: 'onUpdateState'
			} );
		} else {
			console.error( 'Unable to add the edit notice tool to the VisualEditor toolbar' );
			return;
		}
	}
	target.remoteNotices.unshift( code );
	target.editNotices.unshift( code );
	actionsToolbar.tools.notices.setNotices( target.getEditNotices() );
	if ( wasNoEditNotices ) {
		// setTimeout for IE
		setTimeout( function () {
			actionsToolbar.tools.notices.getPopup().toggle( true );
		}, 0 );
	}
}

function addEditIntro( name ) {
	$( '.mw-editsection, #ca-edit, #ca-ve-edit' ).find( 'a' ).each( function ( i, el ) {
		el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
	} );

	if ( mw.util.getParamValue( 'editintro' ) !== name ) {
		var editNoticeLoaded = false;
		mw.libs.ve.addPlugin( function () {
			if ( !editNoticeLoaded ) {
				new mw.Api().get( {
					action: 'parse',
					page: name,
					prop: 'text',
					formatversion: 2,
				} ).done( function ( data ) {
					if ( data && data.parse && data.parse.text !== undefined ) {
						editNoticeLoaded = true;
						if ( data.parse.text ) {
							mw.hook( 've.activationComplete' ).add( function () {
								addVeEditNotice( data.parse.text );
							} );
						}
					}
				} );
			}
		} );
	}
}

if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
	runAsEarlyAsPossible( function () {
		var cats = mw.config.get( 'wgCategories' );
		if ( !cats ) return;
		if ( $.inArray( 'Википедия:Биографии современников', cats ) !== -1 ) {
			addEditIntro( 'Шаблон:Editnotice/Ныне_живущие' );
		} else if ( $.inArray( 'Персоналии, умершие менее года назад', cats ) !== -1 ) {
			addEditIntro( 'Шаблон:Editnotice/Недавно_умершие' );
		}
	}, $( '#ca-history' ) );
}

}() );