(bug 6565) Strict JavaScript writing
[lhc/web/wiklou.git] / skins / common / wikibits.js
1 // MediaWiki JavaScript support functions
2
3 var clientPC = navigator.userAgent.toLowerCase(); // Get client info
4 var is_gecko = ((clientPC.indexOf('gecko')!=-1) && (clientPC.indexOf('spoofer')==-1)
5 && (clientPC.indexOf('khtml') == -1) && (clientPC.indexOf('netscape/7.0')==-1));
6 var is_safari = ((clientPC.indexOf('applewebkit')!=-1) && (clientPC.indexOf('spoofer')==-1));
7 var is_khtml = (navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled ));
8 if (clientPC.indexOf('opera') != -1) {
9 var is_opera = true;
10 var is_opera_preseven = (window.opera && !document.childNodes);
11 var is_opera_seven = (window.opera && document.childNodes);
12 }
13
14 // add any onload functions in this hook (please don't hard-code any events in the xhtml source)
15
16 var doneOnloadHook;
17
18 if (!window.onloadFuncts)
19 var onloadFuncts = [];
20
21 function addOnloadHook(hookFunct) {
22 // Allows add-on scripts to add onload functions
23 onloadFuncts[onloadFuncts.length] = hookFunct;
24 }
25
26 function runOnloadHook() {
27 // don't run anything below this for non-dom browsers
28 if (doneOnloadHook || !(document.getElementById && document.getElementsByTagName))
29 return;
30
31 histrowinit();
32 unhidetzbutton();
33 tabbedprefs();
34 akeytt();
35 scrollEditBox();
36 setupCheckboxShiftClick();
37
38 // Run any added-on functions
39 for (var i = 0; i < onloadFuncts.length; i++)
40 onloadFuncts[i]();
41
42 doneOnloadHook = true;
43 }
44
45 function hookEvent(hookName, hookFunct) {
46 if (window.addEventListener)
47 addEventListener(hookName, hookFunct, false);
48 else if (window.attachEvent)
49 attachEvent("on" + hookName, hookFunct);
50 }
51
52 hookEvent("load", runOnloadHook);
53
54 // document.write special stylesheet links
55 if (typeof stylepath != 'undefined' && typeof skin != 'undefined') {
56 if (is_opera_preseven) {
57 document.write('<link rel="stylesheet" type="text/css" href="'+stylepath+'/'+skin+'/Opera6Fixes.css">');
58 } else if (is_opera_seven) {
59 document.write('<link rel="stylesheet" type="text/css" href="'+stylepath+'/'+skin+'/Opera7Fixes.css">');
60 } else if (is_khtml) {
61 document.write('<link rel="stylesheet" type="text/css" href="'+stylepath+'/'+skin+'/KHTMLFixes.css">');
62 }
63 }
64 // Un-trap us from framesets
65 if (window.top != window)
66 window.top.location = window.location;
67
68 // for enhanced RecentChanges
69 function toggleVisibility(_levelId, _otherId, _linkId) {
70 var thisLevel = document.getElementById(_levelId);
71 var otherLevel = document.getElementById(_otherId);
72 var linkLevel = document.getElementById(_linkId);
73 if (thisLevel.style.display == 'none') {
74 thisLevel.style.display = 'block';
75 otherLevel.style.display = 'none';
76 linkLevel.style.display = 'inline';
77 } else {
78 thisLevel.style.display = 'none';
79 otherLevel.style.display = 'inline';
80 linkLevel.style.display = 'none';
81 }
82 }
83
84 // page history stuff
85 // attach event handlers to the input elements on history page
86 function histrowinit() {
87 var hf = document.getElementById('pagehistory');
88 if (!hf)
89 return;
90 var lis = hf.getElementsByTagName('li');
91 for (var i = 0; i < lis.length; i++) {
92 var inputs = historyRadios(lis[i]);
93 if (inputs[0] && inputs[1]) {
94 inputs[0].onclick = diffcheck;
95 inputs[1].onclick = diffcheck;
96 }
97 }
98 diffcheck();
99 }
100
101 function historyRadios(parent) {
102 var inputs = parent.getElementsByTagName('input');
103 var radios = [];
104 for (var i = 0; i < inputs.length; i++) {
105 if (inputs[i].name == "diff" || inputs[i].name == "oldid")
106 radios[radios.length] = inputs[i];
107 }
108 return radios;
109 }
110
111 // check selection and tweak visibility/class onclick
112 function diffcheck() {
113 var dli = false; // the li where the diff radio is checked
114 var oli = false; // the li where the oldid radio is checked
115 var hf = document.getElementById('pagehistory');
116 if (!hf)
117 return true;
118 var lis = hf.getElementsByTagName('li');
119 for (i=0;i<lis.length;i++) {
120 var inputs = historyRadios(lis[i]);
121 if (inputs[1] && inputs[0]) {
122 if (inputs[1].checked || inputs[0].checked) { // this row has a checked radio button
123 if (inputs[1].checked && inputs[0].checked && inputs[0].value == inputs[1].value)
124 return false;
125 if (oli) { // it's the second checked radio
126 if (inputs[1].checked) {
127 oli.className = "selected";
128 return false;
129 }
130 } else if (inputs[0].checked) {
131 return false;
132 }
133 if (inputs[0].checked)
134 dli = lis[i];
135 if (!oli)
136 inputs[0].style.visibility = 'hidden';
137 if (dli)
138 inputs[1].style.visibility = 'hidden';
139 lis[i].className = "selected";
140 oli = lis[i];
141 } else { // no radio is checked in this row
142 if (!oli)
143 inputs[0].style.visibility = 'hidden';
144 else
145 inputs[0].style.visibility = 'visible';
146 if (dli)
147 inputs[1].style.visibility = 'hidden';
148 else
149 inputs[1].style.visibility = 'visible';
150 lis[i].className = "";
151 }
152 }
153 }
154 return true;
155 }
156
157 // generate toc from prefs form, fold sections
158 // XXX: needs testing on IE/Mac and safari
159 // more comments to follow
160 function tabbedprefs() {
161 var prefform = document.getElementById('preferences');
162 if (!prefform || !document.createElement)
163 return;
164 if (prefform.nodeName.toLowerCase() == 'a')
165 return; // Occasional IE problem
166 prefform.className = prefform.className + 'jsprefs';
167 var sections = new Array();
168 var children = prefform.childNodes;
169 var seci = 0;
170 for (var i = 0; i < children.length; i++) {
171 if (children[i].nodeName.toLowerCase() == 'fieldset') {
172 children[i].id = 'prefsection-' + seci;
173 children[i].className = 'prefsection';
174 if (is_opera || is_khtml)
175 children[i].className = 'prefsection operaprefsection';
176 var legends = children[i].getElementsByTagName('legend');
177 sections[seci] = new Object();
178 legends[0].className = 'mainLegend';
179 if (legends[0] && legends[0].firstChild.nodeValue)
180 sections[seci].text = legends[0].firstChild.nodeValue;
181 else
182 sections[seci].text = '# ' + seci;
183 sections[seci].secid = children[i].id;
184 seci++;
185 if (sections.length != 1)
186 children[i].style.display = 'none';
187 else
188 var selectedid = children[i].id;
189 }
190 }
191 var toc = document.createElement('ul');
192 toc.id = 'preftoc';
193 toc.selectedid = selectedid;
194 for (i = 0; i < sections.length; i++) {
195 var li = document.createElement('li');
196 if (i == 0)
197 li.className = 'selected';
198 var a = document.createElement('a');
199 a.href = '#' + sections[i].secid;
200 a.onmousedown = a.onclick = uncoversection;
201 a.appendChild(document.createTextNode(sections[i].text));
202 a.secid = sections[i].secid;
203 li.appendChild(a);
204 toc.appendChild(li);
205 }
206 prefform.parentNode.insertBefore(toc, prefform.parentNode.childNodes[0]);
207 document.getElementById('prefsubmit').id = 'prefcontrol';
208 }
209
210 function uncoversection() {
211 var oldsecid = this.parentNode.parentNode.selectedid;
212 var newsec = document.getElementById(this.secid);
213 if (oldsecid != this.secid) {
214 var ul = document.getElementById('preftoc');
215 document.getElementById(oldsecid).style.display = 'none';
216 newsec.style.display = 'block';
217 ul.selectedid = this.secid;
218 var lis = ul.getElementsByTagName('li');
219 for (var i = 0; i< lis.length; i++) {
220 lis[i].className = '';
221 }
222 this.parentNode.className = 'selected';
223 }
224 return false;
225 }
226
227 // Timezone stuff
228 // tz in format [+-]HHMM
229 function checkTimezone(tz, msg) {
230 var localclock = new Date();
231 // returns negative offset from GMT in minutes
232 var tzRaw = localclock.getTimezoneOffset();
233 var tzHour = Math.floor( Math.abs(tzRaw) / 60);
234 var tzMin = Math.abs(tzRaw) % 60;
235 var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin;
236 if (tz != tzString) {
237 var junk = msg.split('$1');
238 document.write(junk[0] + "UTC" + tzString + junk[1]);
239 }
240 }
241
242 function unhidetzbutton() {
243 var tzb = document.getElementById('guesstimezonebutton');
244 if (tzb)
245 tzb.style.display = 'inline';
246 }
247
248 // in [-]HH:MM format...
249 // won't yet work with non-even tzs
250 function fetchTimezone() {
251 // FIXME: work around Safari bug
252 var localclock = new Date();
253 // returns negative offset from GMT in minutes
254 var tzRaw = localclock.getTimezoneOffset();
255 var tzHour = Math.floor( Math.abs(tzRaw) / 60);
256 var tzMin = Math.abs(tzRaw) % 60;
257 var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour +
258 ":" + ((tzMin < 10) ? "0" : "") + tzMin;
259 return tzString;
260 }
261
262 function guessTimezone(box) {
263 document.getElementsByName("wpHourDiff")[0].value = fetchTimezone();
264 }
265
266 function showTocToggle() {
267 if (document.createTextNode) {
268 // Uses DOM calls to avoid document.write + XHTML issues
269
270 var linkHolder = document.getElementById('toctitle')
271 if (!linkHolder)
272 return;
273
274 var outerSpan = document.createElement('span');
275 outerSpan.className = 'toctoggle';
276
277 var toggleLink = document.createElement('a');
278 toggleLink.id = 'togglelink';
279 toggleLink.className = 'internal';
280 toggleLink.href = 'javascript:toggleToc()';
281 toggleLink.appendChild(document.createTextNode(tocHideText));
282
283 outerSpan.appendChild(document.createTextNode('['));
284 outerSpan.appendChild(toggleLink);
285 outerSpan.appendChild(document.createTextNode(']'));
286
287 linkHolder.appendChild(document.createTextNode(' '));
288 linkHolder.appendChild(outerSpan);
289
290 var cookiePos = document.cookie.indexOf("hidetoc=");
291 if (cookiePos > -1 && document.cookie.charAt(cookiePos + 8) == 1)
292 toggleToc();
293 }
294 }
295
296 function changeText(el, newText) {
297 // Safari work around
298 if (el.innerText)
299 el.innerText = newText;
300 else if (el.firstChild && el.firstChild.nodeValue)
301 el.firstChild.nodeValue = newText;
302 }
303
304 function toggleToc() {
305 var toc = document.getElementById('toc').getElementsByTagName('ul')[0];
306 var toggleLink = document.getElementById('togglelink')
307
308 if (toc && toggleLink && toc.style.display == 'none') {
309 changeText(toggleLink, tocHideText);
310 toc.style.display = 'block';
311 document.cookie = "hidetoc=0";
312 } else {
313 changeText(toggleLink, tocShowText);
314 toc.style.display = 'none';
315 document.cookie = "hidetoc=1";
316 }
317 }
318
319 var mwEditButtons = [];
320 var mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js
321
322 // this function generates the actual toolbar buttons with localized text
323 // we use it to avoid creating the toolbar where javascript is not enabled
324 function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
325 // Don't generate buttons for browsers which don't fully
326 // support it.
327 mwEditButtons[mwEditButtons.length] =
328 {"imageFile": imageFile,
329 "speedTip": speedTip,
330 "tagOpen": tagOpen,
331 "tagClose": tagClose,
332 "sampleText": sampleText};
333 }
334
335 // this function generates the actual toolbar buttons with localized text
336 // we use it to avoid creating the toolbar where javascript is not enabled
337 function mwInsertEditButton(parent, item) {
338 var image = document.createElement("img");
339 image.width = 23;
340 image.height = 22;
341 image.src = item.imageFile;
342 image.border = 0;
343 image.alt = item.speedTip;
344 image.title = item.speedTip;
345 image.style.cursor = "pointer";
346 image.onclick = function() {
347 insertTags(item.tagOpen, item.tagClose, item.sampleText);
348 return false;
349 }
350
351 parent.appendChild(image);
352 return true;
353 }
354
355 function mwSetupToolbar() {
356 var toolbar = document.getElementById('toolbar');
357 if (!toolbar) return false;
358
359 var textbox = document.getElementById('wpTextbox1');
360 if (!textbox) return false;
361
362 // Don't generate buttons for browsers which don't fully
363 // support it.
364 if (!document.selection && textbox.selectionStart == null)
365 return false;
366
367 for (var i in mwEditButtons) {
368 mwInsertEditButton(toolbar, mwEditButtons[i]);
369 }
370 for (var i in mwCustomEditButtons) {
371 mwInsertEditButton(toolbar, mwCustomEditButtons[i]);
372 }
373 return true;
374 }
375
376 function escapeQuotes(text) {
377 var re = new RegExp("'","g");
378 text = text.replace(re,"\\'");
379 re = new RegExp("\\n","g");
380 text = text.replace(re,"\\n");
381 return escapeQuotesHTML(text);
382 }
383
384 function escapeQuotesHTML(text) {
385 var re = new RegExp('&',"g");
386 text = text.replace(re,"&amp;");
387 var re = new RegExp('"',"g");
388 text = text.replace(re,"&quot;");
389 var re = new RegExp('<',"g");
390 text = text.replace(re,"&lt;");
391 var re = new RegExp('>',"g");
392 text = text.replace(re,"&gt;");
393 return text;
394 }
395
396 // apply tagOpen/tagClose to selection in textarea,
397 // use sampleText instead of selection if there is none
398 // copied and adapted from phpBB
399 function insertTags(tagOpen, tagClose, sampleText) {
400 if (document.editform)
401 var txtarea = document.editform.wpTextbox1;
402 else {
403 // some alternate form? take the first one we can find
404 var areas = document.getElementsByTagName('textarea');
405 var txtarea = areas[0];
406 }
407
408 // IE
409 if (document.selection && !is_gecko) {
410 var theSelection = document.selection.createRange().text;
411 if (!theSelection)
412 theSelection=sampleText;
413 txtarea.focus();
414 if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
415 theSelection = theSelection.substring(0, theSelection.length - 1);
416 document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
417 } else {
418 document.selection.createRange().text = tagOpen + theSelection + tagClose;
419 }
420
421 // Mozilla
422 } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
423 var replaced = false;
424 var startPos = txtarea.selectionStart;
425 var endPos = txtarea.selectionEnd;
426 if (endPos-startPos)
427 replaced = true;
428 var scrollTop = txtarea.scrollTop;
429 var myText = (txtarea.value).substring(startPos, endPos);
430 if (!myText)
431 myText=sampleText;
432 if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
433 subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
434 } else {
435 subst = tagOpen + myText + tagClose;
436 }
437 txtarea.value = txtarea.value.substring(0, startPos) + subst +
438 txtarea.value.substring(endPos, txtarea.value.length);
439 txtarea.focus();
440 //set new selection
441 if (replaced) {
442 var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
443 txtarea.selectionStart = cPos;
444 txtarea.selectionEnd = cPos;
445 } else {
446 txtarea.selectionStart = startPos+tagOpen.length;
447 txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
448 }
449 txtarea.scrollTop = scrollTop;
450
451 // All other browsers get no toolbar.
452 // There was previously support for a crippled "help"
453 // bar, but that caused more problems than it solved.
454 }
455 // reposition cursor if possible
456 if (txtarea.createTextRange)
457 txtarea.caretPos = document.selection.createRange().duplicate();
458 }
459
460 function akeytt() {
461 if (typeof ta == "undefined" || !ta)
462 return;
463 var pref = 'alt-';
464 if (is_safari || navigator.userAgent.toLowerCase().indexOf('mac') + 1
465 || navigator.userAgent.toLowerCase().indexOf('konqueror') + 1 )
466 pref = 'control-';
467 if (is_opera)
468 pref = 'shift-esc-';
469
470 for (var id in ta) {
471 var n = document.getElementById(id);
472 if (n) {
473 var a = null;
474 var ak = '';
475 // Are we putting accesskey in it
476 if (ta[id][0].length > 0) {
477 // Is this object a object? If not assume it's the next child.
478
479 if (n.nodeName.toLowerCase() == "a") {
480 a = n;
481 } else {
482 a = n.childNodes[0];
483 }
484
485 if (a) {
486 a.accessKey = ta[id][0];
487 ak = ' ['+pref+ta[id][0]+']';
488 }
489 } else {
490 // We don't care what type the object is when assigning tooltip
491 a = n;
492 ak = '';
493 }
494
495 if (a) {
496 a.title = ta[id][1]+ak;
497 }
498 }
499 }
500 }
501
502 function setupRightClickEdit() {
503 if (document.getElementsByTagName) {
504 var divs = document.getElementsByTagName('div');
505 for (var i = 0; i < divs.length; i++) {
506 var el = divs[i];
507 if(el.className == 'editsection') {
508 addRightClickEditHandler(el);
509 }
510 }
511 }
512 }
513
514 function addRightClickEditHandler(el) {
515 for (var i = 0; i < el.childNodes.length; i++) {
516 var link = el.childNodes[i];
517 if (link.nodeType == 1 && link.nodeName.toLowerCase() == 'a') {
518 var editHref = link.getAttribute('href');
519
520 // find the following a
521 var next = el.nextSibling;
522 while (next.nodeType != 1)
523 next = next.nextSibling;
524
525 // find the following header
526 next = next.nextSibling;
527 while (next.nodeType != 1)
528 next = next.nextSibling;
529
530 if (next && next.nodeType == 1 &&
531 next.nodeName.match(/^[Hh][1-6]$/)) {
532 next.oncontextmenu = function() {
533 document.location = editHref;
534 return false;
535 }
536 }
537 }
538 }
539 }
540
541 function setupCheckboxShiftClick() {
542 if (document.getElementsByTagName) {
543 var uls = document.getElementsByTagName('ul');
544 var len = uls.length;
545 for (var i = 0; i < len; ++i) {
546 addCheckboxClickHandlers(uls[i]);
547 }
548 }
549 }
550
551 function addCheckboxClickHandlers(ul, start, finish) {
552 if (ul.checkboxHandlersTimer) {
553 clearInterval(ul.checkboxHandlersTimer);
554 }
555 if ( !ul.childNodes ) {
556 return;
557 }
558 var len = ul.childNodes.length;
559 if (len < 2) {
560 return;
561 }
562 start = start || 0;
563 finish = finish || start + 250;
564 if ( finish > len ) { finish = len; }
565 ul.checkboxes = ul.checkboxes || [];
566 ul.lastCheckbox = ul.lastCheckbox || null;
567 for (var i = start; i<finish; ++i) {
568 var child = ul.childNodes[i];
569 if ( child && child.childNodes && child.childNodes[0] ) {
570 var cb = child.childNodes[0];
571 if ( !cb.nodeName || cb.nodeName.toLowerCase() != 'input' ||
572 !cb.type || cb.type.toLowerCase() != 'checkbox' ) {
573 return;
574 }
575 cb.index = ul.checkboxes.push(cb) - 1;
576 cb.container = ul;
577 cb.onmouseup = checkboxMouseupHandler;
578 }
579 }
580 if (finish < len) {
581 var f=function(){ addCheckboxClickHandlers(ul, finish, finish+250); };
582 ul.checkboxHandlersTimer=setInterval(f, 200);
583 }
584 }
585
586 function checkboxMouseupHandler(e) {
587 if (typeof e == 'undefined') {
588 e = window.event;
589 }
590 if ( !e.shiftKey || this.container.lastCheckbox === null ) {
591 this.container.lastCheckbox = this.index;
592 return true;
593 }
594 var endState = !this.checked;
595 if ( is_opera ) { // opera has already toggled the checkbox by this point
596 endState = !endState;
597 }
598 var start, finish;
599 if ( this.index < this.container.lastCheckbox ) {
600 start = this.index + 1;
601 finish = this.container.lastCheckbox;
602 } else {
603 start = this.container.lastCheckbox;
604 finish = this.index - 1;
605 }
606 for (var i = start; i <= finish; ++i ) {
607 this.container.checkboxes[i].checked = endState;
608 }
609 this.container.lastCheckbox = this.index;
610 return true;
611 }
612
613 function fillDestFilename() {
614 if (!document.getElementById)
615 return;
616 var path = document.getElementById('wpUploadFile').value;
617 // Find trailing part
618 var slash = path.lastIndexOf('/');
619 var backslash = path.lastIndexOf('\\');
620 var fname;
621 if (slash == -1 && backslash == -1) {
622 fname = path;
623 } else if (slash > backslash) {
624 fname = path.substring(slash+1, 10000);
625 } else {
626 fname = path.substring(backslash+1, 10000);
627 }
628
629 // Capitalise first letter and replace spaces by underscores
630 fname = fname.charAt(0).toUpperCase().concat(fname.substring(1,10000)).replace(/ /g, '_');
631
632 // Output result
633 var destFile = document.getElementById('wpDestFile');
634 if (destFile)
635 destFile.value = fname;
636 }
637
638
639 function considerChangingExpiryFocus() {
640 if (!document.getElementById)
641 return;
642 var drop = document.getElementById('wpBlockExpiry');
643 if (!drop)
644 return;
645 var field = document.getElementById('wpBlockOther');
646 if (!field)
647 return;
648 var opt = drop.value;
649 if (opt == 'other')
650 field.style.display = '';
651 else
652 field.style.display = 'none';
653 }
654
655 function scrollEditBox() {
656 var editBoxEl = document.getElementById("wpTextbox1");
657 var scrollTopEl = document.getElementById("wpScrolltop");
658 var editFormEl = document.getElementById("editform");
659
660 if (editBoxEl && scrollTopEl) {
661 if (scrollTopEl.value) editBoxEl.scrollTop = scrollTopEl.value;
662 editFormEl.onsubmit = function() {
663 document.getElementById("wpScrolltop").value = document.getElementById("wpTextbox1").scrollTop;
664 }
665 }
666 }
667
668 hookEvent("load", scrollEditBox);
669
670 function allmessagesfilter() {
671 text = document.getElementById('allmessagesinput').value;
672 k = document.getElementById('allmessagestable');
673 if (!k) { return;}
674
675 var items = k.getElementsByTagName('span');
676
677 if ( text.length > allmessages_prev.length ) {
678 for (var i = items.length-1, j = 0; i >= 0; i--) {
679 j = allmessagesforeach(items, i, j);
680 }
681 } else {
682 for (var i = 0, j = 0; i < items.length; i++) {
683 j = allmessagesforeach(items, i, j);
684 }
685 }
686 allmessages_prev = text;
687 }
688
689 function allmessagesforeach(items, i, j) {
690 var hItem = items[i].getAttribute('id');
691 if (hItem.substring(0,17) == 'sp-allmessages-i-') {
692 if (items[i].firstChild && items[i].firstChild.nodeName == '#text' && items[i].firstChild.nodeValue.indexOf(text) != -1) {
693 var itemA = document.getElementById( hItem.replace('i', 'r1') );
694 var itemB = document.getElementById( hItem.replace('i', 'r2') );
695 if ( itemA.style.display != '' ) {
696 var s = "allmessageshider(\"" + hItem.replace('i', 'r1') + "\", \"" + hItem.replace('i', 'r2') + "\", '')";
697 var k = window.setTimeout(s,j++*5);
698 }
699 } else {
700 var itemA = document.getElementById( hItem.replace('i', 'r1') );
701 var itemB = document.getElementById( hItem.replace('i', 'r2') );
702 if ( itemA.style.display != 'none' ) {
703 var s = "allmessageshider(\"" + hItem.replace('i', 'r1') + "\", \"" + hItem.replace('i', 'r2') + "\", 'none')";
704 var k = window.setTimeout(s,j++*5);
705 }
706 }
707 }
708 return j;
709 }
710
711
712 function allmessageshider(idA, idB, cstyle) {
713 var itemA = document.getElementById( idA );
714 var itemB = document.getElementById( idB );
715 if (itemA) { itemA.style.display = cstyle; }
716 if (itemB) { itemB.style.display = cstyle; }
717 }
718
719 function allmessagesmodified() {
720 allmessages_modified = !allmessages_modified;
721 k = document.getElementById('allmessagestable');
722 if (!k) { return;}
723 var items = k.getElementsByTagName('tr');
724 for (var i = 0, j = 0; i< items.length; i++) {
725 if (!allmessages_modified ) {
726 if ( items[i].style.display != '' ) {
727 var s = "allmessageshider(\"" + items[i].getAttribute('id') + "\", null, '')";
728 var k = window.setTimeout(s,j++*5);
729 }
730 } else if (items[i].getAttribute('class') == 'def' && allmessages_modified) {
731 if ( items[i].style.display != 'none' ) {
732 var s = "allmessageshider(\"" + items[i].getAttribute('id') + "\", null, 'none')";
733 var k = window.setTimeout(s,j++*5);
734 }
735 }
736 }
737 }
738
739 function allmessagesshow() {
740 k = document.getElementById('allmessagesfilter');
741 if (k) { k.style.display = ''; }
742
743 allmessages_prev = '';
744 allmessages_modified = false;
745 }
746
747 hookEvent("load", allmessagesshow);
748 hookEvent("load", mwSetupToolbar);