1 // Toolbar JavaScript support functions from mediawiki
2 // $Id: toolbar.js,v 1.2 2004-05-27 17:55:38 rurban Exp $
4 // Un-trap us from framesets
5 if( window.top != window ) window.top.location = window.location;
7 // This function generates the actual toolbar buttons with localized text
8 // We use it to avoid creating the toolbar where javascript is not enabled
9 // Not all buttons use this helper, some need special javascript treatment.
10 function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
11 speedTip=escapeQuotes(speedTip);
12 tagOpen=escapeQuotes(tagOpen);
13 tagClose=escapeQuotes(tagClose);
14 sampleText=escapeQuotes(sampleText);
15 document.write("<a href=\"javascript:insertTags");
16 document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
17 document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\">");
18 document.write("</a>");
22 function addInfobox(infoText) {
23 // if no support for changing selection, add a small copy & paste field
24 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
25 var is_nav = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
26 && (clientPC.indexOf('khtml') == -1));
27 if(!document.selection && !is_nav) {
28 infoText=escapeQuotesHTML(infoText);
29 document.write("<form name='infoform' id='infoform'>"+
30 "<input size=80 id='infobox' name='infobox' value=\""+
31 infoText+"\" readonly=\"readonly\"></form>");
35 function escapeQuotes(text) {
36 var re=new RegExp("'","g");
37 text=text.replace(re,"\\'");
38 re=new RegExp('"',"g");
39 text=text.replace(re,'"');
40 re=new RegExp("\\n","g");
41 text=text.replace(re,"\\n");
45 function escapeQuotesHTML(text) {
46 var re=new RegExp('"',"g");
47 text=text.replace(re,""");
51 // apply tagOpen/tagClose to selection in textarea,
52 // use sampleText instead of selection if there is none
53 // copied and adapted from phpBB
54 function insertTags(tagOpen, tagClose, sampleText) {
55 //f=document.getElementById('editpage');
56 var txtarea = document.getElementById('edit[content]');
57 // var txtarea = document.editpage.edit[content];
60 if(document.selection) {
61 var theSelection = document.selection.createRange().text;
62 if(!theSelection) { theSelection=sampleText;}
64 if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
65 theSelection = theSelection.substring(0, theSelection.length - 1);
66 document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
68 document.selection.createRange().text = tagOpen + theSelection + tagClose;
70 // Mozilla -- disabled because it induces a scrolling bug which makes it virtually unusable
71 } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
72 var startPos = txtarea.selectionStart;
73 var endPos = txtarea.selectionEnd;
74 var scrollTop=txtarea.scrollTop;
75 var myText = (txtarea.value).substring(startPos, endPos);
76 if(!myText) { myText=sampleText;}
77 if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
78 subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
80 subst = tagOpen + myText + tagClose;
82 txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
84 var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
85 txtarea.selectionStart=cPos;
86 txtarea.selectionEnd=cPos;
87 txtarea.scrollTop=scrollTop;
90 // Append at the end: Some people find that annoying
91 //txtarea.value += tagOpen + sampleText + tagClose;
93 var re=new RegExp("\\n","g");
94 tagOpen=tagOpen.replace(re,"");
95 tagClose=tagClose.replace(re,"");
96 document.infoform.infobox.value=tagOpen+sampleText+tagClose;
99 // reposition cursor if possible
100 if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();