MediaWiki:Monobook.js

Матеріал з Вікіпедії — вільної енциклопедії.
Перейти до навігації Перейти до пошуку

Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.

  • Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
  • Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
  • Internet Explorer / Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5
  • Opera: натисніть Ctrl-F5
function insertTagsTo_(tagOpen, tagClose, sampleText, outputid) {
	var txtarea = document.getElementById(outputid);
	if (!txtarea)
		return
	;
 
	// IE
	if (document.selection  && $.client.profile().layout != '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();
}
 
// Клавіатурка для [[Special:Search]]
/*
== Small search keyboard ==
; Author: Maciej Jaros [[:pl:User:Nux]]
; Licence: CC-BY or [http://opensource.org/licenses/gpl-license.php GNU General Public License v2]
*/
if (mw.config.get('wgCanonicalSpecialPageName') == "Search")
{
	$(addSearchKeyboards);
}
 
function addSearchKeyboards() {
 
	if (document.forms['search'])
		addSearchKeyboard(document.forms['search']);
 
	if (document.forms['powersearch'])
		addSearchKeyboard(document.forms['powersearch']);
 
}
 
function addSearchKeyboard(searchForm) {
	var searchBoxId = 'lsearchbox';
	if (!searchForm.lsearchbox) {
		if (searchForm.search.id == '') {
			searchBoxId = searchForm.name + 'box';
			searchForm.search.id = searchBoxId;
		} else
			searchBoxId = searchForm.search.id;
	}
 
	var letters = new Array('ґ', 'є', 'і', 'ї', "'");
	var html = "Клавіатурка: ";
	for (var i = 0; i < letters.length; i++) {
		html += "<a onclick=\"insertTagsTo_('\\" + letters[i] + "','','','" + searchBoxId + "');return false\" href=\"#\">" + letters[i] + "</a>";
	}
 
	var newEl = document.createElement('div');
	newEl.className = 'search_keyboard';
	newEl.innerHTML = html;
	newEl.style.cssText = 'width:50%; font-size:small; font-weight: bold';
	document.getElementById(searchBoxId).parentNode.appendChild(newEl);
}