MediaWiki:Gadget-wikEd.js
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
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript"></' + 'script>');
// define custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = {};
wikEdButton[100] = ['wikEdKabutes', 'wikEdButton', 'Kabutės', 'http://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', 'http://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', 'http://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', 'http://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', 'http://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ė', 'http://bits.wikimedia.org/skins-1.5/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 ( /<\!\-\-(.*?)\-\->/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 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 ( /<ref>(.*?)<\/ref>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<ref>(.*?)<\/ref>/gi, '$1');
}
// add the text formatting
else {
if (obj.changed.plain == '')
obj.changed.plain = '<ref>išnašos tekstas</ref>';
else
obj.changed.plain = '<ref>' + obj.changed.plain + '</ref>';
obj.changed.plain = obj.changed.plain.replace(/(<ref>)( *)(.*?)( *)(<\/ref>)/, '$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 ( /<math>(.*?)<\/math>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<math>(.*?)<\/math>/gi, '$1');
}
// add the text formatting
else {
if (obj.changed.plain == '')
obj.changed.plain = '<math>matematinė formulė</math>';
else
obj.changed.plain = '<math>' + obj.changed.plain + '</math>';
obj.changed.plain = obj.changed.plain.replace(/(<math>)( *)(.*?)( *)(<\/math>)/, '$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;
}
// </nowiki></pre>