MediaWiki:Gadget-edittools-enhanced.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.
// reformat the edit tools (below edit form)

mw.loader.using('ext.gadget.gConfig', function() {
	gConfig.register('edittools-enhanced', 'Zwijanie narzędzi edycyjnych pod polem edycji', [
		{
			name: 'section-shown',
			desc: 'Numer domyślnie rozwiniętej sekcji (0 – pokaż wszystkie).',
			type: 'integer',
			deflt: 1
		}
	])

	var $edittools = $('#plwiki-edittools')
	if($edittools.length == 0) return // not an edit page or protected
	var $sections = $edittools.find('.plwiki-edittools-section')

	// construct the selector element, using <b>s inside the edittools (assumed to be "headings")
	var $sel = $('<select>')
	$sections.find('b').each(function(i, e){
		$sel.append( $('<option>').text( $(e).text() ) )
	})

	// construct a table to wrap the edittools with.
	var $table = $('<table>').css('width', '100%').append( $('<tr>').append( $('<td>').css('width', '100%') ) )
	// move the edittools' sections inside it.
	$table.find('td').append( $sections )
	// create a heading cell before the sections cell containing the selector
	$table.find('tr').prepend( $('<th>').css('vertical-align', 'top').append($sel) )

	$edittools.append($table)

	// create a special option for showing all sections at once
	var message = {pl: '[Pokaż wszystko]', en: '[Show all]'}
	$sel.prepend( $('<option>').text( message[mw.config.get('wgUserLanguage')] || message['en'] ) )

	// register event handler to show and hide sections on demand
	$sel.on('change', function() {
		if($sel[0].selectedIndex == 0) {
			$sections.show()
			$sections.find('b').show()
		} else {
			$sections.hide().eq( $sel[0].selectedIndex - 1 ).show()
			$sections.find('b').hide()
		}

		gConfig.set('edittools-enhanced', 'section-shown', $sel[0].selectedIndex)
		gConfig.synchronise(function(){})
	})
	// choose the section (first by default; 0th is [Show all]) and fire the event to update the sections shown
	$sel[0].selectedIndex = gConfig.get('edittools-enhanced', 'section-shown')
	$sel.trigger('change')

	// insert the entire thing right before the edit summary and related stuffs
	$('.editOptions').before( $edittools )
})