f928892eec9aee1898a500a88b8bdaacc75cabab
1 // Wikipedia JavaScript support functions
3 // if this is true, the toolbar will no longer overwrite the infobox when you move the mouse over individual items
6 var clientPC
= navigator
.userAgent
.toLowerCase(); // Get client info
7 var is_gecko
= ((clientPC
.indexOf('gecko')!=-1) && (clientPC
.indexOf('spoofer')==-1)
8 && (clientPC
.indexOf('khtml') == -1));
9 var is_safari
= ((clientPC
.indexOf('AppleWebKit')!=-1) && (clientPC
.indexOf('spoofer')==-1));
10 if (clientPC
.indexOf('opera')!=-1) {
12 var is_opera_preseven
= (window
.opera
&& !document
.childNodes
);
13 var is_opera_seven
= (window
.opera
&& document
.childNodes
);
16 // document.write special stylesheet links
17 function addcss ( stylepath
) {
18 if (is_opera_preseven
) {
19 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'Opera6Fixes.css">');
20 } else if (is_opera_seven
) {
21 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'Opera7Fixes.css">');
26 // Un-trap us from framesets
27 if( window
.top
!= window
) window
.top
.location
= window
.location
;
29 // for enhanced RecentChanges
30 function toggleVisibility( _levelId
, _otherId
, _linkId
) {
31 var thisLevel
= document
.getElementById( _levelId
);
32 var otherLevel
= document
.getElementById( _otherId
);
33 var linkLevel
= document
.getElementById( _linkId
);
34 if ( thisLevel
.style
.display
== 'none' ) {
35 thisLevel
.style
.display
= 'block';
36 otherLevel
.style
.display
= 'none';
37 linkLevel
.style
.display
= 'inline';
39 thisLevel
.style
.display
= 'none';
40 otherLevel
.style
.display
= 'inline';
41 linkLevel
.style
.display
= 'none';
46 // tz in format [+-]HHMM
47 function checkTimezone( tz
, msg
) {
48 var localclock
= new Date();
49 // returns negative offset from GMT in minutes
50 var tzRaw
= localclock
.getTimezoneOffset();
51 var tzHour
= Math
.floor( Math
.abs(tzRaw
) / 60);
52 var tzMin
= Math
.abs(tzRaw
) % 60;
53 var tzString
= ((tzRaw
>= 0) ? "-" : "+") + ((tzHour
< 10) ? "0" : "") + tzHour
+ ((tzMin
< 10) ? "0" : "") + tzMin
;
54 if( tz
!= tzString
) {
55 var junk
= msg
.split( '$1' );
56 document
.write( junk
[0] + "UTC" + tzString
+ junk
[1] );
60 // in [-]HH:MM format...
61 // won't yet work with non-even tzs
62 function fetchTimezone() {
63 // FIXME: work around Safari bug
64 var localclock
= new Date();
65 // returns negative offset from GMT in minutes
66 var tzRaw
= localclock
.getTimezoneOffset();
67 var tzHour
= Math
.floor( Math
.abs(tzRaw
) / 60);
68 var tzMin
= Math
.abs(tzRaw
) % 60;
69 var tzString
= ((tzRaw
>= 0) ? "-" : "") + ((tzHour
< 10) ? "0" : "") + tzHour
+
70 ":" + ((tzMin
< 10) ? "0" : "") + tzMin
;
74 function guessTimezone(box
) {
75 document
.preferences
.wpHourDiff
.value
= fetchTimezone();
78 function showTocToggle(show
,hide
) {
79 if(document
.getElementById
) {
80 document
.writeln('<span class=\'toctoggle\'>[<a href="javascript:toggleToc()" class="internal">' +
81 '<span id="showlink" style="display:none;">' + show
+ '</span>' +
82 '<span id="hidelink">' + hide
+ '</span>'
87 function toggleToc() {
88 var toc
= document
.getElementById('tocinside');
89 var showlink
=document
.getElementById('showlink');
90 var hidelink
=document
.getElementById('hidelink');
91 if(toc
.style
.display
== 'none') {
92 toc
.style
.display
= tocWas
;
93 hidelink
.style
.display
='';
94 showlink
.style
.display
='none';
97 tocWas
= toc
.style
.display
;
98 toc
.style
.display
= 'none';
99 hidelink
.style
.display
='none';
100 showlink
.style
.display
='';
105 // this function generates the actual toolbar buttons with localized text
106 // we use it to avoid creating the toolbar where javascript is not enabled
107 function addButton(imageFile
, speedTip
, tagOpen
, tagClose
, sampleText
) {
109 speedTip
=escapeQuotes(speedTip
);
110 tagOpen
=escapeQuotes(tagOpen
);
111 tagClose
=escapeQuotes(tagClose
);
112 sampleText
=escapeQuotes(sampleText
);
115 // we can't change the selection, so we show example texts
116 // when moving the mouse instead, until the first button is clicked
117 if(!document
.selection
&& !is_gecko
) {
118 // filter backslashes so it can be shown in the infobox
119 var re
=new RegExp("\\\\n","g");
120 tagOpen
=tagOpen
.replace(re
,"");
121 tagClose
=tagClose
.replace(re
,"");
122 mouseOver
= "onMouseover=\"if(!noOverwrite){document.infoform.infobox.value='"+tagOpen
+sampleText
+tagClose
+"'};\"";
125 document
.write("<a href=\"javascript:insertTags");
126 document
.write("('"+tagOpen
+"','"+tagClose
+"','"+sampleText
+"');\">");
128 document
.write("<img width=\"23\" height=\"22\" src=\""+imageFile
+"\" border=\"0\" ALT=\""+speedTip
+"\" TITLE=\""+speedTip
+"\""+mouseOver
+">");
129 document
.write("</a>");
133 function addInfobox(infoText
,text_alert
) {
134 alertText
=text_alert
;
135 var clientPC
= navigator
.userAgent
.toLowerCase(); // Get client info
137 var re
=new RegExp("\\\\n","g");
138 alertText
=alertText
.replace(re
,"\n");
140 // if no support for changing selection, add a small copy & paste field
141 // document.selection is an IE-only property. The full toolbar works in IE and
142 // Gecko-based browsers.
143 if(!document
.selection
&& !is_gecko
) {
144 infoText
=escapeQuotesHTML(infoText
);
145 document
.write("<form name='infoform' id='infoform'>"+
146 "<input size=80 id='infobox' name='infobox' value=\""+
147 infoText
+"\" READONLY></form>");
152 function escapeQuotes(text
) {
153 var re
=new RegExp("'","g");
154 text
=text
.replace(re
,"\\'");
155 re
=new RegExp('"',"g");
156 text
=text
.replace(re
,'"');
157 re
=new RegExp("\\n","g");
158 text
=text
.replace(re
,"\\n");
162 function escapeQuotesHTML(text
) {
163 var re
=new RegExp('"',"g");
164 text
=text
.replace(re
,""");
168 // apply tagOpen/tagClose to selection in textarea,
169 // use sampleText instead of selection if there is none
170 // copied and adapted from phpBB
171 function insertTags(tagOpen
, tagClose
, sampleText
) {
173 var txtarea
= document
.editform
.wpTextbox1
;
175 if(document
.selection
&& !is_gecko
) {
176 var theSelection
= document
.selection
.createRange().text
;
177 if(!theSelection
) { theSelection
=sampleText
;}
179 if(theSelection
.charAt(theSelection
.length
- 1) == " "){// exclude ending space char, if any
180 theSelection
= theSelection
.substring(0, theSelection
.length
- 1);
181 document
.selection
.createRange().text
= tagOpen
+ theSelection
+ tagClose
+ " ";
183 document
.selection
.createRange().text
= tagOpen
+ theSelection
+ tagClose
;
187 } else if(txtarea
.selectionStart
|| txtarea
.selectionStart
== '0') {
188 var startPos
= txtarea
.selectionStart
;
189 var endPos
= txtarea
.selectionEnd
;
190 var scrollTop
=txtarea
.scrollTop
;
191 var myText
= (txtarea
.value
).substring(startPos
, endPos
);
192 if(!myText
) { myText
=sampleText
;}
193 if(myText
.charAt(myText
.length
- 1) == " "){ // exclude ending space char, if any
194 subst
= tagOpen
+ myText
.substring(0, (myText
.length
- 1)) + tagClose
+ " ";
196 subst
= tagOpen
+ myText
+ tagClose
;
198 txtarea
.value
= txtarea
.value
.substring(0, startPos
) + subst
+
199 txtarea
.value
.substring(endPos
, txtarea
.value
.length
);
202 var cPos
=startPos
+(tagOpen
.length
+myText
.length
+tagClose
.length
);
203 txtarea
.selectionStart
=cPos
;
204 txtarea
.selectionEnd
=cPos
;
205 txtarea
.scrollTop
=scrollTop
;
209 var copy_alertText
=alertText
;
210 var re1
=new RegExp("\\$1","g");
211 var re2
=new RegExp("\\$2","g");
212 copy_alertText
=copy_alertText
.replace(re1
,sampleText
);
213 copy_alertText
=copy_alertText
.replace(re2
,tagOpen
+sampleText
+tagClose
);
216 text
=prompt(copy_alertText
);
220 if(!text
) { text
=sampleText
;}
221 text
=tagOpen
+text
+tagClose
;
222 document
.infoform
.infobox
.value
=text
;
223 // in Safari this causes scrolling
229 // reposition cursor if possible
230 if (txtarea
.createTextRange
) txtarea
.caretPos
= document
.selection
.createRange().duplicate();