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