MediaWiki:Gadget-wikEd.js

Puslapis iš Vikižodyno, laisvojo žodyno.

Dėmesio: Išsaugojus jums gali prireikti išvalyti jūsų naršyklės podėlį, kad pamatytumėte pokyčius.

  • Firefox / Safari: Laikydami Shift pasirinkite Perkrauti, arba paspauskite Ctrl-F5 ar Ctrl-R (sistemoje Apple Mac ⌘-R)
  • Google Chrome: Spauskite Ctrl-Shift-R (sistemoje Apple Mac ⌘-Shift-R)
  • Internet Explorer / Edge: Laikydami Ctrl paspauskite Naujinti, arba paspauskite Ctrl-F5
  • Opera: Eikite į Meniu → Nuostatos (sistemoje Apple Mac Opera → Nustatymai), tuomet Privatumas ir sauga → išvalyti naršymo podėlį → išsaugotos talpyklos vaizdai ir failai.
// <pre><nowiki>
//  _________________________________________________________________________________________
// |                                                                                         |
// |                    === WARNING: GLOBAL GADGET FILE ===                                  |
// |                  Changes to this page affect many users.                                |
// | Please discuss changes on the talk page or on [[Wikipedia_talk:Gadget]] before editing. |
// |_________________________________________________________________________________________|
//
// Imports [[User:Cacycle/wikEd.js]]
// wikEd is a full-featured in-browser editor for Wikipedia, see [[User:Cacycle/wikEd]]

// install [[User:Cacycle/wikEd]] in-browser text editor
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js&action=raw&ctype=text/javascript');

// </nowiki></pre>
// define  custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = {};
wikEdButton[100] = ['wikEdKabutes', 'wikEdButton', 'Kabutės', '//upload.wikimedia.org/wikipedia/commons/2/23/Quotes-Lithuanian.png', '16', '16', 'Kabutės', 'javascript:WikEdEditButton(this, this.id, null, KabutesHandler);' ];
wikEdButton[101] = ['wikEdKomentarai', 'wikEdButton', 'Komentarai', '//upload.wikimedia.org/wikipedia/commons/3/37/Btn_toolbar_commentaire.png', '16', '16', 'Komentarai', 'javascript:WikEdEditButton(this, this.id, null, KomentaraiHandler);' ];
wikEdButton[102] = ['wikEdKategorija', 'wikEdButton', 'Kategorija', '//upload.wikimedia.org/wikipedia/commons/1/11/Button_category.png', '16', '16', 'Kategorija', 'javascript:WikEdEditButton(this, this.id, null, KategorijaHandler);' ];
wikEdButton[103] = ['wikEdNukreipimas', 'wikEdButton', 'Nukreipimas', '//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png', '16', '16', 'Nukreipimas', 'javascript:WikEdEditButton(this, this.id, null, NukreipimasHandler);' ];
wikEdButton[104] = ['wikEdIsnasa', 'wikEdButton', 'Išnaša', '//upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png', '16', '16', 'Išnaša', 'javascript:WikEdEditButton(this, this.id, null, IsnasaHandler);' ];
wikEdButton[105] = ['wikEdMath', 'wikEdButton', 'Matematinė formulė', '/w/skins/common/images/button_math.png', '16', '16', 'Matematinė formulė', 'javascript:WikEdEditButton(this, this.id, null, MathHandler);' ];
 
// define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
var wikEdButtonBar = {};
wikEdButtonBar['custom1'] = ['wikEdButtonBarCustom1',  'wikEdButtonBarCustom1',  'wikEdButtonsCustom1',  'wikEdButtonsCustom1',  44, 'Papildomi mygtukai', [100, 101, 104, 'br', 102, 103, 105] ];
 
// define the function which is called upon clicking the custom button
// this example code adds or removes div tags around the selected text
 
function KabutesHandler(obj) {
 
   // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
   //   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
   WikEdGetText(obj, 'selection, cursor');
   if (obj.selection.plain != '') {
      obj.changed = obj.selection;
   }
   else {
      obj.changed = obj.cursor;
   }
 
   // make the changes to the plain target text
 
   // remove the previously added formatting
   if ( /\„(.*?)\“/i.test(obj.changed.plain) ) {
      obj.changed.plain = obj.changed.plain.replace(/\„(.*?)\“/gi, '$1');
   }
 
   // add the text formatting
   else {
      obj.changed.plain = '\„' + obj.changed.plain + '\“';
      obj.changed.plain = obj.changed.plain.replace(/(\„)( *)(.*?)( *)(\“)/, '$2$1$3$5$4');
   }
 
   // keep the changed text selected, needed to remove the formatting with a second custom button click
   obj.changed.keepSel = true;
 
   return;
}
 
function KomentaraiHandler(obj) {
 
   // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
   //   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
   WikEdGetText(obj, 'selection, cursor');
   if (obj.selection.plain != '') {
      obj.changed = obj.selection;
   }
   else {
      obj.changed = obj.cursor;
   }
 
   // make the changes to the plain target text
 
   // remove the previously added formatting
   if ( /&lt;\!\-\-(.*?)\-\-&gt;/i.test(obj.changed.plain) ) {
      obj.changed.plain = obj.changed.plain.replace(/&lt;\!\-\-(.*?)\-\-&gt;/gi, '$1');
   }
 
   // add the text formatting
   else {
      obj.changed.plain = '&lt;\!\-\-' + obj.changed.plain + '\-\-&gt;';
      // obj.changed.plain = obj.changed.plain.replace(/(&lt;\!\-\-)( *)(.*?)( *)(\-\-&gt;)/, '$2$1$3$5$4');
   }
 
   // keep the changed text selected, needed to remove the formatting with a second custom button click
   obj.changed.keepSel = true;
 
   return;
}
 
