1 // Toolbar JavaScript support functions. Taken from mediawiki
4 // Un-trap us from framesets
5 if( window.top != window ) window.top.location = window.location;
8 // This function generates the actual toolbar buttons with localized text
9 // We use it to avoid creating the toolbar where javascript is not enabled
10 // Not all buttons use this helper, some need special javascript treatment.
11 function addButton(imageFile, speedTip, func, args) {
13 speedTip=escapeQuotes(speedTip);
14 document.write("<a href=\"javascript:"+func+"(");
15 for (i=0; i<args.length; i++){
16 if (i>0) document.write(",");
17 document.write("'"+escapeQuotes(args[i])+"'");
19 //width=\"23\" height=\"22\"
20 document.write(");\"><img src=\""+imageFile+"\" width=\"18\" height=\"18\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\">");
21 document.write("</a>");
24 function addTagButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
25 addButton(imageFile, speedTip, "insertTags", [tagOpen, tagClose, sampleText]);
29 // This function generates a popup list to select from.
30 // In an external window so far, but we really want that as acdropdown pulldown, hence the name.
31 // plugins, pagenames, categories, templates.
32 // Not with document.write because we cannot use self.opener then.
33 //function addPulldown(imageFile, speedTip, pages) {
34 // addButton(imageFile, speedTip, "showPulldown", pages);
37 // pages is either an array of strings or an array of array(name,value)
38 function showPulldown(title, pages, okbutton, closebutton, fromid) {
39 height = new String(Math.min(315, 80 + (pages.length * 12))); // 270 or smaller
40 pullwin = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,height='+height+',width=200');
41 pullwin.window.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+escapeQuotes(title)+'</title><style type=\"text/css\"><'+'!'+'-- body {font-family:Tahoma,Arial,Helvetica,sans-serif;font-size:10pt;background-color:#dddddd;} input { font-weight:bold;margin-left:2px;margin-right:2px;} option {font-size:9pt} #buttons { background-color:#dddddd;padding-right:10px;width:180px;} --'+'></style></head>');
42 pullwin.window.document.write('\n<body bgcolor=\"#dddddd\"><form action=\"\"><div id=\"buttons\"><input type=\"button\" value=\"'+okbutton+'\" onclick=\"if(self.opener)self.opener.do_pulldown(document.forms[0].select.value,\''+fromid+'\'); return false;\"><input type=\"button\" value=\"'+closebutton+'\" onClick=\"self.close(); return false;\"></div>\n<select style=\"margin-top:10px;width:190px;\" name=\"select\" size=\"'+((pages.length>20)?'20':new String(pages.length))+'\" onDblClick=\"if(self.opener)self.opener.do_pulldown(document.forms[0].select.value,\''+fromid+'\'); return false;\">');
43 for (i=0; i<pages.length; i++){
44 if (typeof pages[i] == 'string')
45 pullwin.window.document.write('<option value="'+pages[i]+'">'+escapeQuotes(pages[i])+'</option>\n');
47 pullwin.window.document.write('<option value="'+pages[i][1]+'">'+escapeQuotes(pages[i][0])+'</option>\n');
49 pullwin.window.document.write('</select></form></body></html>');
50 pullwin.window.document.close();
53 function do_pulldown(text,fromid) {
54 // do special actions dependent on fromid: tb-categories
55 if (fromid == 'tb-categories') {
56 var txtarea = document.getElementById('edit-content');
57 text = unescapeSpecial(text)
58 txtarea.value += '\n'+text;
60 insertTags(text, '', '\n');
64 function addInfobox(infoText) {
65 // if no support for changing selection, add a small copy & paste field
66 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
67 var is_nav = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
68 && (clientPC.indexOf('khtml') == -1));
69 if(!document.selection && !is_nav) {
70 infoText=escapeQuotesHTML(infoText);
71 document.write("<form name='infoform' id='infoform'>"+
72 "<input size=80 id='infobox' name='infobox' value=\""+
73 infoText+"\" readonly=\"readonly\"></form>");
76 function escapeQuotes(text) {
77 var re=new RegExp("'","g");
78 text=text.replace(re,"\\'");
79 re=new RegExp('"',"g");
80 text=text.replace(re,'"');
81 re=new RegExp("\\n","g");
82 text=text.replace(re,"\\n");
85 function escapeQuotesHTML(text) {
86 var re=new RegExp('"',"g");
87 text=text.replace(re,""");
90 function unescapeSpecial(text) {
92 var re=new RegExp('%0A',"g");
93 text = text.replace(re,'\n');
94 var re=new RegExp('%22',"g");
95 text = text.replace(re,'"');
96 var re=new RegExp('%27',"g");
97 text = text.replace(re,'\'');
98 var re=new RegExp('%09',"g");
99 text = text.replace(re,' ');
100 var re=new RegExp('%7C',"g");
101 text = text.replace(re,'|');
102 var re=new RegExp('%5B',"g");
103 text = text.replace(re,'[');
104 var re=new RegExp('%5D',"g");
105 text = text.replace(re,']');
106 var re=new RegExp('%5C',"g");
107 text = text.replace(re,'\\');
111 // apply tagOpen/tagClose to selection in textarea,
112 // use sampleText instead of selection if there is none
113 // copied and adapted from phpBB
114 function insertTags(tagOpen, tagClose, sampleText) {
115 //f=document.getElementById('editpage');
116 var txtarea = document.getElementById('edit-content');
117 // var txtarea = document.editpage.edit[content];
118 tagOpen = unescapeSpecial(tagOpen)
120 if(document.selection) {
121 var theSelection = document.selection.createRange().text;
122 if(!theSelection) { theSelection=sampleText;}
124 if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
125 theSelection = theSelection.substring(0, theSelection.length - 1);
126 document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
128 document.selection.createRange().text = tagOpen + theSelection + tagClose;
130 // Mozilla -- this induces a scrolling bug which makes it virtually unusable
131 } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
132 var startPos = txtarea.selectionStart;
133 var endPos = txtarea.selectionEnd;
134 var scrollTop=txtarea.scrollTop;
135 var myText = (txtarea.value).substring(startPos, endPos);
136 if(!myText) { myText=sampleText;}
137 if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
138 subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
140 subst = tagOpen + myText + tagClose;
142 txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
144 var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
145 txtarea.selectionStart=cPos;
146 txtarea.selectionEnd=cPos;
147 txtarea.scrollTop=scrollTop;
150 // Append at the end: Some people find that annoying
151 txtarea.value += tagOpen + sampleText + tagClose;
153 //var re=new RegExp("\\n","g");
154 //tagOpen=tagOpen.replace(re,"");
155 //tagClose=tagClose.replace(re,"");
156 //document.infoform.infobox.value=tagOpen+sampleText+tagClose;
159 // reposition cursor if possible
160 if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
163 // JS_SEARCHREPLACE from walterzorn.de
164 var f, sr_undo, replacewin, undo_buffer=new Array(), undo_buffer_index=0;
166 function define_f() {
167 f=document.getElementById('editpage')
168 f.editarea=document.getElementById('edit-content')
169 sr_undo=document.getElementById('sr_undo')
173 function undo_enable(bool) {
175 sr_undo.src=uri_undo_btn
176 sr_undo.alt=msg_undo_alt
177 sr_undo.disabled = false
179 sr_undo.src=uri_undo_d_btn
180 sr_undo.alt=msg_undo_d_alt
181 sr_undo.disabled = true
182 if(sr_undo.blur) sr_undo.blur();
186 replacewin = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,height=90,width=450');
187 replacewin.window.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+msg_repl_title+"</title><style type=\"text/css\"><'+'!'+'-- body, input {font-family:Tahoma,Arial,Helvetica,sans-serif;font-size:10pt;font-weight:bold;} td {font-size:9pt} --'+'></style></head><body bgcolor=\"#dddddd\" onload=\"if(document.forms[0].searchinput.focus) document.forms[0].searchinput.focus(); return false;\"><form action=\"\"><center><table><tr><td align=\"right\">"+msg_repl_search+":</td><td align=\"left\"><input type=\"text\" name=\"searchinput\" size=\"45\" maxlength=\"500\"></td></tr><tr><td align=\"right\">"+msg_repl_replace_with+":</td><td align=\"left\"><input type=\"text\" name=\"replaceinput\" size=\"45\" maxlength=\"500\"></td></tr><tr><td colspan=\"2\" align=\"center\"><input type=\"button\" value=\" "+msg_repl_ok+" \" onclick=\"if(self.opener)self.opener.do_replace(); return false;\"> <input type=\"button\" value=\""+msg_repl_close+"\" onclick=\"self.close(); return false;\"></td></tr></table></center></form></body></html>");
188 replacewin.window.document.close();
191 function do_replace() {
192 var txt = undo_buffer[undo_buffer_index]=f.editarea.value
193 var searchinput = new RegExp(replacewin.document.forms[0].searchinput.value,'g')
194 var replaceinput = replacewin.document.forms[0].replaceinput.value
195 if (searchinput==''||searchinput==null) {
196 if (replacewin) replacewin.window.document.forms[0].searchinput.focus();
199 var z_repl=txt.match(searchinput)? txt.match(searchinput).length : 0;
200 txt=txt.replace(searchinput,replaceinput);
201 searchinput=searchinput.toString().substring(1,searchinput.toString().length-2);
202 msg_replfound = msg_replfound.replace('\1', searchinput).replace('\2', z_repl).replace('\3', replaceinput)
203 msg_replnot = msg_replnot.replace('%s', searchinput)
204 result(z_repl, msg_replfound, txt, msg_replnot);
205 replacewin.window.focus();
206 replacewin.window.document.forms[0].searchinput.focus();
209 function result(count,question,value_txt,alert_txt) {
211 if(window.confirm(question)==true) {
212 f.editarea.value=value_txt;
221 if(undo_buffer_index==0) return;
222 else if(undo_buffer_index>0) {
223 f.editarea.value=undo_buffer[undo_buffer_index-1];
224 undo_buffer[undo_buffer_index]=null;
226 if(undo_buffer_index==0) {
232 //save a snapshot in the undo buffer
233 function undo_save() {
234 undo_buffer[undo_buffer_index]=f.editarea.value;