1 // MediaWiki JavaScript support functions
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
));
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) {
13 var is_opera_preseven
= (window
.opera
&& !document
.childNodes
);
14 var is_opera_seven
= (window
.opera
&& document
.childNodes
);
17 // Global external objects used by this script.
18 /*extern ta, stylepath, skin */
20 // add any onload functions in this hook (please don't hard-code any events in the xhtml source)
23 if (!window
.onloadFuncts
) {
24 var onloadFuncts
= [];
27 function addOnloadHook(hookFunct
) {
28 // Allows add-on scripts to add onload functions
29 onloadFuncts
[onloadFuncts
.length
] = hookFunct
;
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
);
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">');
52 // Un-trap us from framesets
53 if (window
.top
!= window
) {
54 window
.top
.location
= window
.location
;
58 // for enhanced RecentChanges
59 function toggleVisibility(_levelId
, _otherId
, _linkId
) {
60 var thisLevel
= document
.getElementById(_levelId
);
61 var otherLevel
= document
.getElementById(_otherId
);
62 var linkLevel
= document
.getElementById(_linkId
);
63 if (thisLevel
.style
.display
== 'none') {
64 thisLevel
.style
.display
= 'block';
65 otherLevel
.style
.display
= 'none';
66 linkLevel
.style
.display
= 'inline';
68 thisLevel
.style
.display
= 'none';
69 otherLevel
.style
.display
= 'inline';
70 linkLevel
.style
.display
= 'none';
74 function historyRadios(parent
) {
75 var inputs
= parent
.getElementsByTagName('input');
77 for (var i
= 0; i
< inputs
.length
; i
++) {
78 if (inputs
[i
].name
== "diff" || inputs
[i
].name
== "oldid") {
79 radios
[radios
.length
] = inputs
[i
];
85 // check selection and tweak visibility/class onclick
86 function diffcheck() {
87 var dli
= false; // the li where the diff radio is checked
88 var oli
= false; // the li where the oldid radio is checked
89 var hf
= document
.getElementById('pagehistory');
93 var lis
= hf
.getElementsByTagName('li');
94 for (var i
=0;i
<lis
.length
;i
++) {
95 var inputs
= historyRadios(lis
[i
]);
96 if (inputs
[1] && inputs
[0]) {
97 if (inputs
[1].checked
|| inputs
[0].checked
) { // this row has a checked radio button
98 if (inputs
[1].checked
&& inputs
[0].checked
&& inputs
[0].value
== inputs
[1].value
) {
101 if (oli
) { // it's the second checked radio
102 if (inputs
[1].checked
) {
103 oli
.className
= "selected";
106 } else if (inputs
[0].checked
) {
109 if (inputs
[0].checked
) {
113 inputs
[0].style
.visibility
= 'hidden';
116 inputs
[1].style
.visibility
= 'hidden';
118 lis
[i
].className
= "selected";
120 } else { // no radio is checked in this row
122 inputs
[0].style
.visibility
= 'hidden';
124 inputs
[0].style
.visibility
= 'visible';
127 inputs
[1].style
.visibility
= 'hidden';
129 inputs
[1].style
.visibility
= 'visible';
131 lis
[i
].className
= "";
138 // page history stuff
139 // attach event handlers to the input elements on history page
140 function histrowinit() {
141 var hf
= document
.getElementById('pagehistory');
145 var lis
= hf
.getElementsByTagName('li');
146 for (var i
= 0; i
< lis
.length
; i
++) {
147 var inputs
= historyRadios(lis
[i
]);
148 if (inputs
[0] && inputs
[1]) {
149 inputs
[0].onclick
= diffcheck
;
150 inputs
[1].onclick
= diffcheck
;
156 // generate toc from prefs form, fold sections
157 // XXX: needs testing on IE/Mac and safari
158 // more comments to follow
159 function tabbedprefs() {
160 var prefform
= document
.getElementById('preferences');
161 if (!prefform
|| !document
.createElement
) {
164 if (prefform
.nodeName
.toLowerCase() == 'a') {
165 return; // Occasional IE problem
167 prefform
.className
= prefform
.className
+ 'jsprefs';
169 var children
= prefform
.childNodes
;
171 for (var i
= 0; i
< children
.length
; i
++) {
172 if (children
[i
].nodeName
.toLowerCase() == 'fieldset') {
173 children
[i
].id
= 'prefsection-' + seci
;
174 children
[i
].className
= 'prefsection';
175 if (is_opera
|| is_khtml
) {
176 children
[i
].className
= 'prefsection operaprefsection';
178 var legends
= children
[i
].getElementsByTagName('legend');
180 legends
[0].className
= 'mainLegend';
181 if (legends
[0] && legends
[0].firstChild
.nodeValue
) {
182 sections
[seci
].text
= legends
[0].firstChild
.nodeValue
;
184 sections
[seci
].text
= '# ' + seci
;
186 sections
[seci
].secid
= children
[i
].id
;
188 if (sections
.length
!= 1) {
189 children
[i
].style
.display
= 'none';
191 var selectedid
= children
[i
].id
;
195 var toc
= document
.createElement('ul');
197 toc
.selectedid
= selectedid
;
198 for (i
= 0; i
< sections
.length
; i
++) {
199 var li
= document
.createElement('li');
201 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
;
211 prefform
.parentNode
.insertBefore(toc
, prefform
.parentNode
.childNodes
[0]);
212 document
.getElementById('prefsubmit').id
= 'prefcontrol';
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
= '';
227 this.parentNode
.className
= 'selected';
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]);
247 function unhidetzbutton() {
248 var tzb
= document
.getElementById('guesstimezonebutton');
250 tzb
.style
.display
= 'inline';
254 // in [-]HH:MM format...
255 // won't yet work with non-even tzs
256 function fetchTimezone() {
257 // FIXME: work around Safari bug
258 var localclock
= new Date();
259 // returns negative offset from GMT in minutes
260 var tzRaw
= localclock
.getTimezoneOffset();
261 var tzHour
= Math
.floor( Math
.abs(tzRaw
) / 60);
262 var tzMin
= Math
.abs(tzRaw
) % 60;
263 var tzString
= ((tzRaw
>= 0) ? "-" : "") + ((tzHour
< 10) ? "0" : "") + tzHour
+
264 ":" + ((tzMin
< 10) ? "0" : "") + tzMin
;
268 function guessTimezone(box
) {
269 document
.getElementsByName("wpHourDiff")[0].value
= fetchTimezone();
272 function showTocToggle() {
273 if (document
.createTextNode
) {
274 // Uses DOM calls to avoid document.write + XHTML issues
276 var linkHolder
= document
.getElementById('toctitle');
281 var outerSpan
= document
.createElement('span');
282 outerSpan
.className
= 'toctoggle';
284 var toggleLink
= document
.createElement('a');
285 toggleLink
.id
= 'togglelink';
286 toggleLink
.className
= 'internal';
287 toggleLink
.href
= 'javascript:toggleToc()';
288 toggleLink
.appendChild(document
.createTextNode(tocHideText
));
290 outerSpan
.appendChild(document
.createTextNode('['));
291 outerSpan
.appendChild(toggleLink
);
292 outerSpan
.appendChild(document
.createTextNode(']'));
294 linkHolder
.appendChild(document
.createTextNode(' '));
295 linkHolder
.appendChild(outerSpan
);
297 var cookiePos
= document
.cookie
.indexOf("hidetoc=");
298 if (cookiePos
> -1 && document
.cookie
.charAt(cookiePos
+ 8) == 1) {
304 function changeText(el
, newText
) {
305 // Safari work around
307 el
.innerText
= newText
;
308 } else if (el
.firstChild
&& el
.firstChild
.nodeValue
) {
309 el
.firstChild
.nodeValue
= newText
;
313 function toggleToc() {
314 var toc
= document
.getElementById('toc').getElementsByTagName('ul')[0];
315 var toggleLink
= document
.getElementById('togglelink');
317 if (toc
&& toggleLink
&& toc
.style
.display
== 'none') {
318 changeText(toggleLink
, tocHideText
);
319 toc
.style
.display
= 'block';
320 document
.cookie
= "hidetoc=0";
322 changeText(toggleLink
, tocShowText
);
323 toc
.style
.display
= 'none';
324 document
.cookie
= "hidetoc=1";
328 var mwEditButtons
= [];
329 var mwCustomEditButtons
= []; // eg to add in MediaWiki:Common.js
331 // this function generates the actual toolbar buttons with localized text
332 // we use it to avoid creating the toolbar where javascript is not enabled
333 function addButton(imageFile
, speedTip
, tagOpen
, tagClose
, sampleText
) {
334 // Don't generate buttons for browsers which don't fully
336 mwEditButtons
[mwEditButtons
.length
] =
337 {"imageFile": imageFile
,
338 "speedTip": speedTip
,
340 "tagClose": tagClose
,
341 "sampleText": sampleText
};
344 // this function generates the actual toolbar buttons with localized text
345 // we use it to avoid creating the toolbar where javascript is not enabled
346 function mwInsertEditButton(parent
, item
) {
347 var image
= document
.createElement("img");
350 image
.src
= item
.imageFile
;
352 image
.alt
= item
.speedTip
;
353 image
.title
= item
.speedTip
;
354 image
.style
.cursor
= "pointer";
355 image
.onclick = function() {
356 insertTags(item
.tagOpen
, item
.tagClose
, item
.sampleText
);
360 parent
.appendChild(image
);
364 function mwSetupToolbar() {
365 var toolbar
= document
.getElementById('toolbar');
366 if (!toolbar
) { return false; }
368 var textbox
= document
.getElementById('wpTextbox1');
369 if (!textbox
) { return false; }
371 // Don't generate buttons for browsers which don't fully
373 if (!document
.selection
&& textbox
.selectionStart
=== null) {
377 for (var i
in mwEditButtons
) {
378 mwInsertEditButton(toolbar
, mwEditButtons
[i
]);
380 for (i
in mwCustomEditButtons
) {
381 mwInsertEditButton(toolbar
, mwCustomEditButtons
[i
]);
386 function escapeQuotes(text
) {
387 var re
= new RegExp("'","g");
388 text
= text
.replace(re
,"\\'");
389 re
= new RegExp("\\n","g");
390 text
= text
.replace(re
,"\\n");
391 return escapeQuotesHTML(text
);
394 function escapeQuotesHTML(text
) {
395 var re
= new RegExp('&',"g");
396 text
= text
.replace(re
,"&");
397 re
= new RegExp('"',"g");
398 text
= text
.replace(re
,""");
399 re
= new RegExp('<',"g");
400 text
= text
.replace(re
,"<");
401 re
= new RegExp('>',"g");
402 text
= text
.replace(re
,">");
406 // apply tagOpen/tagClose to selection in textarea,
407 // use sampleText instead of selection if there is none
408 // copied and adapted from phpBB
409 function insertTags(tagOpen
, tagClose
, sampleText
) {
411 if (document
.editform
) {
412 txtarea
= document
.editform
.wpTextbox1
;
414 // some alternate form? take the first one we can find
415 var areas
= document
.getElementsByTagName('textarea');
420 if (document
.selection
&& !is_gecko
) {
421 var theSelection
= document
.selection
.createRange().text
;
423 theSelection
=sampleText
;
426 if (theSelection
.charAt(theSelection
.length
- 1) == " ") { // exclude ending space char, if any
427 theSelection
= theSelection
.substring(0, theSelection
.length
- 1);
428 document
.selection
.createRange().text
= tagOpen
+ theSelection
+ tagClose
+ " ";
430 document
.selection
.createRange().text
= tagOpen
+ theSelection
+ tagClose
;
434 } else if(txtarea
.selectionStart
|| txtarea
.selectionStart
== '0') {
435 var replaced
= false;
436 var startPos
= txtarea
.selectionStart
;
437 var endPos
= txtarea
.selectionEnd
;
438 if (endPos
-startPos
) {
441 var scrollTop
= txtarea
.scrollTop
;
442 var myText
= (txtarea
.value
).substring(startPos
, endPos
);
447 if (myText
.charAt(myText
.length
- 1) == " ") { // exclude ending space char, if any
448 subst
= tagOpen
+ myText
.substring(0, (myText
.length
- 1)) + tagClose
+ " ";
450 subst
= tagOpen
+ myText
+ tagClose
;
452 txtarea
.value
= txtarea
.value
.substring(0, startPos
) + subst
+
453 txtarea
.value
.substring(endPos
, txtarea
.value
.length
);
457 var cPos
= startPos
+(tagOpen
.length
+myText
.length
+tagClose
.length
);
458 txtarea
.selectionStart
= cPos
;
459 txtarea
.selectionEnd
= cPos
;
461 txtarea
.selectionStart
= startPos
+tagOpen
.length
;
462 txtarea
.selectionEnd
= startPos
+tagOpen
.length
+myText
.length
;
464 txtarea
.scrollTop
= scrollTop
;
466 // All other browsers get no toolbar.
467 // There was previously support for a crippled "help"
468 // bar, but that caused more problems than it solved.
470 // reposition cursor if possible
471 if (txtarea
.createTextRange
) {
472 txtarea
.caretPos
= document
.selection
.createRange().duplicate();
477 * Set up accesskeys/tooltips. If doId is specified, only set up for that id.
478 * Note that the ta array is deprecated and will not be supported indefinite-
479 * ly -- use the accesskey/tooltip messages instead.
481 * @param mixed doId string or null
483 function akeytt( doId
) {
485 if (undefined == typeof ta
) ta
= new Object
;
486 if (is_safari
|| navigator
.userAgent
.toLowerCase().indexOf('mac') + 1
487 || navigator
.userAgent
.toLowerCase().indexOf('konqueror') + 1 ) {
489 } else if (is_opera
) {
491 } else if (is_ff2_x11
) {
492 pref
= 'ctrl-shift-';
493 } else if (is_ff2_win
) {
500 // We're only resetting one id, so don't add the pref to titles
503 // Add browser-specific pref to accesskeys set the proper way
504 els
= document
.getElementsByTagName("*");
505 for (var i
= 0; i
< els
.length
; ++i
) {
506 var element
, tit
, key
;
508 if ( (tit
= element
.getAttribute("title")) && (key
= element
.getAttribute("accesskey"))
509 && tit
.search(/\[.\]$/) != -1 ) {
510 element
.setAttribute("title", tit
.replace(/\[(.)\]$/,"["+pref
+key
+"]"));
515 // Now deal with evil deprecated ta
517 var n
= document
.getElementById(id
);
521 // Are we putting accesskey in it
522 if (ta
[id
][0].length
> 0) {
523 // Is this object a object? If not assume it's the next child.
525 if (n
.nodeName
.toLowerCase() == "a") {
530 // Don't add an accesskey for the watch tab if the watch
531 // checkbox is also available.
532 if (a
&& ((id
!= 'ca-watch' && id
!= 'ca-unwatch') ||
533 !(window
.location
.search
.match(/[\?&](action=edit|action=submit)/i)))) {
534 a
.accessKey
= ta
[id
][0];
535 ak
= ' ['+pref
+ta
[id
][0]+']';
538 // We don't care what type the object is when assigning tooltip
544 a
.title
= ta
[id
][1]+ak
;
550 function setupRightClickEdit() {
551 if (document
.getElementsByTagName
) {
552 var spans
= document
.getElementsByTagName('span');
553 for (var i
= 0; i
< spans
.length
; i
++) {
555 if(el
.className
== 'editsection') {
556 addRightClickEditHandler(el
);
562 function addRightClickEditHandler(el
) {
563 for (var i
= 0; i
< el
.childNodes
.length
; i
++) {
564 var link
= el
.childNodes
[i
];
565 if (link
.nodeType
== 1 && link
.nodeName
.toLowerCase() == 'a') {
566 var editHref
= link
.getAttribute('href');
567 // find the enclosing (parent) header
568 var prev
= el
.parentNode
;
569 if (prev
&& prev
.nodeType
== 1 &&
570 prev
.nodeName
.match(/^[Hh][1-6]$/)) {
571 prev
.oncontextmenu = function(e
) {
572 if (!e
) { e
= window
.event
; }
573 // e is now the event in all browsers
575 if (e
.target
) { targ
= e
.target
; }
576 else if (e
.srcElement
) { targ
= e
.srcElement
; }
577 if (targ
.nodeType
== 3) { // defeat Safari bug
578 targ
= targ
.parentNode
;
580 // targ is now the target element
582 // We don't want to deprive the noble reader of a context menu
583 // for the section edit link, do we? (Might want to extend this
585 if (targ
.nodeName
.toLowerCase() != 'a'
586 || targ
.parentNode
.className
!= 'editsection') {
587 document
.location
= editHref
;
597 function setupCheckboxShiftClick() {
598 if (document
.getElementsByTagName
) {
599 var uls
= document
.getElementsByTagName('ul');
600 var len
= uls
.length
;
601 for (var i
= 0; i
< len
; ++i
) {
602 addCheckboxClickHandlers(uls
[i
]);
607 function addCheckboxClickHandlers(ul
, start
, finish
) {
608 if (ul
.checkboxHandlersTimer
) {
609 clearInterval(ul
.checkboxHandlersTimer
);
611 if ( !ul
.childNodes
) {
614 var len
= ul
.childNodes
.length
;
619 finish
= finish
|| start
+ 250;
620 if ( finish
> len
) { finish
= len
; }
621 ul
.checkboxes
= ul
.checkboxes
|| [];
622 ul
.lastCheckbox
= ul
.lastCheckbox
|| null;
623 for (var i
= start
; i
<finish
; ++i
) {
624 var child
= ul
.childNodes
[i
];
625 if ( child
&& child
.childNodes
&& child
.childNodes
[0] ) {
626 var cb
= child
.childNodes
[0];
627 if ( !cb
.nodeName
|| cb
.nodeName
.toLowerCase() != 'input' ||
628 !cb
.type
|| cb
.type
.toLowerCase() != 'checkbox' ) {
631 cb
.index
= ul
.checkboxes
.push(cb
) - 1;
633 cb
.onmouseup
= checkboxMouseupHandler
;
637 var f=function(){ addCheckboxClickHandlers(ul
, finish
, finish
+250); };
638 ul
.checkboxHandlersTimer
=setInterval(f
, 200);
642 function checkboxMouseupHandler(e
) {
643 if (typeof e
== 'undefined') {
646 if ( !e
.shiftKey
|| this.container
.lastCheckbox
=== null ) {
647 this.container
.lastCheckbox
= this.index
;
650 var endState
= !this.checked
;
651 if ( is_opera
) { // opera has already toggled the checkbox by this point
652 endState
= !endState
;
655 if ( this.index
< this.container
.lastCheckbox
) {
656 start
= this.index
+ 1;
657 finish
= this.container
.lastCheckbox
;
659 start
= this.container
.lastCheckbox
;
660 finish
= this.index
- 1;
662 for (var i
= start
; i
<= finish
; ++i
) {
663 this.container
.checkboxes
[i
].checked
= endState
;
665 this.container
.lastCheckbox
= this.index
;
669 function toggle_element_activation(ida
,idb
) {
670 if (!document
.getElementById
) {
673 document
.getElementById(ida
).disabled
=true;
674 document
.getElementById(idb
).disabled
=false;
677 function toggle_element_check(ida
,idb
) {
678 if (!document
.getElementById
) {
681 document
.getElementById(ida
).checked
=true;
682 document
.getElementById(idb
).checked
=false;
685 function fillDestFilename(id
) {
686 if (!document
.getElementById
) {
689 var path
= document
.getElementById(id
).value
;
690 // Find trailing part
691 var slash
= path
.lastIndexOf('/');
692 var backslash
= path
.lastIndexOf('\\');
694 if (slash
== -1 && backslash
== -1) {
696 } else if (slash
> backslash
) {
697 fname
= path
.substring(slash
+1, 10000);
699 fname
= path
.substring(backslash
+1, 10000);
702 // Capitalise first letter and replace spaces by underscores
703 fname
= fname
.charAt(0).toUpperCase().concat(fname
.substring(1,10000)).replace(/ /g
, '_');
706 var destFile
= document
.getElementById('wpDestFile');
708 destFile
.value
= fname
;
713 function considerChangingExpiryFocus() {
714 if (!document
.getElementById
) {
717 var drop
= document
.getElementById('wpBlockExpiry');
721 var field
= document
.getElementById('wpBlockOther');
725 var opt
= drop
.value
;
726 if (opt
== 'other') {
727 field
.style
.display
= '';
729 field
.style
.display
= 'none';
733 function scrollEditBox() {
734 var editBoxEl
= document
.getElementById("wpTextbox1");
735 var scrollTopEl
= document
.getElementById("wpScrolltop");
736 var editFormEl
= document
.getElementById("editform");
738 if (editBoxEl
&& scrollTopEl
) {
739 if (scrollTopEl
.value
) { editBoxEl
.scrollTop
= scrollTopEl
.value
; }
740 editFormEl
.onsubmit = function() {
741 document
.getElementById("wpScrolltop").value
= document
.getElementById("wpTextbox1").scrollTop
;
746 hookEvent("load", scrollEditBox
);
748 var allmessages_nodelist
= false;
749 var allmessages_modified
= false;
750 var allmessages_timeout
= false;
751 var allmessages_running
= false;
753 function allmessagesmodified() {
754 allmessages_modified
= !allmessages_modified
;
758 function allmessagesfilter() {
759 if ( allmessages_timeout
)
760 window
.clearTimeout( allmessages_timeout
);
762 if ( !allmessages_running
)
763 allmessages_timeout
= window
.setTimeout( 'allmessagesfilter_do();', 500 );
766 function allmessagesfilter_do() {
767 if ( !allmessages_nodelist
)
770 var text
= document
.getElementById('allmessagesinput').value
;
771 var nodef
= allmessages_modified
;
773 allmessages_running
= true;
775 for ( var name
in allmessages_nodelist
) {
776 var nodes
= allmessages_nodelist
[name
];
777 var display
= ( name
.indexOf( text
) == -1 ? 'none' : '' );
779 for ( var i
= 0; i
< nodes
.length
; i
++)
780 nodes
[i
].style
.display
=
781 ( nodes
[i
].className
== "def" && nodef
782 ? 'none' : display
);
785 if ( text
!= document
.getElementById('allmessagesinput').value
||
786 nodef
!= allmessages_modified
)
787 allmessagesfilter_do(); // repeat
789 allmessages_running
= false;
792 function allmessagesfilter_init() {
793 if ( allmessages_nodelist
)
796 var nodelist
= new Array();
797 var templist
= new Array();
799 var table
= document
.getElementById('allmessagestable');
800 if ( !table
) return;
802 var rows
= document
.getElementsByTagName('tr');
803 for ( var i
= 0; i
< rows
.length
; i
++ ) {
804 var id
= rows
[i
].getAttribute('id')
805 if ( id
&& id
.substring(0,16) != 'sp-allmessages-r' ) continue;
806 templist
[ id
] = rows
[i
];
809 var spans
= table
.getElementsByTagName('span');
810 for ( var i
= 0; i
< spans
.length
; i
++ ) {
811 var id
= spans
[i
].getAttribute('id')
812 if ( id
&& id
.substring(0,17) != 'sp-allmessages-i-' ) continue;
813 if ( !spans
[i
].firstChild
|| spans
[i
].firstChild
.nodeType
!= 3 ) continue;
815 var nodes
= new Array();
816 var row1
= templist
[ id
.replace('i', 'r1') ];
817 var row2
= templist
[ id
.replace('i', 'r2') ];
819 if ( row1
) nodes
[nodes
.length
] = row1
;
820 if ( row2
) nodes
[nodes
.length
] = row2
;
821 nodelist
[ spans
[i
].firstChild
.nodeValue
] = nodes
;
824 var k
= document
.getElementById('allmessagesfilter');
825 if (k
) { k
.style
.display
= ''; }
827 allmessages_nodelist
= nodelist
;
830 hookEvent( "load", allmessagesfilter_init
);
833 Written by Jonathan Snook, http://www.snook.ca/jonathan
834 Add-ons by Robert Nyman, http://www.robertnyman.com
835 Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"
836 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
838 function getElementsByClassName(oElm
, strTagName
, oClassNames
){
839 var arrElements
= (strTagName
== "*" && oElm
.all
)? oElm
.all
: oElm
.getElementsByTagName(strTagName
);
840 var arrReturnElements
= new Array();
841 var arrRegExpClassNames
= new Array();
842 if(typeof oClassNames
== "object"){
843 for(var i
=0; i
<oClassNames
.length
; i
++){
844 arrRegExpClassNames
.push(new RegExp("(^|\\s)" + oClassNames
[i
].replace(/\-/g, "\\-") + "(\\s|$)"));
848 arrRegExpClassNames
.push(new RegExp("(^|\\s)" + oClassNames
.replace(/\-/g, "\\-") + "(\\s|$)"));
852 for(var j
=0; j
<arrElements
.length
; j
++){
853 oElement
= arrElements
[j
];
855 for(var k
=0; k
<arrRegExpClassNames
.length
; k
++){
856 if(!arrRegExpClassNames
[k
].test(oElement
.className
)){
862 arrReturnElements
.push(oElement
);
865 return (arrReturnElements
)
868 function sortableTables() {
869 if (getElementsByClassName(document
, "table", "sortable").length
!= 0) {
870 document
.write('<script type="text/javascript" src="'+stylepath
+'/common/sorttable.js"></script>');
874 function redirectToFragment(fragment
) {
875 var match
= navigator
.userAgent
.match(/AppleWebKit\/(\d+)/);
877 var webKitVersion
= parseInt(match
[1]);
878 if (webKitVersion
< 420) {
879 // Released Safari w/ WebKit 418.9.1 messes up horribly
880 // Nightlies of 420+ are ok
885 // Mozilla needs to wait until after load, otherwise the window doesn't scroll
886 addOnloadHook(function () {
887 if (window
.location
.hash
== "")
888 window
.location
.hash
= fragment
;
891 if (window
.location
.hash
== "")
892 window
.location
.hash
= fragment
;
896 function runOnloadHook() {
897 // don't run anything below this for non-dom browsers
898 if (doneOnloadHook
|| !(document
.getElementById
&& document
.getElementsByTagName
)) {
907 setupCheckboxShiftClick();
910 // Run any added-on functions
911 for (var i
= 0; i
< onloadFuncts
.length
; i
++) {
915 doneOnloadHook
= true;
918 //note: all skins should call runOnloadHook() at the end of html output,
919 // so the below should be redundant. It's there just in case.
920 hookEvent("load", runOnloadHook
);
922 hookEvent("load", mwSetupToolbar
);