function KategorijaHandler(obj) {
 
   // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
   //   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
   WikEdGetText(obj, 'selection, cursor');
   if (obj.selection.plain != '') {
      obj.changed = obj.selection;
   }
   else {
      obj.changed = obj.cursor;
   }
 
   // make the changes to the plain target text
 
   // remove the previously added formatting
   if ( /\[\[(?:Kategorija|Category)\:(.*?)\]\]/i.test(obj.changed.plain) ) {
      obj.changed.plain = obj.changed.plain.replace(/\[\[(?:Kategorija|Category)\:(.*?)\]\]/gi, '$1');
   }
 
   // add the text formatting
   else {
      if (obj.changed.plain == '')
         obj.changed.plain = '[[Kategorija:kategorijos pavadinimas]]';
      else
         obj.changed.plain = '[[Kategorija:' + obj.changed.plain + ']]';
      obj.changed.plain = obj.changed.plain.replace(/(\[\[Kategorija\:)( *)(.*?)( *)(\]\])/, '$2$1$3$5$4');
   }
 
   // keep the changed text selected, needed to remove the formatting with a second custom button click
   obj.changed.keepSel = true;
 
   return;
}
 
function NukreipimasHandler(obj) {
 
   // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
   //   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
   WikEdGetText(obj, 'selection, cursor');
   if (obj.selection.plain != '') {
      obj.changed = obj.selection;
   }
   else {
      obj.changed = obj.cursor;
   }
 
   // make the changes to the plain target text
 
   // remove the previously added formatting
   if ( /\#REDIRECT \[\[(.*?)\]\]/.test(obj.changed.plain) ) {
      obj.changed.plain = obj.changed.plain.replace(/\#REDIRECT \[\[(.*?)\]\]/g, '$1');
   }
 
   // add the text formatting
   else {
      if (obj.changed.plain == '')
         obj.changed.plain = '#REDIRECT [[straipsnio pavadinimas]]';
      else
         obj.changed.plain = '#REDIRECT [[' + obj.changed.plain + ']]';
      obj.changed.plain = obj.changed.plain.replace(/(\#REDIRECT \[\[)( *)(.*?)( *)(\]\])/, '$1$3$5$4');
   }
 
   // keep the changed text selected, needed to remove the formatting with a second custom button click
   obj.changed.keepSel = true;
 
   return;
}
 
function IsnasaHandler(obj) {
 
   // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
   //   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
   WikEdGetText(obj, 'selection, cursor');
   if (obj.selection.plain != '') {
      obj.changed = obj.selection;
   }
   else {
      obj.changed = obj.cursor;
   }
 
   // make the changes to the plain target text
 
   // remove the previously added formatting
   if ( /&lt;ref&gt;(.*?)&lt;\/ref&gt;/i.test(obj.changed.plain) ) {
      obj.changed.plain = obj.changed.plain.replace(/&lt;ref&gt;(.*?)&lt;\/ref&gt;/gi, '$1');
   }
 
   // add the text formatting
   else {
      if (obj.changed.plain == '')
         obj.changed.plain = '&lt;ref&gt;išnašos tekstas&lt;/ref&gt;';
      else
         obj.changed.plain = '&lt;ref&gt;' + obj.changed.plain + '&lt;/ref&gt;';
      obj.changed.plain = obj.changed.plain.replace(/(&lt;ref&gt;)( *)(.*?)( *)(&lt;\/ref&gt;)/, '$2$1$3$5$4');
   }
 
   // keep the changed text selected, needed to remove the formatting with a second custom button click
   obj.changed.keepSel = true;
 
   return;
}
 
function MathHandler(obj) {
 
   // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
   //   focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line
   WikEdGetText(obj, 'selection, cursor');
   if (obj.selection.plain != '') {
      obj.changed = obj.selection;
   }
   else {
      obj.changed = obj.cursor;
   }
 
   // make the changes to the plain target text
 
   // remove the previously added formatting
   if ( /&lt;math&gt;(.*?)&lt;\/math&gt;/i.test(obj.changed.plain) ) {
      obj.changed.plain = obj.changed.plain.replace(/&lt;math&gt;(.*?)&lt;\/math&gt;/gi, '$1');
   }
 
   // add the text formatting
   else {
      if (obj.changed.plain == '')
         obj.changed.plain = '&lt;math&gt;matematinė formulė&lt;/math&gt;';
      else
         obj.changed.plain = '&lt;math&gt;' + obj.changed.plain + '&lt;/math&gt;';
      obj.changed.plain = obj.changed.plain.replace(/(&lt;math&gt;)( *)(.*?)( *)(&lt;\/math&gt;)/, '$2$1$3$5$4');
   }
 
   // keep the changed text selected, needed to remove the formatting with a second custom button click
   obj.changed.keepSel = true;
 
   return;
}