Revision 56207 of "MediaWiki:Monobook.js" on cswikisource

/* Viz i nově zřízený MediaWiki:Common.js - viz bug 4178. */

/*
===Edit toolbar===
různá tlačítka na edit toolbar, zde podle cs.wiki a en.wiki
<pre>*/

function commonCustomizeEditToolbar()
  {
  if (!mwCustomEditButtons)
    return;
// vložení tabulky
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "//upload.wikimedia.org/wikipedia/commons/0/04/Button_array.png",
    "speedTip": "Insert a table",
    "tagOpen": '{| class="wikitable"\n|-\n',
    "tagClose": "\n|}",
    "sampleText": "! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"}

}

/*</pre>

==== funkce insertTagsTo_ ====
; Author: phpBB Team, WikiMedia, Maciej Jaros [[:pl:User:Nux]]
; Licence: [http://opensource.org/licenses/gpl-license.php GNU General Public License v2]
; Description: Apply tagOpen/tagClose to selection in given textarea/input, use sampleText instead of selection if there is none. Copied and adapted from phpBB
<pre>*/

// outputid = 'some_id_of_a_textarea_or_a_text_input'
function insertTagsTo_(tagOpen, tagClose, sampleText, outputid) {
	var txtarea = document.getElementById(outputid);
	if (!txtarea)
		return
	;

	// IE
	if (document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;
		if (!theSelection)
			theSelection=sampleText;
		txtarea.focus();
		if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
			theSelection = theSelection.substring(0, theSelection.length - 1);
			document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
		} else {
			document.selection.createRange().text = tagOpen + theSelection + tagClose;
		}

	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
		var replaced = false;
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		if (endPos-startPos)
			replaced = true;
		var scrollTop = txtarea.scrollTop;
		var myText = (txtarea.value).substring(startPos, endPos);
		if (!myText)
			myText=sampleText;
		if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
			subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
		} else {
			subst = tagOpen + myText + tagClose;
		}
		txtarea.value = txtarea.value.substring(0, startPos) + subst +
			txtarea.value.substring(endPos, txtarea.value.length);
		txtarea.focus();
		//set new selection
		if (replaced) {
			var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
			txtarea.selectionStart = cPos;
			txtarea.selectionEnd = cPos;
		} else {
			txtarea.selectionStart = startPos+tagOpen.length;
			txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
		}
		txtarea.scrollTop = scrollTop;
	}
	// reposition cursor if possible
	if (txtarea.createTextRange)
		txtarea.caretPos = document.selection.createRange().duplicate();
}
/*</pre>

===Diakritika na stránce Hledat===
; převzato z cs.wiki, tam následující údaje:
; Author: Maciej Jaros [[:pl:User:Nux]]
; Licence: CC-BY or [http://opensource.org/licenses/gpl-license.php GNU General Public License v2]

<pre>*/
if (wgNamespaceNumber == -1 && wgPageName=="Speciální:Search")
{
	addOnloadHook(addSearchKeyboard);
}

function addSearchKeyboard() {
	var subEl = document.getElementById('results');
	var newEl = document.createElement('div');
	newEl.className = 'search_keyboard';
	newEl.innerHTML = "\
<b>Znaky:\
<a onclick=\"insertTagsTo_('č','','','lsearchbox');return false\" href=\"#\">č</a>\
<a onclick=\"insertTagsTo_('š','','','lsearchbox');return false\" href=\"#\">š</a>\
<a onclick=\"insertTagsTo_('ř','','','lsearchbox');return false\" href=\"#\">ř</a>\
<a onclick=\"insertTagsTo_('ž','','','lsearchbox');return false\" href=\"#\">ž</a>\
<a onclick=\"insertTagsTo_('ť','','','lsearchbox');return false\" href=\"#\">ť</a>\
<a onclick=\"insertTagsTo_('ď','','','lsearchbox');return false\" href=\"#\">ď</a>\
<a onclick=\"insertTagsTo_('ň','','','lsearchbox');return false\" href=\"#\">ň</a>\
<a onclick=\"insertTagsTo_('ě','','','lsearchbox');return false\" href=\"#\">ě</a>\
<a onclick=\"insertTagsTo_('á','','','lsearchbox');return false\" href=\"#\">á</a>\
<a onclick=\"insertTagsTo_('í','','','lsearchbox');return false\" href=\"#\">í</a>\
<a onclick=\"insertTagsTo_('é','','','lsearchbox');return false\" href=\"#\">é</a>\
<a onclick=\"insertTagsTo_('ó','','','lsearchbox');return false\" href=\"#\">ó</a>\
<a onclick=\"insertTagsTo_('ú','','','lsearchbox');return false\" href=\"#\">ú</a>\
<a onclick=\"insertTagsTo_('ý','','','lsearchbox');return false\" href=\"#\">ý</a>\
<a onclick=\"insertTagsTo_('ů','','','lsearchbox');return false\" href=\"#\">ů</a>\
<a onclick=\"insertTagsTo_('ö','','','lsearchbox');return false\" href=\"#\">ö</a>\
<a onclick=\"insertTagsTo_('ü','','','lsearchbox');return false\" href=\"#\">ü</a>\
<a onclick=\"insertTagsTo_('ä','','','lsearchbox');return false\" href=\"#\">ä</a>\</b>\
";
	newEl.style.cssText = 'margin-left:25%; width:50%; font-size:small;';
	subEl.parentNode.insertBefore(newEl, subEl);
}