User:Connel MacKenzie/editbarbuttons.js

MyChar = new Array; MyCharText = new Array; MyCharEnd = new Array; MyCharDefault = new Array;

//The cleaner way to add an editbar button.

function addEditButton(imageFile, tagOpen, sampleText, tagClose, speedTip) {       mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/" + imageFile, "tagOpen": tagOpen, "sampleText": sampleText, "tagClose": tagClose, "speedTip": speedTip };   }

function insertTagsValue(uchar, ucharend, uchardefault, ucharnr) { var txtarea = document.editform.wpTextbox1; // IE       if (document.selection && !is_gecko) { var theSelection = document.selection.createRange.text; // 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 theSelection = (txtarea.value).substring(startPos, endPos); }       if (theSelection == "") { if(!(lastVal = GetCookie("CharDefaultValue-"+ ucharnr))) lastVal ="0"; theSelection= parseInt(lastVal)+parseInt(uchardefault.substr(1)); theSelection= theSelection.toString; }        setCookie("CharDefaultValue-"+ ucharnr,theSelection); insertTags(uchar,ucharend,theSelection); }

function addEditButtons {

addEditButton( 'commons/3/30/Btn_toolbar_rayer.png',        ' ', 'strikeout', ' ', 'Strikeout');

addEditButton( 'commons/5/59/Button_template.png',        '<' + '!--', 'sample comment', '-->', 'Comment');

addEditButton( 'en/c/c8/Button_redirect.png',        '#REDIRECT ', ,         , '#redirect');

addEditButton( 'en/5/5f/Button_center.png',        ' ', 'Centered text', ' ', 'Center');

addEditButton( 'en/e/e9/Button_headline2.png',        '\n===', 'Sub-heading', '===', 'Sub-heading');

addEditButton( 'en/8/8e/Button_shifting.png', ':',        'Indented text', ':', 'Indent');

addEditButton( 'commons/5/58/Button_small.png', ' ',        'Small text', ' ', 'Small text');

addEditButton( 'en/8/80/Button_upper_letter.png', ' ',        'superscript', ' ', 'superscript');

addEditButton( 'en/9/93/Button_sub_link.png',        '', 'subheading');

addEditButton( 'commons/2/23/Button_code.png',        ' ', 'nowiki\'d text', ' ', 'tt+nowiki'); }

addEditButtons;

function stringReplaceBox { Valreplace=getCookie ("StrReplace"); Valreplacement=getCookie ("StrReplacement"); PromptWin = window.open("about:blank", "PromptWin", "width=280,height=120,dependent=yes,location=no,menubar=no,resizable=yes,status=no,toolbar=no"); PromptWin.document.open; PromptWin.document.write(" Text ersetzen "); PromptWin.document.write(""); PromptWin.document.write(""); PromptWin.document.write(" "); PromptWin.document.write("  "); PromptWin.document.write(" "); PromptWin.document.write("  "); PromptWin.document.close; PromptWin.document.replaceform.valreplace.select; }

function stringReplace(inReplace,inReplacement) { setCookie ("StrReplace",inReplace); setCookie ("StrReplacement",inReplacement); var StrReplace = new RegExp(inReplace, "g"); var StrReplacement=inReplacement; if (document.editform) var txtarea = document.editform.wpTextbox1; else { // some alternate form? take the first one we can find var areas = document.getElementsByTagName('textarea'); var txtarea = areas[0]; }       txtarea.value=txtarea.value.replace(StrReplace,StrReplacement); }

function bsImprovedToolbar { tooly = document.getElementById('toolbar'); if ( (!tooly) ) return;

var buttonAB = document.createElement("img"); buttonAB.width = 23; buttonAB.height = 22; buttonAB.src = 'http://upload.wikimedia.org/wikipedia/commons/5/59/Button_replace.png'; buttonAB.border = 0; buttonAB.alt = 'Replace text'; buttonAB.title = 'Replace text' buttonAB.style.cursor = "pointer"; buttonAB.onclick = function { stringReplaceBox; return false; } tooly.appendChild(buttonAB); }

addOnloadHook(bsImprovedToolbar);