MediaWiki:Common.js/edit.js

Zo stránky Wikislovník

Poznámka: Aby sa zmeny prejavili, po uložení musíte vymazať vyrovnávaciu pamäť vášho prehliadača.

  • Mozilla Firefox / Safari: Držte stlačený Shift a kliknite na Reload alebo stlačte buď Ctrl-F5 alebo Ctrl-R (⌘-R na Mac)
  • Google Chrome: Stlačte Ctrl-Shift-R (⌘-Shift-R na Mac)
  • Internet Explorer: Držte Ctrl a kliknite na Refresh alebo stlačte Ctrl-F5
  • Opera: Stlačte Ctrl-F5.
//fix edit summary prompt for undo
//this code fixes the fact that the undo function combined with the "no edit summary prompter" causes problems if leaving the
//edit summary unchanged
//this was added by [[User:Deskana]], code by [[User:Tra]]
//see bug 8912
$(function () {
    if (document.location.search.indexOf("undo=") != -1
        && document.getElementsByName('wpAutoSummary')[0]) {
        document.getElementsByName('wpAutoSummary')[0].value='1';
    }
})

/** Edittools javascript loader ************************************************
 *
 *  Description: Pulls in [[MediaWiki:Edittools.js]]. Includes a cache-bypassing
 *  version number in the URL in order to allow any changes to the edittools to
 *  be rapidly deployed to users.
 *
 *  Note that, by default, this function does nothing unless the element with
 *  the ID "editpage-specialchars" (which contains the old edittools code in
 *  [[MediaWiki:Edittools]], and will be retained as a placeholder in the new
 *  implementation) has a class named "edittools-version-NNN", where NNN is a
 *  number.  If the class name has "test" before the number, the code will only
 *  run for users who have set "window.testJsEdittools = true" in their user JS.
 *  The "test" should be retained in the class name until the new edittools
 *  implementation is ready and fully tested, and until at least 30 days have
 *  passed since this loader stub was added (which will be in 27 June 2008).
 *
 *  For compatibility with Alex Smotrov's original implementation, on which this
 *  code is loosely based (see [[mw:User talk:Alex Smotrov/edittools.js]]), this
 *  loader can also be disabled by setting "window.noDefaultEdittools = true".
 *
 *  Maintainers: [[User:Ilmari Karonen]]
 */

$(function () {
    // needs to be deferred until the DOM has fully loaded
    var placeholder = document.getElementById("editpage-specialchars");
    if (!placeholder || window.noDefaultEdittools) return;
    var match = /(?:^| )edittools-version-(\d+)(?: |$)/.exec(placeholder.className);
    
    // set window.testJsEdittools = true to enable testing before full deployment
    if (!match && window.testJsEdittools)
        match = /(?:^| )edittools-version-(test\d+)(?: |$)/.exec(placeholder.className);
    
    if (!match) return;
    var url = mw.config.get('wgScript') + '?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=' + match[1];
    mw.loader.load(url);
});







/*
== Informacja o nie wpisaniu opisu zmian ==
; Autorzy (Authors): [[:pl:User:Adziura|Adam Dziura]], [[:pl:User:Nux|Maciej Jaros]]
; Wyłączenie (disable): window.NoSummaryWarningDone = true;
<pre>
*/
$(function()
{
	if (!window.NoSummaryWarningDone)
	{
		var save_el = document.getElementById('wpSave');
		if (save_el)
			save_el.onclick = new Function('return FormValidation()')
		;
	}
});
	
function FormValidation()
{
	var input_el = document.getElementById('wpSummary');
	var summary = input_el.value;
	// empty or nothing but section comment
	if (summary == '' || summary.substring(summary.indexOf('*/'))=='*/ ')
	{
		// ignore redirects - there is autosummary
		var wpTextbox1 = document.getElementById('wpTextbox1');
		if (wpTextbox1.value.substring(0, 9).toUpperCase() == '#REDIRECT')
			return true;
		
		// if user hasn't been warned yet then do it
		if (!input_el.warningSet)
		{
			// set warning, do not submit form
			input_el.warningSet = true;
			input_el.className = 'warning';
			document.getElementById('wpSummaryLabel').className = 'warning';
			return false;
		}
	}	
	return true;
}

