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