MediaWiki:Gadget-wikEd.js: Unterschied zwischen den Versionen

Aus PhysikWiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(17 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
// define  custom buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdConfig = {};
var wikEdButton = {};
wikEdConfig.button = [];
wikEdButton[100] = ['wikEdDiv', 'wikEdButton', 'Make the selection a math element', 'http://upload.wikimedia.org/wikipedia/commons/6/67/WikEd_logo.png', '16', '16', 'math', 'javascript:WikEdEditButton(this, this.id, null, TestHandler);' ];
wikEdConfig.button[100]= ['wikEdMiv', 'wikEdButton', 'Make the selection a math element', 'skins/common/images/button_math.png', '16', '16', 'math', 'javascript:WikEdEditButton(this, this.id, null, TestHandler);' ];
wikEdConfig.button[101] = ['wikEdM', 'wikEdButton', 'Make the selection a FB', 'skins/common/images/button_template.png', '16', '16', 'math', 'javascript:WikEdEditButton(this, this.id, null, HdlFB);' ];


// define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
// define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
var wikEdButtonBar = {};
wikEdConfig.buttonBar = {};
wikEdButtonBar['custom1'] = ['wikEdButtonBarCustom1',  'wikEdButtonBarCustom1',  'wikEdButtonsCustom1',  'wikEdButtonsCustom1',  44, 'My custom buttons', [100, 'br', 101] ];
wikEdConfig.buttonBar.custom1 = ['wikEdButtonBarCustom1',  'wikEdButtonBarCustom1',  'wikEdButtonsCustom1',  'wikEdButtonsCustom1',  44, 'My custom buttons', [100, 'br', 101]];
// define the function which is called upon clicking the custom button
// define the function which is called upon clicking the custom button
// this example code adds or removes div tags around the selected text
// this example code adds or removes math tags around the selected text


var wikEdButtonKey = {
  100: [',', 188] // shift-alt-,: "replace all" button shortcut
}
function TestHandler(obj) {
function TestHandler(obj) {


Zeile 24: Zeile 28:


// remove the previously added formatting
// remove the previously added formatting
if ( /<div>(.*?)<\/div>/i.test(obj.changed.plain) ) {
if ( /<math>(.*?)<\/math>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<div>(.*?)<\/div>/gi, '$1');
obj.changed.plain = obj.changed.plain.replace(/<math>(.*?)<\/math>/gi, '$1');
}
 
// add the text formatting
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 = false;
 
return;
}
 
function HdlFB(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 ( /\{\{FB\|(.*?)\}\}/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\{\{FB\|(.*?)\}\}/gi, '$1');
}
}


// add the text formatting
// add the text formatting
else {
else {
obj.changed.plain = '<div>' + obj.changed.plain + '</div>';
obj.changed.plain = '{{FB|' + obj.changed.plain + '}}';
obj.changed.plain = obj.changed.plain.replace(/(<div>)( *)(.*?)( *)(<\/div>)/, '$2$1$3$5$4');
obj.changed.plain = obj.changed.plain.replace(/(\{\{FB\|)( *)(.*?)( *)(\}\})/, '$2$1$3$5$4');
}
}


Zeile 39: Zeile 74:
return;
return;
}
}
// install [[Wikipedia:User:Cacycle/wikEd]] in-browser text editor
// install [[Wikipedia:User:Cacycle/wikEd]] in-browser text editor
document.write('<script type="text/javascript" src="'
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript"></' + 'script>');
+ '&action=raw&ctype=text/javascript"></' + 'script>');

Aktuelle Version vom 20. Dezember 2010, 18:36 Uhr

var wikEdConfig = {};
wikEdConfig.button = [];
wikEdConfig.button[100]= ['wikEdMiv', 'wikEdButton', 'Make the selection a math element', 'skins/common/images/button_math.png', '16', '16', 'math', 'javascript:WikEdEditButton(this, this.id, null, TestHandler);' ];
wikEdConfig.button[101] = ['wikEdM', 'wikEdButton', 'Make the selection a FB', 'skins/common/images/button_template.png', '16', '16', 'math', 'javascript:WikEdEditButton(this, this.id, null, HdlFB);' ];

// define custom button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
wikEdConfig.buttonBar = {};
wikEdConfig.buttonBar.custom1 = ['wikEdButtonBarCustom1',  'wikEdButtonBarCustom1',  'wikEdButtonsCustom1',  'wikEdButtonsCustom1',  44, 'My custom buttons', [100, 'br', 101]];
// define the function which is called upon clicking the custom button
// this example code adds or removes math tags around the selected text

var wikEdButtonKey = {
  100: [',', 188] // shift-alt-,: "replace all" button shortcut
}
function TestHandler(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 {
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 = false;

return;
}

function HdlFB(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 ( /\{\{FB\|(.*?)\}\}/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\{\{FB\|(.*?)\}\}/gi, '$1');
}

// add the text formatting
else {
obj.changed.plain = '{{FB|' + obj.changed.plain + '}}';
obj.changed.plain = obj.changed.plain.replace(/(\{\{FB\|)( *)(.*?)( *)(\}\})/, '$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;
}


// install [[Wikipedia: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>');