Clear message cache on rebuild
[mediawiki.git] / stylesheets / wikibits.js
blob155e0609d2ccbc72445df44a85dc81517ecf098f
1 // Wikipedia JavaScript support functions
3 // for enhanced RecentChanges
4 function toggleVisibility( _levelId, _otherId, _linkId) {
5         var thisLevel = document.getElementById( _levelId );
6         var otherLevel = document.getElementById( _otherId );
7         var linkLevel = document.getElementById( _linkId );
8         if ( thisLevel.style.display == 'none' ) {
9                 thisLevel.style.display = 'block';
10                 otherLevel.style.display = 'none';
11                 linkLevel.style.display = 'inline';
12         } else {
13                 thisLevel.style.display = 'none';
14                 otherLevel.style.display = 'inline';
15                 linkLevel.style.display = 'none';
16                 }
17         }
19 // Timezone stuff
20 // tz in format [+-]HHMM
21 function checkTimezone( tz, msg ) {
22         var localclock = new Date();
23         // returns negative offset from GMT in minutes
24         var tzRaw = localclock.getTimezoneOffset();
25         var tzHour = Math.floor( Math.abs(tzRaw) / 60);
26         var tzMin = Math.abs(tzRaw) % 60;
27         var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin;
28         if( tz != tzString ) {
29                 var junk = msg.split( '$1' );
30                 document.write( junk[0] + "UTC" + tzString + junk[1] );
31         }
34 // in [-]HH:MM format...
35 // won't yet work with non-even tzs
36 function fetchTimezone() {
37         // FIXME: work around Safari bug
38         var localclock = new Date();
39         // returns negative offset from GMT in minutes
40         var tzRaw = localclock.getTimezoneOffset();
41         var tzHour = Math.floor( Math.abs(tzRaw) / 60);
42         var tzMin = Math.abs(tzRaw) % 60;
43         var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + 
44                 ":" + ((tzMin < 10) ? "0" : "") + tzMin;
45         return tzString;
48 function guessTimezone(box) {
49         document.preferences.wpHourDiff.value = fetchTimezone();
52 function showTocToggle(show,hide) {
53         if(document.getElementById) {
54                 document.writeln('<small>[<a href="javascript:toggleToc()" class="internal">' +
55                 '<span id="showlink" style="display:none;">' + show + '</span>' +
56                 '<span id="hidelink">' + hide + '</span>'
57                 + '</a>]</small>');
58         }
61 function toggleToc() {
62         var toc = document.getElementById('tocinside');
63         var showlink=document.getElementById('showlink');
64         var hidelink=document.getElementById('hidelink');
65         if(toc.style.display == 'none') {
66                 toc.style.display = tocWas;
67                 hidelink.style.display='';
68                 showlink.style.display='none';
70         } else {
71                 tocWas = toc.style.display;
72                 toc.style.display = 'none';
73                 hidelink.style.display='none';
74                 showlink.style.display='';
76         }
79 // this function generates the actual toolbar buttons with localized text
80 // we use it to avoid creating the toolbar where javascript is not enabled
81 function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
84         speedTip=escapeQuotes(speedTip);
85         tagOpen=escapeQuotes(tagOpen);
86         tagClose=escapeQuotes(tagClose);
87         sampleText=escapeQuotes(sampleText);
88         document.write("<a href=\"#\" onclick=\"javascript:insertTags");
89         document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
90         document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" ALT=\""+speedTip+"\" TITLE=\""+speedTip+"\">");
91         document.write("</a>");
92         return;
95 function addInfobox(infoText) {
97         // if no support for changing selection, add a small copy & paste field
98         var clientPC = navigator.userAgent.toLowerCase(); // Get client info
99         var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
100                 && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
101                 && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1)
102                 && (clientPC.indexOf('khtml')==-1) && (clientPC.indexOf('gecko')==-1));
103         if(!document.selection && !is_nav) {
104                 infoText=escapeQuotesHTML(infoText);
105                 document.write("<form name='infoform' id='infoform'>"+
106                         "<input size=80 id='infobox' name='infobox' value=\""+
107                         infoText+"\" READONLY></form>");
108         }
112 function escapeQuotes(text) {
113         var re=new RegExp("'","g");
114         text=text.replace(re,"\\'");
115         re=new RegExp('"',"g");
116         text=text.replace(re,'&quot;');
117         re=new RegExp("\\n","g");
118         text=text.replace(re,"\\n");
119         return text;
122 function escapeQuotesHTML(text) {
123         var re=new RegExp('"',"g");
124         text=text.replace(re,"&quot;");
125         return text;
128 // apply tagOpen/tagClose to selection in textarea,
129 // use sampleText instead of selection if there is none
130 // copied and adapted from phpBB
131 function insertTags(tagOpen, tagClose, sampleText) {
133         var txtarea = document.editform.wpTextbox1;
134         // IE
135         if(document.selection) {
136                 var theSelection = document.selection.createRange().text;
137                 if(!theSelection) { theSelection=sampleText;}
138                 txtarea.focus();
139                 if(theSelection.charAt(theSelection.length - 1) == " "){// exclude ending space char, if any
140                         theSelection = theSelection.substring(0, theSelection.length - 1);
141                         document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
142                 } else {
143                         document.selection.createRange().text = tagOpen + theSelection + tagClose;
144                 }
145         // Mozilla -- disabled because it induces a scrolling bug which makes it virtually unusable
146         } else if(false && txtarea.selectionStart || txtarea.selectionStart == '0') {
147                 var startPos = txtarea.selectionStart;
148                 var endPos = txtarea.selectionEnd;
149                 var myText = (txtarea.value).substring(startPos, endPos);
150                 if(!myText) { myText=sampleText;}
151                 if(myText.charAt(myText.length - 1) == " "){ // exclude ending space char, if any
152                         subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " "; 
153                 } else {
154                         subst = tagOpen + myText + tagClose; 
155                 }
156                 txtarea.value = txtarea.value.substring(0, startPos) + subst + txtarea.value.substring(endPos, txtarea.value.length);
157                 txtarea.focus();
158                 var cPos=startPos+(tagOpen.length+myText.length+tagClose.length);
159                 txtarea.selectionStart=cPos;
160                 txtarea.selectionEnd=cPos;
161         // All others
162         } else {
163                 // Append at the end: Some people find that annoying
164                 //txtarea.value += tagOpen + sampleText + tagClose;
165                 //txtarea.focus();
166                 var re=new RegExp("\\n","g");
167                 tagOpen=tagOpen.replace(re,"");
168                 tagClose=tagClose.replace(re,"");
169                 document.infoform.infobox.value=tagOpen+sampleText+tagClose;
170                 txtarea.focus();
171         }
172         // reposition cursor if possible
173         if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();