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