1 // Wikipedia JavaScript support functions
2 // if this is true, the toolbar will no longer overwrite the infobox when you move the mouse over individual items
5 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
6 var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
7 && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
8 var is_safari = ((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1));
9 var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
10 if (clientPC.indexOf('opera')!=-1) {
12 var is_opera_preseven = (window.opera && !document.childNodes);
13 var is_opera_seven = (window.opera && document.childNodes);
15 // apply tagOpen/tagClose to selection in textarea,
16 // use sampleText instead of selection if there is none
17 // copied and adapted from phpBB
18 function insertTags(tagOpen, tagClose, sampleText) {
20 tagOpen = unescape(tagOpen);
21 tagClose = unescape(tagClose);
23 var txtarea = document.forms['mform1'].newcontent;
26 if(document.selection && !is_gecko) {
27 var theSelection = document.selection.createRange().text;
28 if(!theSelection) { theSelection=sampleText;}
30 if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
31 theSelection = theSelection.substring(0, theSelection.length - 1);
32 document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
34 document.selection.createRange().text = tagOpen + theSelection + tagClose;
38 } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
39 var startPos = txtarea.selectionStart;
40 var endPos = txtarea.selectionEnd;
41 var scrollTop=txtarea.scrollTop;
42 var myText = (txtarea.value).substring(startPos, endPos);
43 if(!myText) { myText=sampleText;}
44 if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
45 subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
47 subst = tagOpen + myText + tagClose;
49 txtarea.value = txtarea.value.substring(0, startPos) + subst +
50 txtarea.value.substring(endPos, txtarea.value.length);
53 var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
54 txtarea.selectionStart=cPos;
55 txtarea.selectionEnd=cPos;
56 txtarea.scrollTop=scrollTop;
60 var copy_alertText=alertText;
61 var re1=new RegExp("\\$1","g");
62 var re2=new RegExp("\\$2","g");
63 copy_alertText=copy_alertText.replace(re1,sampleText);
64 copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
67 text=prompt(copy_alertText);
71 if(!text) { text=sampleText;}
72 text=tagOpen+text+tagClose;
73 document.infoform.infobox.value=text;
74 // in Safari this causes scrolling
80 // reposition cursor if possible
81 if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();