1 |
efrain |
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
|
|
|
3 |
var noOverwrite=false;
|
|
|
4 |
var alertText;
|
|
|
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) {
|
|
|
11 |
var is_opera = true;
|
|
|
12 |
var is_opera_preseven = (window.opera && !document.childNodes);
|
|
|
13 |
var is_opera_seven = (window.opera && document.childNodes);
|
|
|
14 |
}
|
|
|
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) {
|
|
|
19 |
|
|
|
20 |
tagOpen = unescape(tagOpen);
|
|
|
21 |
tagClose = unescape(tagClose);
|
|
|
22 |
|
|
|
23 |
var txtarea = document.forms['mform1'].newcontent;
|
|
|
24 |
|
|
|
25 |
// IE
|
|
|
26 |
if(document.selection && !is_gecko) {
|
|
|
27 |
var theSelection = document.selection.createRange().text;
|
|
|
28 |
if(!theSelection) { theSelection=sampleText;}
|
|
|
29 |
txtarea.focus();
|
|
|
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 + " ";
|
|
|
33 |
} else {
|
|
|
34 |
document.selection.createRange().text = tagOpen + theSelection + tagClose;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
// Mozilla
|
|
|
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 + " ";
|
|
|
46 |
} else {
|
|
|
47 |
subst = tagOpen + myText + tagClose;
|
|
|
48 |
}
|
|
|
49 |
txtarea.value = txtarea.value.substring(0, startPos) + subst +
|
|
|
50 |
txtarea.value.substring(endPos, txtarea.value.length);
|
|
|
51 |
txtarea.focus();
|
|
|
52 |
|
|
|
53 |
var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
|
|
|
54 |
txtarea.selectionStart=cPos;
|
|
|
55 |
txtarea.selectionEnd=cPos;
|
|
|
56 |
txtarea.scrollTop=scrollTop;
|
|
|
57 |
|
|
|
58 |
// All others
|
|
|
59 |
} else {
|
|
|
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);
|
|
|
65 |
var text;
|
|
|
66 |
if (sampleText) {
|
|
|
67 |
text=prompt(copy_alertText);
|
|
|
68 |
} else {
|
|
|
69 |
text="";
|
|
|
70 |
}
|
|
|
71 |
if(!text) { text=sampleText;}
|
|
|
72 |
text=tagOpen+text+tagClose;
|
|
|
73 |
document.infoform.infobox.value=text;
|
|
|
74 |
// in Safari this causes scrolling
|
|
|
75 |
if(!is_safari) {
|
|
|
76 |
txtarea.focus();
|
|
|
77 |
}
|
|
|
78 |
noOverwrite=true;
|
|
|
79 |
}
|
|
|
80 |
// reposition cursor if possible
|
|
|
81 |
if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
|
|
|
82 |
}
|