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 webkit_match
= clientPC
.match(/applewebkit\/(\d+)/);
8 var is_safari
= clientPC
.indexOf('applewebkit') != -1 &&
9 clientPC
.indexOf('spoofer') == -1;
10 var is_safari_win
= is_safari
&& clientPC
.indexOf('windows') != -1;
11 var webkit_version
= parseInt(webkit_match
[1]);
13 // For accesskeys; note that FF3+ is included here!
14 var is_ff2
= /firefox\/[2-9]|minefield\/3/.test( clientPC
);
15 var ff2_bugs
= /firefox\/2/.test( clientPC
);
16 // These aren't used here, but some custom scripts rely on them
17 var is_ff2_win
= is_ff2
&& clientPC
.indexOf('windows') != -1;
18 var is_ff2_x11
= is_ff2
&& clientPC
.indexOf('x11') != -1;
19 if (clientPC
.indexOf('opera') != -1) {
21 var is_opera_preseven
= window
.opera
&& !document
.childNodes
;
22 var is_opera_seven
= window
.opera
&& document
.childNodes
;
23 var is_opera_95
= /opera\/(9\.[5-9]|[1-9][0-9])/.test( clientPC
);
24 var opera6_bugs
= is_opera_preseven
;
25 var opera7_bugs
= is_opera_seven
&& !is_opera_95
;
26 var opera95_bugs
= /opera\/(9\.5)/.test( clientPC
);
28 // Start at 4 to minimize the chance of breaking on IE10 :)
29 var ie6_bugs
= /msie [4-6]/.test( clientPC
);
31 // Global external objects used by this script.
32 /*extern ta, stylepath, skin */
34 // add any onload functions in this hook (please don't hard-code any events in the xhtml source)
37 if (!window
.onloadFuncts
) {
38 var onloadFuncts
= [];
41 function addOnloadHook(hookFunct
) {
42 // Allows add-on scripts to add onload functions
44 onloadFuncts
[onloadFuncts
.length
] = hookFunct
;
46 hookFunct(); // bug in MSIE script loading
51 function hookEvent(hookName
, hookFunct
) {
52 addHandler(window
, hookName
, hookFunct
);
55 function importScript(page
) {
56 // TODO: might want to introduce a utility function to match wfUrlencode() in PHP
57 var uri
= wgScript
+ '?title=' +
58 encodeURIComponent(page
.replace(/ /g,'_')).replace(/%2F
/ig,'/').replace(/%3A/ig,':') +
59 '&action
=raw
&ctype
=text
/javascript
';
60 return importScriptURI(uri);
63 var loadedScripts = {}; // included-scripts tracker
64 function importScriptURI(url) {
65 if (loadedScripts[url]) {
68 loadedScripts[url] = true;
69 var s = document.createElement('script
');
70 s.setAttribute('src
', url);
71 s.setAttribute('type
', 'text
/javascript
');
72 document.getElementsByTagName('head
')[0].appendChild(s);
76 function importStylesheet(page) {
77 return importStylesheetURI(wgScript + '?action
=raw
&ctype
=text
/css&title=' + encodeURIComponent(page.replace(/ /g
,'_')));
80 function importStylesheetURI(url
, media
) {
81 var l
= document
.createElement('link');
88 document
.getElementsByTagName('head')[0].appendChild(l
);
92 function appendCSS(text
) {
93 var s
= document
.createElement('style');
97 s
.styleSheet
.cssText
= text
; //IE
99 s
.appendChild(document
.createTextNode(text
+ '')); //Safari sometimes borks on null
101 document
.getElementsByTagName('head')[0].appendChild(s
);
105 // special stylesheet links
106 if (typeof stylepath
!= 'undefined' && typeof skin
!= 'undefined') {
107 // FIXME: This tries to load the stylesheets even for skins where they
108 // don't exist, i.e., everything but Monobook.
110 importStylesheetURI(stylepath
+'/'+skin
+'/Opera6Fixes.css');
111 } else if (opera7_bugs
) {
112 importStylesheetURI(stylepath
+'/'+skin
+'/Opera7Fixes.css');
113 } else if (opera95_bugs
) {
114 importStylesheetURI(stylepath
+'/'+skin
+'/Opera9Fixes.css');
115 } else if (ff2_bugs
) {
116 importStylesheetURI(stylepath
+'/'+skin
+'/FF2Fixes.css');
122 // Un-trap us from framesets
123 if (window
.top
!= window
) {
124 window
.top
.location
= window
.location
;
128 function showTocToggle() {
129 if (document
.createTextNode
) {
130 // Uses DOM calls to avoid document.write + XHTML issues
132 var linkHolder
= document
.getElementById('toctitle');
133 var existingLink
= document
.getElementById('togglelink');
134 if (!linkHolder
|| existingLink
) {
135 // Don't add the toggle link twice
139 var outerSpan
= document
.createElement('span');
140 outerSpan
.className
= 'toctoggle';
142 var toggleLink
= document
.createElement('a');
143 toggleLink
.id
= 'togglelink';
144 toggleLink
.className
= 'internal';
145 toggleLink
.href
= 'javascript:toggleToc()';
146 toggleLink
.appendChild(document
.createTextNode(tocHideText
));
148 outerSpan
.appendChild(document
.createTextNode('['));
149 outerSpan
.appendChild(toggleLink
);
150 outerSpan
.appendChild(document
.createTextNode(']'));
152 linkHolder
.appendChild(document
.createTextNode(' '));
153 linkHolder
.appendChild(outerSpan
);
155 var cookiePos
= document
.cookie
.indexOf("hidetoc=");
156 if (cookiePos
> -1 && document
.cookie
.charAt(cookiePos
+ 8) == 1) {
162 function changeText(el
, newText
) {
163 // Safari work around
165 el
.innerText
= newText
;
166 } else if (el
.firstChild
&& el
.firstChild
.nodeValue
) {
167 el
.firstChild
.nodeValue
= newText
;
171 function toggleToc() {
172 var tocmain
= document
.getElementById('toc');
173 var toc
= document
.getElementById('toc').getElementsByTagName('ul')[0];
174 var toggleLink
= document
.getElementById('togglelink');
176 if (toc
&& toggleLink
&& toc
.style
.display
== 'none') {
177 changeText(toggleLink
, tocHideText
);
178 toc
.style
.display
= 'block';
179 document
.cookie
= "hidetoc=0";
180 tocmain
.className
= 'toc';
182 changeText(toggleLink
, tocShowText
);
183 toc
.style
.display
= 'none';
184 document
.cookie
= "hidetoc=1";
185 tocmain
.className
= 'toc tochidden';
189 var mwEditButtons
= [];
190 var mwCustomEditButtons
= []; // eg to add in MediaWiki:Common.js
192 function escapeQuotes(text
) {
193 var re
= new RegExp("'","g");
194 text
= text
.replace(re
,"\\'");
195 re
= new RegExp("\\n","g");
196 text
= text
.replace(re
,"\\n");
197 return escapeQuotesHTML(text
);
200 function escapeQuotesHTML(text
) {
201 var re
= new RegExp('&',"g");
202 text
= text
.replace(re
,"&");
203 re
= new RegExp('"',"g");
204 text
= text
.replace(re
,""");
205 re
= new RegExp('<',"g");
206 text
= text
.replace(re
,"<");
207 re
= new RegExp('>',"g");
208 text
= text
.replace(re
,">");
214 * Set the accesskey prefix based on browser detection.
216 var tooltipAccessKeyPrefix
= 'alt-';
218 tooltipAccessKeyPrefix
= 'shift-esc-';
219 } else if (!is_safari_win
&& is_safari
&& webkit_version
> 526) {
220 tooltipAccessKeyPrefix
= 'ctrl-alt-';
221 } else if (!is_safari_win
&& (is_safari
222 || clientPC
.indexOf('mac') != -1
223 || clientPC
.indexOf('konqueror') != -1 )) {
224 tooltipAccessKeyPrefix
= 'ctrl-';
226 tooltipAccessKeyPrefix
= 'alt-shift-';
228 var tooltipAccessKeyRegexp
= /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/;
231 * Add the appropriate prefix to the accesskey shown in the tooltip.
232 * If the nodeList parameter is given, only those nodes are updated;
233 * otherwise, all the nodes that will probably have accesskeys by
234 * default are updated.
236 * @param Array nodeList -- list of elements to update
238 function updateTooltipAccessKeys( nodeList
) {
240 // Rather than scan all links on the whole page, we can just scan these
241 // containers which contain the relevant links. This is really just an
242 // optimization technique.
243 var linkContainers
= [
244 "column-one", // Monobook and Modern
245 "head", "panel", "p-logo" // Vector
247 for ( var i
in linkContainers
) {
248 var linkContainer
= document
.getElementById( linkContainers
[i
] );
249 if ( linkContainer
) {
250 updateTooltipAccessKeys( linkContainer
.getElementsByTagName("a") );
253 // these are rare enough that no such optimization is needed
254 updateTooltipAccessKeys( document
.getElementsByTagName("input") );
255 updateTooltipAccessKeys( document
.getElementsByTagName("label") );
259 for ( var i
= 0; i
< nodeList
.length
; i
++ ) {
260 var element
= nodeList
[i
];
261 var tip
= element
.getAttribute("title");
262 if ( tip
&& tooltipAccessKeyRegexp
.exec(tip
) ) {
263 tip
= tip
.replace(tooltipAccessKeyRegexp
,
264 "["+tooltipAccessKeyPrefix
+"$5]");
265 element
.setAttribute("title", tip
);
271 * Add a link to one of the portlet menus on the page, including:
273 * p-cactions: Content actions (shown as tabs above the main content in Monobook)
274 * p-personal: Personal tools (shown at the top right of the page in Monobook)
275 * p-navigation: Navigation
278 * This function exists for the convenience of custom JS authors. All
279 * but the first three parameters are optional, though providing at
280 * least an id and a tooltip is recommended.
282 * By default the new link will be added to the end of the list. To
283 * add the link before a given existing item, pass the DOM node of
284 * that item (easily obtained with document.getElementById()) as the
285 * nextnode parameter; to add the link _after_ an existing item, pass
286 * the node's nextSibling instead.
288 * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb")
289 * @param String href -- link URL
290 * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook)
291 * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-")
292 * @param String tooltip -- text to show when hovering over the link, without accesskey suffix
293 * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts)
294 * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list
296 * @return Node -- the DOM node of the new item (an LI element) or null
298 function addPortletLink(portlet
, href
, text
, id
, tooltip
, accesskey
, nextnode
) {
299 var root
= document
.getElementById(portlet
);
303 var node
= root
.getElementsByTagName( 'ul' )[0];
308 // unhide portlet if it was hidden before
309 root
.className
= root
.className
.replace( /(^| )emptyPortlet( |$)/, "$2" );
311 var span
= document
.createElement( 'span' );
312 span
.appendChild( document
.createTextNode( text
) );
314 var link
= document
.createElement( 'a' );
315 link
.appendChild( span
);
318 var item
= document
.createElement( 'li' );
319 item
.appendChild( link
);
325 link
.setAttribute( 'accesskey', accesskey
);
326 tooltip
+= ' [' + accesskey
+ ']';
329 link
.setAttribute( 'title', tooltip
);
331 if ( accesskey
&& tooltip
) {
332 updateTooltipAccessKeys( new Array( link
) );
335 if ( nextnode
&& nextnode
.parentNode
== node
) {
336 node
.insertBefore( item
, nextnode
);
338 node
.appendChild( item
); // IE compatibility (?)
344 function getInnerText(el
) {
345 if ( typeof el
== 'string' ) {
348 if ( typeof el
== 'undefined' ) {
351 if ( el
.textContent
) {
352 return el
.textContent
; // not needed but it is faster
354 if ( el
.innerText
) {
355 return el
.innerText
; // IE doesn't have textContent
359 var cs
= el
.childNodes
;
361 for (var i
= 0; i
< l
; i
++) {
362 switch (cs
[i
].nodeType
) {
363 case 1: // ELEMENT_NODE
364 str
+= ts_getInnerText(cs
[i
]);
367 str
+= cs
[i
].nodeValue
;
374 /* Dummy for deprecated function */
375 function akeytt( doId
) {
381 function setupCheckboxShiftClick() {
384 var inputs
= document
.getElementsByTagName('input');
385 addCheckboxClickHandlers(inputs
);
388 function addCheckboxClickHandlers(inputs
, start
) {
393 var finish
= start
+ 250;
394 if ( finish
> inputs
.length
) {
395 finish
= inputs
.length
;
398 for ( var i
= start
; i
< finish
; i
++ ) {
400 if ( !cb
.type
|| cb
.type
.toLowerCase() != 'checkbox' ) {
403 var end
= checkboxes
.length
;
404 checkboxes
[end
] = cb
;
406 cb
.onclick
= checkboxClickHandler
;
409 if ( finish
< inputs
.length
) {
410 setTimeout( function () {
411 addCheckboxClickHandlers(inputs
, finish
);
416 function checkboxClickHandler(e
) {
417 if (typeof e
== 'undefined') {
420 if ( !e
.shiftKey
|| lastCheckbox
=== null ) {
421 lastCheckbox
= this.index
;
424 var endState
= this.checked
;
426 if ( this.index
< lastCheckbox
) {
427 start
= this.index
+ 1;
428 finish
= lastCheckbox
;
430 start
= lastCheckbox
;
431 finish
= this.index
- 1;
433 for (var i
= start
; i
<= finish
; ++i
) {
434 checkboxes
[i
].checked
= endState
;
435 if( i
> start
&& typeof checkboxes
[i
].onchange
== 'function' ) {
436 checkboxes
[i
].onchange(); // fire triggers
439 lastCheckbox
= this.index
;
445 Written by Jonathan Snook, http://www.snook.ca/jonathan
446 Add-ons by Robert Nyman, http://www.robertnyman.com
447 Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"
448 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
450 function getElementsByClassName(oElm
, strTagName
, oClassNames
){
451 var arrReturnElements
= new Array();
452 if ( typeof( oElm
.getElementsByClassName
) == "function" ) {
453 /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
454 var arrNativeReturn
= oElm
.getElementsByClassName( oClassNames
);
455 if ( strTagName
== "*" ) {
456 return arrNativeReturn
;
458 for ( var h
=0; h
< arrNativeReturn
.length
; h
++ ) {
459 if( arrNativeReturn
[h
].tagName
.toLowerCase() == strTagName
.toLowerCase() ) {
460 arrReturnElements
[arrReturnElements
.length
] = arrNativeReturn
[h
];
463 return arrReturnElements
;
465 var arrElements
= (strTagName
== "*" && oElm
.all
)? oElm
.all
: oElm
.getElementsByTagName(strTagName
);
466 var arrRegExpClassNames
= new Array();
467 if(typeof oClassNames
== "object"){
468 for(var i
=0; i
<oClassNames
.length
; i
++){
469 arrRegExpClassNames
[arrRegExpClassNames
.length
] =
470 new RegExp("(^|\\s)" + oClassNames
[i
].replace(/\-/g, "\\-") + "(\\s|$)");
473 arrRegExpClassNames
[arrRegExpClassNames
.length
] =
474 new RegExp("(^|\\s)" + oClassNames
.replace(/\-/g, "\\-") + "(\\s|$)");
478 for(var j
=0; j
<arrElements
.length
; j
++){
479 oElement
= arrElements
[j
];
481 for(var k
=0; k
<arrRegExpClassNames
.length
; k
++){
482 if(!arrRegExpClassNames
[k
].test(oElement
.className
)){
488 arrReturnElements
[arrReturnElements
.length
] = oElement
;
491 return (arrReturnElements
);
494 function redirectToFragment(fragment
) {
495 var match
= navigator
.userAgent
.match(/AppleWebKit\/(\d+)/);
497 var webKitVersion
= parseInt(match
[1]);
498 if (webKitVersion
< 420) {
499 // Released Safari w/ WebKit 418.9.1 messes up horribly
500 // Nightlies of 420+ are ok
505 // Mozilla needs to wait until after load, otherwise the window doesn't scroll
506 addOnloadHook(function () {
507 if (window
.location
.hash
== '') {
508 window
.location
.hash
= fragment
;
512 if (window
.location
.hash
== '') {
513 window
.location
.hash
= fragment
;
519 * Table sorting script based on one (c) 1997-2006 Stuart Langridge and Joost
521 * http://www.joostdevalk.nl/code/sortable-table/
522 * http://www.kryogenix.org/code/browser/sorttable/
524 * @todo don't break on colspans/rowspans (bug 8028)
525 * @todo language-specific digit grouping/decimals (bug 8063)
526 * @todo support all accepted date formats (bug 8226)
529 var ts_image_path
= stylepath
+ '/common/images/';
530 var ts_image_up
= 'sort_up.gif';
531 var ts_image_down
= 'sort_down.gif';
532 var ts_image_none
= 'sort_none.gif';
533 var ts_europeandate
= wgContentLanguage
!= 'en'; // The non-American-inclined can change to "true"
534 var ts_alternate_row_colors
= false;
535 var ts_number_transform_table
= null;
536 var ts_number_regex
= null;
538 function sortables_init() {
540 // Find all tables with class sortable and make them sortable
541 var tables
= getElementsByClassName(document
, "table", "sortable");
542 for (var ti
= 0; ti
< tables
.length
; ti
++) {
543 if (!tables
[ti
].id
) {
544 tables
[ti
].setAttribute('id','sortable_table_id_'+idnum
);
547 ts_makeSortable(tables
[ti
]);
551 function ts_makeSortable(table
) {
553 if (table
.rows
&& table
.rows
.length
> 0) {
554 if (table
.tHead
&& table
.tHead
.rows
.length
> 0) {
555 firstRow
= table
.tHead
.rows
[table
.tHead
.rows
.length
-1];
557 firstRow
= table
.rows
[0];
564 // We have a first row: assume it's the header, and make its contents clickable links
565 for (var i
= 0; i
< firstRow
.cells
.length
; i
++) {
566 var cell
= firstRow
.cells
[i
];
567 if ((" "+cell
.className
+" ").indexOf(" unsortable ") == -1) {
568 cell
.innerHTML
+= '<a href="#" class="sortheader" '
569 + 'onclick="ts_resortTable(this);return false;">'
570 + '<span class="sortarrow">'
574 + '" alt="↓"/></span></a>';
577 if (ts_alternate_row_colors
) {
582 function ts_getInnerText(el
) {
583 return getInnerText( el
);
586 function ts_resortTable(lnk
) {
588 var span
= lnk
.getElementsByTagName('span')[0];
590 var td
= lnk
.parentNode
;
591 var tr
= td
.parentNode
;
592 var column
= td
.cellIndex
;
594 var table
= tr
.parentNode
;
595 while (table
&& !(table
.tagName
&& table
.tagName
.toLowerCase() == 'table')) {
596 table
= table
.parentNode
;
602 if ( table
.rows
.length
<= 1 ) {
606 // Generate the number transform table if it's not done already
607 if (ts_number_transform_table
=== null) {
608 ts_initTransformTable();
611 // Work out a type for the column
612 // Skip the first row if that's where the headings are
613 var rowStart
= (table
.tHead
&& table
.tHead
.rows
.length
> 0 ? 0 : 1);
616 for (var i
= rowStart
; i
< table
.rows
.length
; i
++) {
617 if (table
.rows
[i
].cells
.length
> column
) {
618 itm
= ts_getInnerText(table
.rows
[i
].cells
[column
]);
619 itm
= itm
.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "");
626 // TODO: bug 8226, localised date formats
627 var sortfn
= ts_sort_generic
;
628 var preprocessor
= ts_toLowerCase
;
629 if (/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/.test(itm
)) {
630 preprocessor
= ts_dateToSortKey
;
631 } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/.test(itm
)) {
632 preprocessor
= ts_dateToSortKey
;
633 } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d$/.test(itm
)) {
634 preprocessor
= ts_dateToSortKey
;
635 // (minus sign)([pound dollar euro yen currency]|cents)
636 } else if (/(^([-\u2212] *)?[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test(itm
)) {
637 preprocessor
= ts_currencyToSortKey
;
638 } else if (ts_number_regex
.test(itm
)) {
639 preprocessor
= ts_parseFloat
;
642 var reverse
= (span
.getAttribute("sortdir") == 'down');
644 var newRows
= new Array();
645 var staticRows
= new Array();
646 for (var j
= rowStart
; j
< table
.rows
.length
; j
++) {
647 var row
= table
.rows
[j
];
648 if((" "+row
.className
+" ").indexOf(" unsortable ") < 0) {
649 var keyText
= ts_getInnerText(row
.cells
[column
]);
650 if(keyText
=== undefined) {
653 var oldIndex
= (reverse
? -j
: j
);
654 var preprocessed
= preprocessor( keyText
.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "") );
656 newRows
[newRows
.length
] = new Array(row
, preprocessed
, oldIndex
);
658 staticRows
[staticRows
.length
] = new Array(row
, false, j
-rowStart
);
662 newRows
.sort(sortfn
);
666 arrowHTML
= '<img src="'+ ts_image_path
+ ts_image_down
+ '" alt="↓"/>';
668 span
.setAttribute('sortdir','up');
670 arrowHTML
= '<img src="'+ ts_image_path
+ ts_image_up
+ '" alt="↑"/>';
671 span
.setAttribute('sortdir','down');
674 for (var i
= 0; i
< staticRows
.length
; i
++) {
675 var row
= staticRows
[i
];
676 newRows
.splice(row
[2], 0, row
);
679 // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
680 // don't do sortbottom rows
681 for (var i
= 0; i
< newRows
.length
; i
++) {
682 if ((" "+newRows
[i
][0].className
+" ").indexOf(" sortbottom ") == -1)
683 table
.tBodies
[0].appendChild(newRows
[i
][0]);
685 // do sortbottom rows only
686 for (var i
= 0; i
< newRows
.length
; i
++) {
687 if ((" "+newRows
[i
][0].className
+" ").indexOf(" sortbottom ") != -1)
688 table
.tBodies
[0].appendChild(newRows
[i
][0]);
691 // Delete any other arrows there may be showing
692 var spans
= getElementsByClassName(tr
, "span", "sortarrow");
693 for (var i
= 0; i
< spans
.length
; i
++) {
694 spans
[i
].innerHTML
= '<img src="'+ ts_image_path
+ ts_image_none
+ '" alt="↓"/>';
696 span
.innerHTML
= arrowHTML
;
698 if (ts_alternate_row_colors
) {
703 function ts_initTransformTable() {
704 if ( typeof wgSeparatorTransformTable
== "undefined"
705 || ( wgSeparatorTransformTable
[0] == '' && wgDigitTransformTable
[2] == '' ) )
707 digitClass
= "[0-9,.]";
708 ts_number_transform_table
= false;
710 ts_number_transform_table
= {};
711 // Unpack the transform table
713 ascii
= wgSeparatorTransformTable
[0].split("\t");
714 localised
= wgSeparatorTransformTable
[1].split("\t");
715 for ( var i
= 0; i
< ascii
.length
; i
++ ) {
716 ts_number_transform_table
[localised
[i
]] = ascii
[i
];
719 ascii
= wgDigitTransformTable
[0].split("\t");
720 localised
= wgDigitTransformTable
[1].split("\t");
721 for ( var i
= 0; i
< ascii
.length
; i
++ ) {
722 ts_number_transform_table
[localised
[i
]] = ascii
[i
];
725 // Construct regex for number identification
726 digits
= ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ',', '\\.'];
728 for ( var digit
in ts_number_transform_table
) {
729 // Escape regex metacharacters
731 digit
.replace( /[\\\\$\*\+\?\.\(\)\|\{\}\[\]\-]/,
732 function( s
) { return '\\' + s
; } )
734 if (digit
.length
> maxDigitLength
) {
735 maxDigitLength
= digit
.length
;
738 if ( maxDigitLength
> 1 ) {
739 digitClass
= '[' + digits
.join( '', digits
) + ']';
741 digitClass
= '(' + digits
.join( '|', digits
) + ')';
745 // We allow a trailing percent sign, which we just strip. This works fine
746 // if percents and regular numbers aren't being mixed.
747 ts_number_regex
= new RegExp(
749 "[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
751 "[-+\u2212]?" + digitClass
+ "+%?" + // Generic localised
756 function ts_toLowerCase( s
) {
757 return s
.toLowerCase();
760 function ts_dateToSortKey(date
) {
761 // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
762 if (date
.length
== 11) {
763 switch (date
.substr(3,3).toLowerCase()) {
764 case "jan": var month
= "01"; break;
765 case "feb": var month
= "02"; break;
766 case "mar": var month
= "03"; break;
767 case "apr": var month
= "04"; break;
768 case "may": var month
= "05"; break;
769 case "jun": var month
= "06"; break;
770 case "jul": var month
= "07"; break;
771 case "aug": var month
= "08"; break;
772 case "sep": var month
= "09"; break;
773 case "oct": var month
= "10"; break;
774 case "nov": var month
= "11"; break;
775 case "dec": var month
= "12"; break;
776 // default: var month = "00";
778 return date
.substr(7,4)+month
+date
.substr(0,2);
779 } else if (date
.length
== 10) {
780 if (ts_europeandate
== false) {
781 return date
.substr(6,4)+date
.substr(0,2)+date
.substr(3,2);
783 return date
.substr(6,4)+date
.substr(3,2)+date
.substr(0,2);
785 } else if (date
.length
== 8) {
786 yr
= date
.substr(6,2);
787 if (parseInt(yr
) < 50) {
792 if (ts_europeandate
== true) {
793 return yr
+date
.substr(3,2)+date
.substr(0,2);
795 return yr
+date
.substr(0,2)+date
.substr(3,2);
801 function ts_parseFloat( s
) {
805 if (ts_number_transform_table
!= false) {
808 for ( var p
= 0; p
< s
.length
; p
++ ) {
810 if (c
in ts_number_transform_table
) {
811 newNum
+= ts_number_transform_table
[c
];
818 num
= parseFloat(s
.replace(/[, ]/g, "").replace("\u2212", "-"));
819 return (isNaN(num
) ? -Infinity
: num
);
822 function ts_currencyToSortKey( s
) {
823 return ts_parseFloat(s
.replace(/[^-\u22120-9.,]/g,''));
826 function ts_sort_generic(a
, b
) {
827 return a
[1] < b
[1] ? -1 : a
[1] > b
[1] ? 1 : a
[2] - b
[2];
830 function ts_alternate(table
) {
831 // Take object table and get all it's tbodies.
832 var tableBodies
= table
.getElementsByTagName("tbody");
833 // Loop through these tbodies
834 for (var i
= 0; i
< tableBodies
.length
; i
++) {
835 // Take the tbody, and get all it's rows
836 var tableRows
= tableBodies
[i
].getElementsByTagName("tr");
837 // Loop through these rows
838 // Start at 1 because we want to leave the heading row untouched
839 for (var j
= 0; j
< tableRows
.length
; j
++) {
840 // Check if j is even, and apply classes for both possible results
841 var oldClasses
= tableRows
[j
].className
.split(" ");
842 var newClassName
= "";
843 for (var k
= 0; k
< oldClasses
.length
; k
++) {
844 if (oldClasses
[k
] != "" && oldClasses
[k
] != "even" && oldClasses
[k
] != "odd")
845 newClassName
+= oldClasses
[k
] + " ";
847 tableRows
[j
].className
= newClassName
+ (j
% 2 == 0 ? "even" : "odd");
853 * End of table sorting code
858 * Add a cute little box at the top of the screen to inform the user of
859 * something, replacing any preexisting message.
861 * @param String -or- Dom Object message HTML to be put inside the right div
862 * @param String className Used in adding a class; should be different for each
863 * call to allow CSS/JS to hide different boxes. null = no class used.
864 * @return Boolean True on success, false on failure
866 function jsMsg( message
, className
) {
867 if ( !document
.getElementById
) {
870 // We special-case skin structures provided by the software. Skins that
871 // choose to abandon or significantly modify our formatting can just define
872 // an mw-js-message div to start with.
873 var messageDiv
= document
.getElementById( 'mw-js-message' );
875 messageDiv
= document
.createElement( 'div' );
876 if ( document
.getElementById( 'column-content' )
877 && document
.getElementById( 'content' ) ) {
878 // MonoBook, presumably
879 document
.getElementById( 'content' ).insertBefore(
881 document
.getElementById( 'content' ).firstChild
883 } else if ( document
.getElementById('content')
884 && document
.getElementById( 'article' ) ) {
885 // Non-Monobook but still recognizable (old-style)
886 document
.getElementById( 'article').insertBefore(
888 document
.getElementById( 'article' ).firstChild
895 messageDiv
.setAttribute( 'id', 'mw-js-message' );
896 messageDiv
.style
.display
= 'block';
898 messageDiv
.setAttribute( 'class', 'mw-js-message-'+className
);
901 if (typeof message
=== 'object') {
902 while (messageDiv
.hasChildNodes()) // Remove old content
903 messageDiv
.removeChild(messageDiv
.firstChild
);
904 messageDiv
.appendChild (message
); // Append new content
907 messageDiv
.innerHTML
= message
;
913 * Inject a cute little progress spinner after the specified element
915 * @param element Element to inject after
916 * @param id Identifier string (for use with removeSpinner(), below)
918 function injectSpinner( element
, id
) {
919 var spinner
= document
.createElement( "img" );
920 spinner
.id
= "mw-spinner-" + id
;
921 spinner
.src
= stylepath
+ "/common/images/spinner.gif";
922 spinner
.alt
= spinner
.title
= "...";
923 if( element
.nextSibling
) {
924 element
.parentNode
.insertBefore( spinner
, element
.nextSibling
);
926 element
.parentNode
.appendChild( spinner
);
931 * Remove a progress spinner added with injectSpinner()
933 * @param id Identifier string
935 function removeSpinner( id
) {
936 var spinner
= document
.getElementById( "mw-spinner-" + id
);
938 spinner
.parentNode
.removeChild( spinner
);
942 function runOnloadHook() {
943 // don't run anything below this for non-dom browsers
944 if (doneOnloadHook
|| !(document
.getElementById
&& document
.getElementsByTagName
)) {
948 // set this before running any hooks, since any errors below
949 // might cause the function to terminate prematurely
950 doneOnloadHook
= true;
952 updateTooltipAccessKeys( null );
953 setupCheckboxShiftClick();
956 // Run any added-on functions
957 for (var i
= 0; i
< onloadFuncts
.length
; i
++) {
963 * Add an event handler to an element
965 * @param Element element Element to add handler to
966 * @param String attach Event to attach to
967 * @param callable handler Event handler callback
969 function addHandler( element
, attach
, handler
) {
970 if( window
.addEventListener
) {
971 element
.addEventListener( attach
, handler
, false );
972 } else if( window
.attachEvent
) {
973 element
.attachEvent( 'on' + attach
, handler
);
978 * Add a click event handler to an element
980 * @param Element element Element to add handler to
981 * @param callable handler Event handler callback
983 function addClickHandler( element
, handler
) {
984 addHandler( element
, 'click', handler
);
988 * Removes an event handler from an element
990 * @param Element element Element to remove handler from
991 * @param String remove Event to remove
992 * @param callable handler Event handler callback to remove
994 function removeHandler( element
, remove
, handler
) {
995 if( window
.removeEventListener
) {
996 element
.removeEventListener( remove
, handler
, false );
997 } else if( window
.detachEvent
) {
998 element
.detachEvent( 'on' + remove
, handler
);
1001 //note: all skins should call runOnloadHook() at the end of html output,
1002 // so the below should be redundant. It's there just in case.
1003 hookEvent("load", runOnloadHook
);
1006 var isMSIE55
= (window
.showModalDialog
&& window
.clipboardData
&& window
.createPopup
);
1007 var doneIETransform
;
1010 if (document
.attachEvent
)
1011 document
.attachEvent('onreadystatechange', hookit
);
1014 if (!doneIETransform
&& document
.getElementById
&& document
.getElementById('bodyContent')) {
1015 doneIETransform
= true;
1016 relativeforfloats();
1021 // png alpha transparency fixes
1022 function fixalpha( logoId
) {
1024 if (isMSIE55
&& !doneIEAlphaFix
)
1026 var plogo
= document
.getElementById( logoId
|| 'p-logo' );
1029 var logoa
= plogo
.getElementsByTagName('a')[0];
1032 var bg
= logoa
.currentStyle
.backgroundImage
;
1033 var imageUrl
= bg
.substring(5, bg
.length
-2);
1035 doneIEAlphaFix
= true;
1037 if (imageUrl
.substr(imageUrl
.length
-4).toLowerCase() == '.png') {
1038 var logospan
= logoa
.appendChild(document
.createElement('span'));
1040 logoa
.style
.backgroundImage
= 'none';
1041 logospan
.style
.filter
= 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl
+ ')';
1042 logospan
.style
.height
= '100%';
1043 logospan
.style
.position
= 'absolute';
1044 logospan
.style
.width
= logoa
.currentStyle
.width
;
1045 logospan
.style
.cursor
= 'hand';
1046 // Center image with hack for IE5.5
1047 if (document
.documentElement
.dir
== "rtl")
1049 logospan
.style
.right
= '50%';
1050 logospan
.style
.setExpression('marginRight', '"-" + (this.offsetWidth / 2) + "px"');
1054 logospan
.style
.left
= '50%';
1055 logospan
.style
.setExpression('marginLeft', '"-" + (this.offsetWidth / 2) + "px"');
1057 logospan
.style
.top
= '50%';
1058 logospan
.style
.setExpression('marginTop', '"-" + (this.offsetHeight / 2) + "px"');
1060 var linkFix
= logoa
.appendChild(logoa
.cloneNode());
1061 linkFix
.style
.position
= 'absolute';
1062 linkFix
.style
.height
= '100%';
1063 linkFix
.style
.width
= '100%';
1068 // fix ie6 disappering float bug
1069 function relativeforfloats() {
1070 var bc
= document
.getElementById('bodyContent');
1072 var tables
= bc
.getElementsByTagName('table');
1073 var divs
= bc
.getElementsByTagName('div');
1075 setrelative(tables
);
1078 function setrelative (nodes
) {
1080 while (i
< nodes
.length
) {
1081 if(((nodes
[i
].style
.float && nodes
[i
].style
.float != ('none') ||
1082 (nodes
[i
].align
&& nodes
[i
].align
!= ('none'))) &&
1083 (!nodes
[i
].style
.position
|| nodes
[i
].style
.position
!= 'relative')))
1085 nodes
[i
].style
.position
= 'relative';
1092 // Expand links for printing
1094 String
.prototype.hasClass = function(classWanted
)
1096 var classArr
= this.split(/\s/);
1097 for (var i
=0; i
<classArr
.length
; i
++)
1098 if (classArr
[i
].toLowerCase() == classWanted
.toLowerCase()) return true;
1104 onbeforeprint = function() {
1107 var contentEl
= document
.getElementById("content");
1111 var allLinks
= contentEl
.getElementsByTagName("a");
1113 for (var i
=0; i
< allLinks
.length
; i
++) {
1114 if (allLinks
[i
].className
.hasClass("external") && !allLinks
[i
].className
.hasClass("free")) {
1115 var expandedLink
= document
.createElement("span");
1116 var expandedText
= document
.createTextNode(" (" + allLinks
[i
].href
+ ")");
1117 expandedLink
.appendChild(expandedText
);
1118 allLinks
[i
].parentNode
.insertBefore(expandedLink
, allLinks
[i
].nextSibling
);
1119 expandedURLs
[i
] = expandedLink
;
1125 onafterprint = function() {
1126 for (var i
=0; i
< expandedURLs
.length
; i
++)
1127 if (expandedURLs
[i
])
1128 expandedURLs
[i
].removeNode(true);