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