Žymos: Keitimas mob. telefonu Keitimas įskiepiu mobiliesiems Advanced mobile edit Pašalintas nukreipimas |
Žymos: Keitimas mob. telefonu Keitimas įskiepiu mobiliesiems Advanced mobile edit Panaikinta |
| 1 eilutė: |
1 eilutė: |
| (function($, mw) {
| |
| // Tikriname, ar esame redagavimo režime
| |
| if (mw.config.get('wgAction') !== 'edit' && mw.config.get('wgAction') !== 'submit') {
| |
| return;
| |
| }
| |
|
| |
|
| // Funkcija, skirta įterpti tekstą į tekstinę sritį (cursor pozicija)
| |
| function insertAtCursor(textarea, text) {
| |
| if (document.selection) { // IE palaikymas
| |
| textarea.focus();
| |
| var sel = document.selection.createRange();
| |
| sel.text = text;
| |
| } else if (textarea.selectionStart || textarea.selectionStart === 0) {
| |
| var startPos = textarea.selectionStart;
| |
| var endPos = textarea.selectionEnd;
| |
| textarea.value = textarea.value.substring(0, startPos) + text + textarea.value.substring(endPos, textarea.value.length);
| |
| textarea.selectionStart = startPos + text.length;
| |
| textarea.selectionEnd = startPos + text.length;
| |
| } else {
| |
| textarea.value += text;
| |
| }
| |
| }
| |
|
| |
| // Funkcija sukurti mūsų mygtukui
| |
| function createInsertButton() {
| |
| var $btn = $('<button type="button" id="customInsertBtn" style="margin-left: 5px;">Įterpti</button>');
| |
| $btn.on('click', function() {
| |
| var type = prompt("Pasirinkite įterpimo tipą:\n1 - Paveikslėlis\n2 - Šablonas\n3 - Kategorija");
| |
| if (!type) return;
| |
| var query = prompt("Įveskite paieškos terminą:");
| |
| if (!query) return;
| |
| var insertion = "";
| |
| switch (type.trim()) {
| |
| case "1":
| |
| // Paveikslėlio sintaksė
| |
| insertion = "[[File:" + query + "]]";
| |
| break;
| |
| case "2":
| |
| // Šablono sintaksė
| |
| insertion = "{{" + query + "}}";
| |
| break;
| |
| case "3":
| |
| // Kategorijos sintaksė
| |
| insertion = "[[Category:" + query + "]]";
| |
| break;
| |
| default:
| |
| alert("Neteisingas pasirinkimas!");
| |
| return;
| |
| }
| |
| var $textarea = $('#wpTextbox1');
| |
| if ($textarea.length) {
| |
| insertAtCursor($textarea[0], insertion);
| |
| } else {
| |
| alert("Teksto sritis nerasta.");
| |
| }
| |
| });
| |
| return $btn;
| |
| }
| |
|
| |
| // Kai puslapis užsikrauna, ieškome redaktoriaus srities ir pridedame mygtuką
| |
| $(document).ready(function() {
| |
| // Pabandome rasti esamą įrankių juostą
| |
| var $toolbar = $('#toolbar');
| |
| if ($toolbar.length) {
| |
| $toolbar.append(createInsertButton());
| |
| } else {
| |
| // Jei nerandame, dedame mygtuką tiesiai prieš tekstinę sritį
| |
| var $textarea = $('#wpTextbox1');
| |
| if ($textarea.length) {
| |
| $textarea.before(createInsertButton());
| |
| }
| |
| }
| |
| });
| |
| })(jQuery, mediaWiki);
| |