1 // MediaWiki JavaScript support functions
3 var clientPC
= navigator
.userAgent
.toLowerCase(); // Get client info
4 var is_gecko
= /gecko/.test( clientPC
) &&
5 !/khtml|spoofer|netscape\/7\.0/.test(clientPC
);
6 var is_safari
= clientPC
.indexOf('applewebkit') != -1 &&
7 clientPC
.indexOf('spoofer') == -1;
8 var is_khtml
= navigator
.vendor
== 'KDE' ||
9 ( document
.childNodes
&& !document
.all
&& !navigator
.taintEnabled
);
10 // For accesskeys; note that FF3+ is included here!
11 var is_ff2
= /firefox\/[2-9]|minefield\/3/.test( clientPC
);
12 // These aren't used here, but some custom scripts rely on them
13 var is_ff2_win
= is_ff2
&& clientPC
.indexOf('windows') != -1;
14 var is_ff2_x11
= is_ff2
&& clientPC
.indexOf('x11') != -1;
15 if (clientPC
.indexOf('opera') != -1) {
17 var is_opera_preseven
= window
.opera
&& !document
.childNodes
;
18 var is_opera_seven
= window
.opera
&& document
.childNodes
;
19 var is_opera_95
= /opera\/(9.[5-9]|[1-9][0-9])/.test( clientPC
);
22 // Global external objects used by this script.
23 /*extern ta, stylepath, skin */
25 // add any onload functions in this hook (please don't hard-code any events in the xhtml source)
28 if (!window
.onloadFuncts
) {
29 var onloadFuncts
= [];
32 function addOnloadHook(hookFunct
) {
33 // Allows add-on scripts to add onload functions
34 onloadFuncts
[onloadFuncts
.length
] = hookFunct
;
37 function hookEvent(hookName
, hookFunct
) {
38 if (window
.addEventListener
) {
39 window
.addEventListener(hookName
, hookFunct
, false);
40 } else if (window
.attachEvent
) {
41 window
.attachEvent("on" + hookName
, hookFunct
);
45 // document.write special stylesheet links
46 if (typeof stylepath
!= 'undefined' && typeof skin
!= 'undefined') {
47 if (is_opera_preseven
) {
48 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'/'+skin
+'/Opera6Fixes.css">');
49 } else if (is_opera_seven
&& !is_opera_95
) {
50 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'/'+skin
+'/Opera7Fixes.css">');
51 } else if (is_khtml
) {
52 document
.write('<link rel="stylesheet" type="text/css" href="'+stylepath
+'/'+skin
+'/KHTMLFixes.css">');
57 // Un-trap us from framesets
58 if (window
.top
!= window
) {
59 window
.top
.location
= window
.location
;
63 // for enhanced RecentChanges
64 function toggleVisibility(_levelId
, _otherId
, _linkId
) {
65 var thisLevel
= document
.getElementById(_levelId
);
66 var otherLevel
= document
.getElementById(_otherId
);
67 var linkLevel
= document
.getElementById(_linkId
);
68 if (thisLevel
.style
.display
== 'none') {
69 thisLevel
.style
.display
= 'block';
70 otherLevel
.style
.display
= 'none';
71 linkLevel
.style
.display
= 'inline';
73 thisLevel
.style
.display
= 'none';
74 otherLevel
.style
.display
= 'inline';
75 linkLevel
.style
.display
= 'none';
79 function showTocToggle() {
80 if (document
.createTextNode
) {
81 // Uses DOM calls to avoid document.write + XHTML issues
83 var linkHolder
= document
.getElementById('toctitle');
88 var outerSpan
= document
.createElement('span');
89 outerSpan
.className
= 'toctoggle';
91 var toggleLink
= document
.createElement('a');
92 toggleLink
.id
= 'togglelink';
93 toggleLink
.className
= 'internal';
94 toggleLink
.href
= 'javascript:toggleToc()';
95 toggleLink
.appendChild(document
.createTextNode(tocHideText
));
97 outerSpan
.appendChild(document
.createTextNode('['));
98 outerSpan
.appendChild(toggleLink
);
99 outerSpan
.appendChild(document
.createTextNode(']'));
101 linkHolder
.appendChild(document
.createTextNode(' '));
102 linkHolder
.appendChild(outerSpan
);
104 var cookiePos
= document
.cookie
.indexOf("hidetoc=");
105 if (cookiePos
> -1 && document
.cookie
.charAt(cookiePos
+ 8) == 1) {
111 function changeText(el
, newText
) {
112 // Safari work around
114 el
.innerText
= newText
;
115 } else if (el
.firstChild
&& el
.firstChild
.nodeValue
) {
116 el
.firstChild
.nodeValue
= newText
;
120 function toggleToc() {
121 var toc
= document
.getElementById('toc').getElementsByTagName('ul')[0];
122 var toggleLink
= document
.getElementById('togglelink');
124 if (toc
&& toggleLink
&& toc
.style
.display
== 'none') {
125 changeText(toggleLink
, tocHideText
);
126 toc
.style
.display
= 'block';
127 document
.cookie
= "hidetoc=0";
129 changeText(toggleLink
, tocShowText
);
130 toc
.style
.display
= 'none';
131 document
.cookie
= "hidetoc=1";
135 var mwEditButtons
= [];
136 var mwCustomEditButtons
= []; // eg to add in MediaWiki:Common.js
138 function escapeQuotes(text
) {
139 var re
= new RegExp("'","g");
140 text
= text
.replace(re
,"\\'");
141 re
= new RegExp("\\n","g");
142 text
= text
.replace(re
,"\\n");
143 return escapeQuotesHTML(text
);
146 function escapeQuotesHTML(text
) {
147 var re
= new RegExp('&',"g");
148 text
= text
.replace(re
,"&");
149 re
= new RegExp('"',"g");
150 text
= text
.replace(re
,""");
151 re
= new RegExp('<',"g");
152 text
= text
.replace(re
,"<");
153 re
= new RegExp('>',"g");
154 text
= text
.replace(re
,">");
160 * Set the accesskey prefix based on browser detection.
162 var tooltipAccessKeyPrefix
= 'alt-';
164 tooltipAccessKeyPrefix
= 'shift-esc-';
166 || navigator
.userAgent
.toLowerCase().indexOf('mac') != -1
167 || navigator
.userAgent
.toLowerCase().indexOf('konqueror') != -1 ) {
168 tooltipAccessKeyPrefix
= 'ctrl-';
170 tooltipAccessKeyPrefix
= 'alt-shift-';
172 var tooltipAccessKeyRegexp
= /\[(ctrl-)?(alt-)?(shift-)?(esc-)?.\]$/;
175 * Add the appropriate prefix to the accesskey shown in the tooltip.
176 * If the nodeList parameter is given, only those nodes are updated;
177 * otherwise, all the nodes that will probably have accesskeys by
178 * default are updated.
180 * @param Array nodeList -- list of elements to update
182 function updateTooltipAccessKeys( nodeList
) {
184 // skins without a "column-one" element don't seem to have links with accesskeys either
185 var columnOne
= document
.getElementById("column-one");
187 updateTooltipAccessKeys( columnOne
.getElementsByTagName("a") );
188 // these are rare enough that no such optimization is needed
189 updateTooltipAccessKeys( document
.getElementsByTagName("input") );
190 updateTooltipAccessKeys( document
.getElementsByTagName("label") );
194 for ( var i
= 0; i
< nodeList
.length
; i
++ ) {
195 var element
= nodeList
[i
];
196 var tip
= element
.getAttribute("title");
197 var key
= element
.getAttribute("accesskey");
198 if ( key
&& tooltipAccessKeyRegexp
.exec(tip
) ) {
199 tip
= tip
.replace(tooltipAccessKeyRegexp
,
200 "["+tooltipAccessKeyPrefix
+key
+"]");
201 element
.setAttribute("title", tip
);
207 * Add a link to one of the portlet menus on the page, including:
209 * p-cactions: Content actions (shown as tabs above the main content in Monobook)
210 * p-personal: Personal tools (shown at the top right of the page in Monobook)
211 * p-navigation: Navigation
214 * This function exists for the convenience of custom JS authors. All
215 * but the first three parameters are optional, though providing at
216 * least an id and a tooltip is recommended.
218 * By default the new link will be added to the end of the list. To
219 * add the link before a given existing item, pass the DOM node of
220 * that item (easily obtained with document.getElementById()) as the
221 * nextnode parameter; to add the link _after_ an existing item, pass
222 * the node's nextSibling instead.
224 * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb")
225 * @param String href -- link URL
226 * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook)
227 * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-")
228 * @param String tooltip -- text to show when hovering over the link, without accesskey suffix
229 * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts)
230 * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list
232 * @return Node -- the DOM node of the new item (an LI element) or null
234 function addPortletLink(portlet
, href
, text
, id
, tooltip
, accesskey
, nextnode
) {
235 var node
= document
.getElementById(portlet
);
236 if ( !node
) return null;
237 node
= node
.getElementsByTagName( "ul" )[0];
238 if ( !node
) return null;
240 var link
= document
.createElement( "a" );
241 link
.appendChild( document
.createTextNode( text
) );
244 var item
= document
.createElement( "li" );
245 item
.appendChild( link
);
246 if ( id
) item
.id
= id
;
249 link
.setAttribute( "accesskey", accesskey
);
250 tooltip
+= " ["+accesskey
+"]";
253 link
.setAttribute( "title", tooltip
);
255 if ( accesskey
&& tooltip
) {
256 updateTooltipAccessKeys( new Array( link
) );
259 if ( nextnode
&& nextnode
.parentNode
== node
)
260 node
.insertBefore( item
, nextnode
);
262 node
.appendChild( item
); // IE compatibility (?)
269 * Set up accesskeys/tooltips from the deprecated ta array. If doId
270 * is specified, only set up for that id. Note that this function is
271 * deprecated and will not be supported indefinitely -- use
272 * updateTooltipAccessKey() instead.
274 * @param mixed doId string or null
276 function akeytt( doId
) {
277 // A lot of user scripts (and some of the code below) break if
278 // ta isn't defined, so we make sure it is. Explictly using
279 // window.ta avoids a "ta is not defined" error.
280 if (!window
.ta
) window
.ta
= new Array
;
282 // Make a local, possibly restricted, copy to avoid clobbering
291 // Now deal with evil deprecated ta
292 var watchCheckboxExists
= document
.getElementById( 'wpWatchthis' ) ? true : false;
294 var n
= document
.getElementById(id
);
298 // Are we putting accesskey in it
299 if (ta
[id
][0].length
> 0) {
300 // Is this object a object? If not assume it's the next child.
302 if (n
.nodeName
.toLowerCase() == "a") {
307 // Don't add an accesskey for the watch tab if the watch
308 // checkbox is also available.
309 if (a
&& ((id
!= 'ca-watch' && id
!= 'ca-unwatch') || !watchCheckboxExists
)) {
310 a
.accessKey
= ta
[id
][0];
311 ak
= ' ['+tooltipAccessKeyPrefix
+ta
[id
][0]+']';
314 // We don't care what type the object is when assigning tooltip
320 a
.title
= ta
[id
][1]+ak
;
329 function setupCheckboxShiftClick() {
332 var inputs
= document
.getElementsByTagName('input');
333 addCheckboxClickHandlers(inputs
);
336 function addCheckboxClickHandlers(inputs
, start
) {
337 if ( !start
) start
= 0;
339 var finish
= start
+ 250;
340 if ( finish
> inputs
.length
)
341 finish
= inputs
.length
;
343 for ( var i
= start
; i
< finish
; i
++ ) {
345 if ( !cb
.type
|| cb
.type
.toLowerCase() != 'checkbox' )
347 var end
= checkboxes
.length
;
348 checkboxes
[end
] = cb
;
350 cb
.onclick
= checkboxClickHandler
;
353 if ( finish
< inputs
.length
) {
354 setTimeout( function () {
355 addCheckboxClickHandlers(inputs
, finish
);
360 function checkboxClickHandler(e
) {
361 if (typeof e
== 'undefined') {
364 if ( !e
.shiftKey
|| lastCheckbox
=== null ) {
365 lastCheckbox
= this.index
;
368 var endState
= this.checked
;
370 if ( this.index
< lastCheckbox
) {
371 start
= this.index
+ 1;
372 finish
= lastCheckbox
;
374 start
= lastCheckbox
;
375 finish
= this.index
- 1;
377 for (var i
= start
; i
<= finish
; ++i
) {
378 checkboxes
[i
].checked
= endState
;
380 lastCheckbox
= this.index
;
384 function toggle_element_activation(ida
,idb
) {
385 if (!document
.getElementById
) {
388 document
.getElementById(ida
).disabled
=true;
389 document
.getElementById(idb
).disabled
=false;
392 function toggle_element_check(ida
,idb
) {
393 if (!document
.getElementById
) {
396 document
.getElementById(ida
).checked
=true;
397 document
.getElementById(idb
).checked
=false;
401 Written by Jonathan Snook, http://www.snook.ca/jonathan
402 Add-ons by Robert Nyman, http://www.robertnyman.com
403 Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"
404 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
406 function getElementsByClassName(oElm
, strTagName
, oClassNames
){
407 var arrElements
= (strTagName
== "*" && oElm
.all
)? oElm
.all
: oElm
.getElementsByTagName(strTagName
);
408 var arrReturnElements
= new Array();
409 var arrRegExpClassNames
= new Array();
410 if(typeof oClassNames
== "object"){
411 for(var i
=0; i
<oClassNames
.length
; i
++){
412 arrRegExpClassNames
[arrRegExpClassNames
.length
] =
413 new RegExp("(^|\\s)" + oClassNames
[i
].replace(/\-/g, "\\-") + "(\\s|$)");
417 arrRegExpClassNames
[arrRegExpClassNames
.length
] =
418 new RegExp("(^|\\s)" + oClassNames
.replace(/\-/g, "\\-") + "(\\s|$)");
422 for(var j
=0; j
<arrElements
.length
; j
++){
423 oElement
= arrElements
[j
];
425 for(var k
=0; k
<arrRegExpClassNames
.length
; k
++){
426 if(!arrRegExpClassNames
[k
].test(oElement
.className
)){
432 arrReturnElements
[arrReturnElements
.length
] = oElement
;
435 return (arrReturnElements
)
438 function redirectToFragment(fragment
) {
439 var match
= navigator
.userAgent
.match(/AppleWebKit\/(\d+)/);
441 var webKitVersion
= parseInt(match
[1]);
442 if (webKitVersion
< 420) {
443 // Released Safari w/ WebKit 418.9.1 messes up horribly
444 // Nightlies of 420+ are ok
449 // Mozilla needs to wait until after load, otherwise the window doesn't scroll
450 addOnloadHook(function () {
451 if (window
.location
.hash
== "")
452 window
.location
.hash
= fragment
;
455 if (window
.location
.hash
== "")
456 window
.location
.hash
= fragment
;
461 * Table sorting script by Joost de Valk, check it out at http://www.joostdevalk.nl/code/sortable-table/.
462 * Based on a script from http://www.kryogenix.org/code/browser/sorttable/.
463 * Distributed under the MIT license: http://www.kryogenix.org/code/browser/licence.html .
465 * Copyright (c) 1997-2006 Stuart Langridge, Joost de Valk.
467 * @todo don't break on colspans/rowspans (bug 8028)
468 * @todo language-specific digit grouping/decimals (bug 8063)
469 * @todo support all accepted date formats (bug 8226)
472 var ts_image_path
= stylepath
+"/common/images/";
473 var ts_image_up
= "sort_up.gif";
474 var ts_image_down
= "sort_down.gif";
475 var ts_image_none
= "sort_none.gif";
476 var ts_europeandate
= wgContentLanguage
!= "en"; // The non-American-inclined can change to "true"
477 var ts_alternate_row_colors
= true;
478 var SORT_COLUMN_INDEX
;
480 function sortables_init() {
482 // Find all tables with class sortable and make them sortable
483 var tables
= getElementsByClassName(document
, "table", "sortable");
484 for (var ti
= 0; ti
< tables
.length
; ti
++) {
485 if (!tables
[ti
].id
) {
486 tables
[ti
].setAttribute('id','sortable_table_id_'+idnum
);
489 ts_makeSortable(tables
[ti
]);
493 function ts_makeSortable(table
) {
495 if (table
.rows
&& table
.rows
.length
> 0) {
496 if (table
.tHead
&& table
.tHead
.rows
.length
> 0) {
497 firstRow
= table
.tHead
.rows
[table
.tHead
.rows
.length
-1];
499 firstRow
= table
.rows
[0];
502 if (!firstRow
) return;
504 // We have a first row: assume it's the header, and make its contents clickable links
505 for (var i
= 0; i
< firstRow
.cells
.length
; i
++) {
506 var cell
= firstRow
.cells
[i
];
507 if ((" "+cell
.className
+" ").indexOf(" unsortable ") == -1) {
508 cell
.innerHTML
+= ' <a href="#" class="sortheader" onclick="ts_resortTable(this);return false;"><span class="sortarrow"><img src="'+ ts_image_path
+ ts_image_none
+ '" alt="↓"/></span></a>';
511 if (ts_alternate_row_colors
) {
516 function ts_getInnerText(el
) {
517 if (typeof el
== "string") return el
;
518 if (typeof el
== "undefined") { return el
};
519 if (el
.textContent
) return el
.textContent
; // not needed but it is faster
520 if (el
.innerText
) return el
.innerText
; // IE doesn't have textContent
523 var cs
= el
.childNodes
;
525 for (var i
= 0; i
< l
; i
++) {
526 switch (cs
[i
].nodeType
) {
527 case 1: //ELEMENT_NODE
528 str
+= ts_getInnerText(cs
[i
]);
531 str
+= cs
[i
].nodeValue
;
538 function ts_resortTable(lnk
) {
540 var span
= lnk
.getElementsByTagName('span')[0];
542 var td
= lnk
.parentNode
;
543 var tr
= td
.parentNode
;
544 var column
= td
.cellIndex
;
546 var table
= tr
.parentNode
;
547 while (table
&& !(table
.tagName
&& table
.tagName
.toLowerCase() == 'table'))
548 table
= table
.parentNode
;
551 // Work out a type for the column
552 if (table
.rows
.length
<= 1) return;
554 // Skip the first row if that's where the headings are
555 var rowStart
= (table
.tHead
&& table
.tHead
.rows
.length
> 0 ? 0 : 1);
558 for (var i
= rowStart
; i
< table
.rows
.length
; i
++) {
559 if (table
.rows
[i
].cells
.length
> column
) {
560 itm
= ts_getInnerText(table
.rows
[i
].cells
[column
]);
561 itm
= itm
.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "");
562 if (itm
!= "") break;
566 sortfn
= ts_sort_caseinsensitive
;
567 if (itm
.match(/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/))
568 sortfn
= ts_sort_date
;
569 if (itm
.match(/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/))
570 sortfn
= ts_sort_date
;
571 if (itm
.match(/^\d\d[\/.-]\d\d[\/.-]\d\d$/))
572 sortfn
= ts_sort_date
;
573 if (itm
.match(/^[\u00a3$\u20ac]/)) // pound dollar euro
574 sortfn
= ts_sort_currency
;
575 if (itm
.match(/^[\d.,]+\%?$/))
576 sortfn
= ts_sort_numeric
;
578 var reverse
= (span
.getAttribute("sortdir") == 'down');
580 var newRows
= new Array();
581 for (var j
= rowStart
; j
< table
.rows
.length
; j
++) {
582 var row
= table
.rows
[j
];
583 var keyText
= ts_getInnerText(row
.cells
[column
]);
584 var oldIndex
= (reverse
? -j
: j
);
586 newRows
[newRows
.length
] = new Array(row
, keyText
, oldIndex
);
589 newRows
.sort(sortfn
);
593 arrowHTML
= '<img src="'+ ts_image_path
+ ts_image_down
+ '" alt="↓"/>';
595 span
.setAttribute('sortdir','up');
597 arrowHTML
= '<img src="'+ ts_image_path
+ ts_image_up
+ '" alt="↑"/>';
598 span
.setAttribute('sortdir','down');
601 // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
602 // don't do sortbottom rows
603 for (var i
= 0; i
< newRows
.length
; i
++) {
604 if ((" "+newRows
[i
][0].className
+" ").indexOf(" sortbottom ") == -1)
605 table
.tBodies
[0].appendChild(newRows
[i
][0]);
607 // do sortbottom rows only
608 for (var i
= 0; i
< newRows
.length
; i
++) {
609 if ((" "+newRows
[i
][0].className
+" ").indexOf(" sortbottom ") != -1)
610 table
.tBodies
[0].appendChild(newRows
[i
][0]);
613 // Delete any other arrows there may be showing
614 var spans
= getElementsByClassName(tr
, "span", "sortarrow");
615 for (var i
= 0; i
< spans
.length
; i
++) {
616 spans
[i
].innerHTML
= '<img src="'+ ts_image_path
+ ts_image_none
+ '" alt="↓"/>';
618 span
.innerHTML
= arrowHTML
;
623 function ts_dateToSortKey(date
) {
624 // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
625 if (date
.length
== 11) {
626 switch (date
.substr(3,3).toLowerCase()) {
627 case "jan": var month
= "01"; break;
628 case "feb": var month
= "02"; break;
629 case "mar": var month
= "03"; break;
630 case "apr": var month
= "04"; break;
631 case "may": var month
= "05"; break;
632 case "jun": var month
= "06"; break;
633 case "jul": var month
= "07"; break;
634 case "aug": var month
= "08"; break;
635 case "sep": var month
= "09"; break;
636 case "oct": var month
= "10"; break;
637 case "nov": var month
= "11"; break;
638 case "dec": var month
= "12"; break;
639 // default: var month = "00";
641 return date
.substr(7,4)+month
+date
.substr(0,2);
642 } else if (date
.length
== 10) {
643 if (ts_europeandate
== false) {
644 return date
.substr(6,4)+date
.substr(0,2)+date
.substr(3,2);
646 return date
.substr(6,4)+date
.substr(3,2)+date
.substr(0,2);
648 } else if (date
.length
== 8) {
649 yr
= date
.substr(6,2);
650 if (parseInt(yr
) < 50) {
655 if (ts_europeandate
== true) {
656 return yr
+date
.substr(3,2)+date
.substr(0,2);
658 return yr
+date
.substr(0,2)+date
.substr(3,2);
664 function ts_parseFloat(num
) {
666 num
= parseFloat(num
.replace(/,/g
, ""));
667 return (isNaN(num
) ? 0 : num
);
670 function ts_sort_date(a
,b
) {
671 var aa
= ts_dateToSortKey(a
[1]);
672 var bb
= ts_dateToSortKey(b
[1]);
673 return (aa
< bb
? -1 : aa
> bb
? 1 : a
[2] - b
[2]);
676 function ts_sort_currency(a
,b
) {
677 var aa
= ts_parseFloat(a
[1].replace(/[^0-9.]/g,''));
678 var bb
= ts_parseFloat(b
[1].replace(/[^0-9.]/g,''));
679 return (aa
!= bb
? aa
- bb
: a
[2] - b
[2]);
682 function ts_sort_numeric(a
,b
) {
683 var aa
= ts_parseFloat(a
[1]);
684 var bb
= ts_parseFloat(b
[1]);
685 return (aa
!= bb
? aa
- bb
: a
[2] - b
[2]);
688 function ts_sort_caseinsensitive(a
,b
) {
689 var aa
= a
[1].toLowerCase();
690 var bb
= b
[1].toLowerCase();
691 return (aa
< bb
? -1 : aa
> bb
? 1 : a
[2] - b
[2]);
694 function ts_sort_default(a
,b
) {
695 return (a
[1] < b
[1] ? -1 : a
[1] > b
[1] ? 1 : a
[2] - b
[2]);
698 function ts_alternate(table
) {
699 // Take object table and get all it's tbodies.
700 var tableBodies
= table
.getElementsByTagName("tbody");
701 // Loop through these tbodies
702 for (var i
= 0; i
< tableBodies
.length
; i
++) {
703 // Take the tbody, and get all it's rows
704 var tableRows
= tableBodies
[i
].getElementsByTagName("tr");
705 // Loop through these rows
706 // Start at 1 because we want to leave the heading row untouched
707 for (var j
= 0; j
< tableRows
.length
; j
++) {
708 // Check if j is even, and apply classes for both possible results
709 var oldClasses
= tableRows
[j
].className
.split(" ");
710 var newClassName
= "";
711 for (var k
= 0; k
< oldClasses
.length
; k
++) {
712 if (oldClasses
[k
] != "" && oldClasses
[k
] != "even" && oldClasses
[k
] != "odd")
713 newClassName
+= oldClasses
[k
] + " ";
715 tableRows
[j
].className
= newClassName
+ (j
% 2 == 0 ? "even" : "odd");
721 * End of table sorting code
726 * Add a cute little box at the top of the screen to inform the user of
727 * something, replacing any preexisting message.
729 * @param String message HTML to be put inside the right div
730 * @param String className Used in adding a class; should be different for each
731 * call to allow CSS/JS to hide different boxes. null = no class used.
732 * @return Boolean True on success, false on failure
734 function jsMsg( message
, className
) {
735 if ( !document
.getElementById
) {
738 // We special-case skin structures provided by the software. Skins that
739 // choose to abandon or significantly modify our formatting can just define
740 // an mw-js-message div to start with.
741 var messageDiv
= document
.getElementById( 'mw-js-message' );
743 messageDiv
= document
.createElement( 'div' );
744 if ( document
.getElementById( 'column-content' )
745 && document
.getElementById( 'content' ) ) {
746 // MonoBook, presumably
747 document
.getElementById( 'content' ).insertBefore(
749 document
.getElementById( 'content' ).firstChild
751 } else if ( document
.getElementById('content')
752 && document
.getElementById( 'article' ) ) {
753 // Non-Monobook but still recognizable (old-style)
754 document
.getElementById( 'article').insertBefore(
756 document
.getElementById( 'article' ).firstChild
763 messageDiv
.setAttribute( 'id', 'mw-js-message' );
765 messageDiv
.setAttribute( 'class', 'mw-js-message-'+className
);
767 messageDiv
.innerHTML
= message
;
772 * Inject a cute little progress spinner after the specified element
774 * @param element Element to inject after
775 * @param id Identifier string (for use with removeSpinner(), below)
777 function injectSpinner( element
, id
) {
778 var spinner
= document
.createElement( "img" );
779 spinner
.id
= "mw-spinner-" + id
;
780 spinner
.src
= stylepath
+ "/common/images/spinner.gif";
781 spinner
.alt
= spinner
.title
= "...";
782 if( element
.nextSibling
) {
783 element
.parentNode
.insertBefore( spinner
, element
.nextSibling
);
785 element
.parentNode
.appendChild( spinner
);
790 * Remove a progress spinner added with injectSpinner()
792 * @param id Identifier string
794 function removeSpinner( id
) {
795 var spinner
= document
.getElementById( "mw-spinner-" + id
);
797 spinner
.parentNode
.removeChild( spinner
);
801 function runOnloadHook() {
802 // don't run anything below this for non-dom browsers
803 if (doneOnloadHook
|| !(document
.getElementById
&& document
.getElementsByTagName
)) {
807 // set this before running any hooks, since any errors below
808 // might cause the function to terminate prematurely
809 doneOnloadHook
= true;
811 updateTooltipAccessKeys( null );
813 setupCheckboxShiftClick();
816 // Run any added-on functions
817 for (var i
= 0; i
< onloadFuncts
.length
; i
++) {
823 * Add an event handler to an element
825 * @param Element element Element to add handler to
826 * @param String attach Event to attach to
827 * @param callable handler Event handler callback
829 function addHandler( element
, attach
, handler
) {
830 if( window
.addEventListener
) {
831 element
.addEventListener( attach
, handler
, false );
832 } else if( window
.attachEvent
) {
833 element
.attachEvent( 'on' + attach
, handler
);
838 * Add a click event handler to an element
840 * @param Element element Element to add handler to
841 * @param callable handler Event handler callback
843 function addClickHandler( element
, handler
) {
844 addHandler( element
, 'click', handler
);
846 //note: all skins should call runOnloadHook() at the end of html output,
847 // so the below should be redundant. It's there just in case.
848 hookEvent("load", runOnloadHook
);