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