/*
</pre>

== Automatyczne opisy zmian ==
; Autor (Author): [[:pl:User:Adziura|Adam Dziura]]
; Poprawki (Fixes): [[:pl:User:Nux|Maciej Jaros]]
<pre>
*/

function przyciskiOpis()
{
	// stop before starting
	if (window.przyciskiOpisDone)
		return;

	//
	// sprawdzenie, czy to jest pole edycji z opisem zmian (nie jest takie jako nagłówek)
	var el = document.getElementById('wpSummaryLabel');
	if (el)
	{
		if (el.innerHTML.indexOf('Zhrnutie úprav')==-1)
			return	// stop
		;
		
	}
	else
	{
		return;	// stop
	}
	
	//
	// dodanie elementu okalającego przyciski bezpośrednio za opisem zmian
	var el = document.getElementById('wpSummary').nextSibling;
	var opisBtns = document.createElement('div');
	opisBtns.id = 'userSummaryButtons'
	el.parentNode.insertBefore(opisBtns, el)
	
	//
	// dodawanie przycisków
	//var kl = 'userButtonsStyle';
	var kl = '';	// klasa jest niepotrzebna (wszystkie <a> w #userSummaryButtons ustawione poprzez CSS)
	if (opisBtns)
	{
		// drobne różne
                przyciskiDodaj(opisBtns, 'pravopis', 'dodajOpis("pravopis")', kl,
                        'Oprava pravopisu');
		przyciskiDodaj(opisBtns, 'gramatika', 'dodajOpis("gramatika")', kl,
			'Oprava gramatiky');
		przyciskiDodaj(opisBtns, 'štylistika', 'dodajOpis("štylistika")', kl,
			'Úprava štylistiky');
		przyciskiDodaj(opisBtns, 'úprava', 'dodajOpis("úprava")', kl,
			'Vetšia zmena stránky');
		przyciskiDodaj(opisBtns, 'wikilinky', 'dodajOpis("wikilinky")', kl,
			'Úprava odkazov na iné články Wikislovníka');
		przyciskiDodaj(opisBtns, 'preklad', 'dodajOpis("preklad")', kl,
			'Úprava odkazov na cudzojazyčné termíny');
		przyciskiDodaj(opisBtns, 'kategórie', 'dodajOpis("kategórie")', kl,
			'Úprava kategórií');
	}
}

/*
Parametry:
* elUserBtns - element okalający, do którego dodać przycisk
* pTekst - tekst w środku przycisku
* pAkcja - akcja (w formie tekstowej) jaką wykonać przy naciśnięciu; może być ciągiem poleceń
* pKlasa - klasa jeśli konieczna
* pOpis - opis widoczny w dymku przy przycisku
*/
function przyciskiDodaj(elUserBtns, pTekst, pAkcja, pKlasa, pOpis)
{
	var nowyBtn = document.createElement('a');

	// atrybuty
	nowyBtn.appendChild(document.createTextNode(pTekst));
	nowyBtn.title = pOpis;
	if (pKlasa != '')
		nowyBtn.className = pKlasa
	;
	nowyBtn.onclick = new Function(pAkcja);

	// dodanie przycisku
	elUserBtns.appendChild(nowyBtn);
}

var clickedMinor = false;
function onMinorEditClick()
{
	if (this.checked && !clickedMinor)
	{
		dodajOpis("drobne");
		clickedMinor = true;
	}
}

function dodajOpis(opis)
{
	var wpS = document.editform.wpSummary;
	if (wpS.value != '' && wpS.value.charAt(wpS.value.length-2) != '/')
	{
		wpS.value += ', ' + opis
	}
	else
	{
		wpS.value += opis
	}
}

$(przyciskiOpis);