khtml fix stylesheet
[lhc/web/wiklou.git] / stylesheets / wikibits.js
1 // Wikipedia JavaScript support functions
2
3 // if this is true, the toolbar will no longer overwrite the infobox when you move the mouse over individual items
4 var noOverwrite=false;
5 var alertText;
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 var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
11 if (clientPC.indexOf('opera')!=-1) {
12 var is_opera = true;
13 var is_opera_preseven = (window.opera && !document.childNodes);
14 var is_opera_seven = (window.opera && document.childNodes);
15 }
16
17 // document.write special stylesheet links
18 function addcss ( stylepath ) {
19 if (is_opera_preseven) {
20 document.write('<link rel="stylesheet" type="text/css" href="'+stylepath+'Opera6Fixes.css">');
21 } else if (is_opera_seven) {
22 document.write('<link rel="stylesheet" type="text/css" href="'+stylepath+'Opera7Fixes.css">');
23 } else if (is_khtml) {
24 document.write('<link rel="stylesheet" type="text/css" href="'+stylepath+'KHTMLFixes.css">');
25 }
26 return;
27 }
28
29 // Un-trap us from framesets
30 if( window.top != window ) window.top.location = window.location;
31
32 // for enhanced RecentChanges
33 function toggleVisibility( _levelId, _otherId, _linkId) {
34 var thisLevel = document.getElementById( _levelId );
35 var otherLevel = document.getElementById( _otherId );
36 var linkLevel = document.getElementById( _linkId );
37 if ( thisLevel.style.display == 'none' ) {
38 thisLevel.style.display = 'block';
39 otherLevel.style.display = 'none';
40 linkLevel.style.display = 'inline';
41 } else {
42 thisLevel.style.display = 'none';
43 otherLevel.style.display = 'inline';
44 linkLevel.style.display = 'none';
45 }
46 }
47
48 // Timezone stuff
49 // tz in format [+-]HHMM
50 function checkTimezone( tz, msg ) {
51 var localclock = new Date();
52 // returns negative offset from GMT in minutes
53 var tzRaw = localclock.getTimezoneOffset();
54 var tzHour = Math.floor( Math.abs(tzRaw) / 60);
55 var tzMin = Math.abs(tzRaw) % 60;
56 var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin;
57 if( tz != tzString ) {
58 var junk = msg.split( '$1' );
59 document.write( junk[0] + "UTC" + tzString + junk[1] );
60 }
61 }
62
63 // in [-]HH:MM format...
64 // won't yet work with non-even tzs
65 function fetchTimezone() {
66 // FIXME: work around Safari bug
67 var localclock = new Date();
68 // returns negative offset from GMT in minutes
69 var tzRaw = localclock.getTimezoneOffset();
70 var tzHour = Math.floor( Math.abs(tzRaw) / 60);
71 var tzMin = Math.abs(tzRaw) % 60;
72 var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour +
73 ":" + ((tzMin < 10) ? "0" : "") + tzMin;
74 return tzString;
75 }
76
77 function guessTimezone(box) {
78 document.preferences.wpHourDiff.value = fetchTimezone();
79 }
80
81 function showTocToggle(show,hide) {
82 if(document.getElementById) {
83 document.writeln('<span class=\'toctoggle\'>[<a href="javascript:toggleToc()" class="internal">' +
84 '<span id="showlink" style="display:none;">' + show + '</span>' +
85 '<span id="hidelink">' + hide + '</span>'
86 + '</a>]</span>');
87 }
88 }
89
90 function toggleToc() {
91 var toc = document.getElementById('tocinside');
92 var showlink=document.getElementById('showlink');
93 var hidelink=document.getElementById('hidelink');
94 if(toc.style.display == 'none') {
95 toc.style.display = tocWas;
96 hidelink.style.display='';
97 showlink.style.display='none';
98
99 } else {
100 tocWas = toc.style.display;
101 toc.style.display = 'none';
102 hidelink.style.display='none';
103 showlink.style.display='';
104
105 }
106 }
107
108 // this function generates the actual toolbar buttons with localized text
109 // we use it to avoid creating the toolbar where javascript is not enabled
110 function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
111
112 speedTip=escapeQuotes(speedTip);
113 tagOpen=escapeQuotes(tagOpen);
114 tagClose=escapeQuotes(tagClose);
115 sampleText=escapeQuotes(sampleText);
116 var mouseOver="";
117
118 // we can't change the selection, so we show example texts
119 // when moving the mouse instead, until the first button is clicked
120 if(!document.selection && !is_gecko) {
121 // filter backslashes so it can be shown in the infobox
122 var re=new RegExp("\\\\n","g");
123 tagOpen=tagOpen.replace(re,"");
124 tagClose=tagClose.replace(re,"");
125 mouseOver = "onMouseover=\"if(!noOverwrite){document.infoform.infobox.value='"+tagOpen+sampleText+tagClose+"'};\"";
126 }
127
128 document.write("<a href=\"javascript:insertTags");
129 document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
130
131 document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" ALT=\""+speedTip+"\" TITLE=\""+speedTip+"\""+mouseOver+">");
132 document.write("</a>");
133 return;
134 }
135
136 function addInfobox(infoText,text_alert) {
137 alertText=text_alert;
138 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
139
140 var re=new RegExp("\\\\n","g");
141 alertText=alertText.replace(re,"\n");
142
143 // if no support for changing selection, add a small copy & paste field
144 // document.selection is an IE-only property. The full toolbar works in IE and
145 // Gecko-based browsers.
146 if(!document.selection && !is_gecko) {
147 infoText=escapeQuotesHTML(infoText);
148 document.write("<form name='infoform' id='infoform'>"+
149 "<input size=80 id='infobox' name='infobox' value=\""+
150 infoText+"\" READONLY></form>");
151 }
152
153 }
154
155 function escapeQuotes(text) {
156 var re=new RegExp("'","g");
157 text=text.replace(re,"\\'");
158 re=new RegExp('"',"g");
159 text=text.replace(re,'&quot;');
160 re=new RegExp("\\n","g");
161 text=text.replace(re,"\\n");
162 return text;
163 }
164
165 function escapeQuotesHTML(text) {
166 var re=new RegExp('"',"g");
167 text=text.replace(re,"&quot;");
168 return text;
169 }
170
171 // apply tagOpen/tagClose to selection in textarea,
172 // use sampleText instead of selection if there is none
173 // copied and adapted from phpBB
174 function insertTags(tagOpen, tagClose, sampleText) {
175
176 var txtarea = document.editform.wpTextbox1;
177 // IE
178 if(document.selection && !is_gecko) {
179 var theSelection = document.selection.createRange().text;
180 if(!theSelection) { theSelection=sampleText;}
181 txtarea.focus();
182 if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
183 theSelection = theSelection.substring(0, theSelection.length - 1);
184 document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
185 } else {
186 document.selection.createRange().text = tagOpen + theSelection + tagClose;
187 }
188
189 // Mozilla
190 } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
191 var startPos = txtarea.selectionStart;
192 var endPos = txtarea.selectionEnd;
193 var scrollTop=txtarea.scrollTop;
194 var myText = (txtarea.value).substring(startPos, endPos);
195 if(!myText) { myText=sampleText;}
196 if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
197 subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
198 } else {
199 subst = tagOpen + myText + tagClose;
200 }
201 txtarea.value = txtarea.value.substring(0, startPos) + subst +
202 txtarea.value.substring(endPos, txtarea.value.length);
203 txtarea.focus();
204
205 var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
206 txtarea.selectionStart=cPos;
207 txtarea.selectionEnd=cPos;
208 txtarea.scrollTop=scrollTop;
209
210 // All others
211 } else {
212 var copy_alertText=alertText;
213 var re1=new RegExp("\\$1","g");
214 var re2=new RegExp("\\$2","g");
215 copy_alertText=copy_alertText.replace(re1,sampleText);
216 copy_alertText=copy_alertText.replace(re2,tagOpen+sampleText+tagClose);
217 var text;
218 if (sampleText) {
219 text=prompt(copy_alertText);
220 } else {
221 text="";
222 }
223 if(!text) { text=sampleText;}
224 text=tagOpen+text+tagClose;
225 document.infoform.infobox.value=text;
226 // in Safari this causes scrolling
227 if(!is_safari) {
228 txtarea.focus();
229 }
230 noOverwrite=true;
231 }
232 // reposition cursor if possible
233 if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
234 }