MediaWiki:Gadget-block.js

Z Wikipedii, wolnej encyklopedii

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
// UWAGA! Z tego gadżetu korzystają także inne projekty
// Style CSS → [[Mediawiki:Common.css]] ↓
// ID #userSummaryButtons
// Autor: [[User:Beau]]

window.blockGadget = {
	version: 4,

	init: function() {
		var that = this;

		if ( mw.config.get( "wgCanonicalSpecialPageName" ) != 'Blockip' && mw.config.get( "wgCanonicalSpecialPageName" ) != 'Block' ) {
			return;
		}

		jQuery( "#wpAllowUsertalk" ).attr( 'checked', false );
		jQuery( "#mw-input-wpDisableUTEdit" ).attr( 'checked', true );

		var wpBlockExpiry = document.querySelector( '[name=wpExpiry]' );
		var wpBlockOther = document.querySelector( '[name=wpExpiry-other]' );

		if ( !wpBlockExpiry ) {
			return;
		}

		var td = document.getElementById( 'mw-htmlform-expiry' ).parentNode;
		var expContainer = document.createElement('div');
		expContainer.style.padding = '3px';
		expContainer.className = 'userSummaryButtons';
		
		td.appendChild( expContainer );

		for ( var caption in bk$times ) {
			var newButton = document.createElement('a');

			// atrybuty
			newButton.title = bk$times[caption];
			newButton.onclick = function() { that.selectItem( wpBlockExpiry, wpBlockOther, this.title ); };
			newButton.appendChild( document.createTextNode( caption ) );

			// dodanie przycisku
			expContainer.appendChild( newButton );
		}

		var wpBlockReasonList = document.querySelector( '[name=wpReason]' );
		var wpBlockOtherReason = document.querySelector( '[name=wpReason-other]' );

		td = document.getElementById( 'mw-htmlform-reason' ).parentNode;
		
		var summContainer = document.createElement('div');
		summContainer.style.padding = '3px';
		summContainer.className = 'userSummaryButtons';
		
		td.appendChild( summContainer );
		
		for ( var i in bk$reasons ) {
			var item = bk$reasons[i];
			var newButton = document.createElement( 'a' );

			// atrybuty
			newButton.item = item;
			newButton.title = item.reason;
			newButton.onclick = function() {
				that.selectItem( wpBlockReasonList, wpBlockOtherReason, this.title );
				if ( this.item.callback ) {
					this.item.callback( item );
				}
			};
			newButton.appendChild( document.createTextNode( item.caption ) );

			// dodanie przycisku
			summContainer.appendChild( newButton );
		}
	},

	selectItem: function( wpBlockExpiry, wpBlockOther, value ) {
		var listed = false;
		for ( var i = 0; i < wpBlockExpiry.options.length; i++ ) {
			if ( wpBlockExpiry.options[i].value == value ) {
				listed = true;
			}
		}
		if ( listed ) {
			wpBlockExpiry.value = value;
			$( wpBlockExpiry ).change();
		}
		else {
			wpBlockExpiry.value = 'other';
			$( wpBlockExpiry ).change();
			wpBlockOther.value = value;
		}
	}
};

jQuery(document).ready(function() {
        blockGadget.init();
});