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