Wikisłownikarz:Zan-mir/common.js: Różnice pomiędzy wersjami

Z Wikisłownika – wolnego słownika wielojęzycznego
Usunięta treść Dodana treść
Nie podano opisu zmian
{{nazwa systematyczna}}
Linia 44: Linia 44:
.appendTo( $container );
.appendTo( $container );


addButton( '{{nazwa systematyczna}}', '{{nazwa systematyczna}}' , '{{nazwa systematyczna}}' );
addButton( 'link fix', 'Korekta linku' , 'link fix' );
addButton( 'link fix', 'Korekta linku' , 'link fix' );
addButton( 'numer fix', 'Korekta numeracji' , 'korekta numeracji' );
addButton( 'numer fix', 'Korekta numeracji' , 'korekta numeracji' );

Wersja z 17:30, 1 mar 2021

/**
 * Skopiowane z MediaWiki:Gadget-edit-summaries.js i zmodyfikowane opisy zmian na własne potrzeby
 * Automatyczne opisy zmian
 * @author [[w:pl:User:Adziura|Adam Dziura]]
 * @author (fixes) [[w:pl:User:Nux|Maciej Jaros]]
 * @author (migration to plwikt) [[wikt:pl:User:Peter Bowman]]
 */

var config = mw.config.get( [
		'wgAction',
		'wgNamespaceNumber'
	] ),
	modules = [ 'ext.gadget.style-summary-buttons' ],
	editformHook = mw.hook( 'wikipage.editform' ),
	usbHook = mw.hook( 'user-summary-buttons.configured' );

function configureUserButtons( $container, $textarea ) {
	$container.on( 'click', '.userSummaryButtonsElement', function ( e ) {
		var action = $( this ).data( 'action' );
		
		if ( typeof action === 'string' ) {
			addSummary( $textarea, action );
		} else {
			action( $container );
		}
		
		return false;
	} );
	
	$( '<a>' )
		.text( 'zwiń/rozwiń' )
		.addClass( 'userSummaryButtonsToggle' )
		.attr( 'title', 'Rozwiń skróty opisów zmian' )
		.on( 'click', function ( e ) {
			$container.children( '.userSummaryButtonsElement' ).each( function ( i, button ) {
				var $button = $( button ),
					currentText = $button.text();
				
				$button.text( $button.data( 'toggle' ) ).data( 'toggle', currentText );
			} );
			
			return false;
		} )
		.appendTo( $container );

	addButton( '{{nazwa systematyczna}}', '{{nazwa systematyczna}}' , '{{nazwa systematyczna}}' );	
	addButton( 'link fix', 'Korekta linku' , 'link fix' );	
	addButton( 'numer fix', 'Korekta numeracji' , 'korekta numeracji' );
	addButton( 'odmiana', 'odmiana' , 'odmiana' );
	addButton( 'przykład', 'przykład' , '+przykład' );
	addButton( 'kategoryzacja regionalizmów', 'regionalizmy' , 'rekategoryzacja regionalizmów' );
	addButton( 'związek zgody', 'związek zgody' , '{{zw zg}}}}' );
	addButton( 'związek rządu', 'związek rządu' , '{{zw rz}}}}' );
	addButton( 'brak na Commons', 'brak na commons' , 'brak pliku na Commons' );
	addButton( 'brak na Wikipedii', 'brak na wikipedii' , 'brak strony na Wikipedii' );
	addButton( 'wikipedia', 'wikipedia' , '+{{wikipedia}}' );	
	addButton( 'foto', 'Grafika' , '+foto' );	
	addButton( 'nowe hasło', 'Dodano nowe hasło' , 'nowe hasło' );
	addButton( 'komentarz', 'Dodano komentarz' );
	addButton( 'ek', 'EK', 'EK' );
	addButton( 'revert', 'przywrócenie poprzedniej wersji', 'revert' );
}

function addButton( text, title, action, cssClass ) {
	usbHook.add( function ( $container ) {
		$( '<a>' )
			.text( text )
			.attr( 'title', title )
			.addClass( 'userSummaryButtonsElement' )
			.addClass( cssClass )
			.data( {
				action: action || text,
				toggle: title
			} )
			.appendTo( $container.append( '&#8203;' ) );
	} );
}

function addSummary( $textarea, summary ) {
	var content = $textarea.val().trim();
	
	if ( content.indexOf( summary ) !== -1 ) {
		return;
	}
	
	if ( content ) {
		if ( content.charAt( content.length - 1 ) === '/' ) {
			content += ' ' + summary;
		} else {
			content += ', ' + summary;
		}
	} else {
		content += summary;
	}
	
	$textarea.val( content ).trigger( 'change' );
}

function editformHookCallback( $editform ) {
	var $container;
	
	if ( $editform.find( '#wpSummaryLabel' ).closest( '.editOptions' ).length ) {
		$container = $( '<div>' ).attr( 'id', 'userSummaryButtons' );
		configureUserButtons( $container, $editform.find( '#wpSummary' ) );
		$editform.find( '#wpSummaryWidget' ).append( $container );
		usbHook.fire( $container );
	}
	
	editformHook.remove( editformHookCallback );
}

if ( [ 'edit', 'submit' ].indexOf( config.wgAction ) !== -1 ) {
	if ( config.wgNamespaceNumber > -1 ) {
		mw.loader.using( modules ).done( function () {
			editformHook.add( editformHookCallback );
		} );
	}
}

mw.loader.using( 'ext.visualEditor.desktopArticleTarget.init' ).done( function () {
	mw.libs.ve.addPlugin( function () {
		return mw.loader.using( [].concat( modules, 'ext.visualEditor.mwcore' ) ).done( function () {
			var realInitialize = ve.ui.MWSaveDialog.prototype.initialize;
			
			ve.ui.MWSaveDialog.prototype.initialize = function () {
				var $container = $( '<span>' ).attr( 'id', 'userSummaryButtons' );
				realInitialize.call( this );
				$container.insertAfter( this.editSummaryInput.$element );
				configureUserButtons( $container, this.editSummaryInput.$element.children( 'textarea' ) );
				usbHook.fire( $container );
			};
		} );
	} );
} );

module.exports = {
	addButton: addButton
};