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
43 if( !doneOnloadHook
) {
44 onloadFuncts
[onloadFuncts
.length
] = hookFunct
;
46 hookFunct(); // bug in MSIE script loading
50 function hookEvent( hookName
, hookFunct
) {
51 addHandler( window
, hookName
, hookFunct
);
54 function importScript( page
) {
55 // TODO: might want to introduce a utility function to match wfUrlencode() in PHP
56 var uri
= wgScript
+ '?title=' +
57 encodeURIComponent(page
.replace(/ /g,'_')).replace(/%2F
/ig,'/').replace(/%3A/ig,':') +
58 '&action
=raw
&ctype
=text
/javascript
';
59 return importScriptURI( uri );
62 var loadedScripts = {}; // included-scripts tracker
63 function importScriptURI( url ) {
64 if ( loadedScripts[url] ) {
67 loadedScripts[url] = true;
68 var s = document.createElement( 'script
' );
69 s.setAttribute( 'src
', url );
70 s.setAttribute( 'type
', 'text
/javascript
' );
71 document.getElementsByTagName('head
')[0].appendChild( s );
75 function importStylesheet( page ) {
76 return importStylesheetURI( wgScript + '?action
=raw
&ctype
=text
/css&title=' + encodeURIComponent( page.replace(/ /g
,'_') ) );
79 function importStylesheetURI( url
, media
) {
80 var l
= document
.createElement( 'link' );
87 document
.getElementsByTagName('head')[0].appendChild( l
);
91 function appendCSS( text
) {
92 var s
= document
.createElement( 'style' );
96 s
.styleSheet
.cssText
= text
; // IE
98 s
.appendChild( document
.createTextNode( text
+ '' ) ); // Safari sometimes borks on null
100 document
.getElementsByTagName('head')[0].appendChild( s
);
104 // special stylesheet links
105 if ( typeof stylepath
!= 'undefined' && typeof skin
!= 'undefined' ) {
106 // FIXME: This tries to load the stylesheets even for skins where they
107 // don't exist, i.e., everything but Monobook.
109 importStylesheetURI( stylepath
+ '/' + skin
+ '/Opera6Fixes.css' );
110 } else if ( opera7_bugs
) {
111 importStylesheetURI( stylepath
+ '/' + skin
+ '/Opera7Fixes.css' );
112 } else if ( opera95_bugs
) {
113 importStylesheetURI( stylepath
+ '/' + skin
+ '/Opera9Fixes.css' );
114 } else if ( ff2_bugs
) {
115 importStylesheetURI( stylepath
+ '/' + skin
+ '/FF2Fixes.css' );
120 if ( wgBreakFrames
) {
121 // Un-trap us from framesets
122 if ( window
.top
!= window
) {
123 window
.top
.location
= window
.location
;
127 function showTocToggle() {
128 if ( document
.createTextNode
) {
129 // Uses DOM calls to avoid document.write + XHTML issues
131 var linkHolder
= document
.getElementById( 'toctitle' );
132 var existingLink
= document
.getElementById( 'togglelink' );
133 if ( !linkHolder
|| existingLink
) {
134 // Don't add the toggle link twice
138 var outerSpan
= document
.createElement( 'span' );
139 outerSpan
.className
= 'toctoggle';
141 var toggleLink
= document
.createElement( 'a' );
142 toggleLink
.id
= 'togglelink';
143 toggleLink
.className
= 'internal';
144 toggleLink
.href
= 'javascript:toggleToc()';
145 toggleLink
.appendChild( document
.createTextNode( tocHideText
) );
147 outerSpan
.appendChild( document
.createTextNode( '[' ) );
148 outerSpan
.appendChild( toggleLink
);
149 outerSpan
.appendChild( document
.createTextNode( ']' ) );
151 linkHolder
.appendChild( document
.createTextNode( ' ' ) );
152 linkHolder
.appendChild( outerSpan
);
154 var cookiePos
= document
.cookie
.indexOf( "hidetoc=" );
155 if ( cookiePos
> -1 && document
.cookie
.charAt( cookiePos
+ 8 ) == 1 ) {
161 function changeText( el
, newText
) {
162 // Safari work around
163 if ( el
.innerText
) {
164 el
.innerText
= newText
;
165 } else if ( el
.firstChild
&& el
.firstChild
.nodeValue
) {
166 el
.firstChild
.nodeValue
= newText
;
170 function toggleToc() {
171 var tocmain
= document
.getElementById( 'toc' );
172 var toc
= document
.getElementById('toc').getElementsByTagName('ul')[0];
173 var toggleLink
= document
.getElementById( 'togglelink' );
175 if ( toc
&& toggleLink
&& toc
.style
.display
== 'none' ) {
176 changeText( toggleLink
, tocHideText
);
177 toc
.style
.display
= 'block';
178 document
.cookie
= "hidetoc=0";
179 tocmain
.className
= 'toc';
181 changeText( toggleLink
, tocShowText
);
182 toc
.style
.display
= 'none';
183 document
.cookie
= "hidetoc=1";
184 tocmain
.className
= 'toc tochidden';
188 var mwEditButtons
= [];
189 var mwCustomEditButtons
= []; // eg to add in MediaWiki:Common.js
191 function escapeQuotes( text
) {
192 var re
= new RegExp( "'", "g" );
193 text
= text
.replace( re
, "\\'" );
194 re
= new RegExp( "\\n", "g" );
195 text
= text
.replace( re
, "\\n" );
196 return escapeQuotesHTML( text
);
199 function escapeQuotesHTML( text
) {
200 var re
= new RegExp( '&', "g" );
201 text
= text
.replace( re
, "&" );
202 re
= new RegExp( '"', "g" );
203 text
= text
.replace( re
, """ );
204 re
= new RegExp( '<', "g" );
205 text
= text
.replace( re
, "<" );
206 re
= new RegExp( '>', "g" );
207 text
= text
.replace( re
, ">" );
212 * Set the accesskey prefix based on browser detection.
214 var tooltipAccessKeyPrefix
= 'alt-';
216 tooltipAccessKeyPrefix
= 'shift-esc-';
217 } else if ( !is_safari_win
&& is_safari
&& webkit_version
> 526 ) {
218 tooltipAccessKeyPrefix
= 'ctrl-alt-';
219 } else if ( !is_safari_win
&& ( is_safari
220 || clientPC
.indexOf('mac') != -1
221 || clientPC
.indexOf('konqueror') != -1 ) ) {
222 tooltipAccessKeyPrefix
= 'ctrl-';
223 } else if ( is_ff2
) {
224 tooltipAccessKeyPrefix
= 'alt-shift-';
226 var tooltipAccessKeyRegexp
= /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/;
229 * Add the appropriate prefix to the accesskey shown in the tooltip.
230 * If the nodeList parameter is given, only those nodes are updated;
231 * otherwise, all the nodes that will probably have accesskeys by
232 * default are updated.
234 * @param Array nodeList -- list of elements to update
236 function updateTooltipAccessKeys( nodeList
) {
238 // Rather than scan all links on the whole page, we can just scan these
239 // containers which contain the relevant links. This is really just an
240 // optimization technique.
241 var linkContainers
= [
242 'column-one', // Monobook and Modern
243 'head', 'panel', 'p-logo' // Vector
245 for ( var i
in linkContainers
) {
246 var linkContainer
= document
.getElementById( linkContainers
[i
] );
247 if ( linkContainer
) {
248 updateTooltipAccessKeys( linkContainer
.getElementsByTagName( 'a' ) );
251 // these are rare enough that no such optimization is needed
252 updateTooltipAccessKeys( document
.getElementsByTagName( 'input' ) );
253 updateTooltipAccessKeys( document
.getElementsByTagName( 'label' ) );
257 for ( var i
= 0; i
< nodeList
.length
; i
++ ) {
258 var element
= nodeList
[i
];
259 var tip
= element
.getAttribute( 'title' );
260 if ( tip
&& tooltipAccessKeyRegexp
.exec( tip
) ) {
261 tip
= tip
.replace(tooltipAccessKeyRegexp
,
262 '[' + tooltipAccessKeyPrefix
+ "$5]");
263 element
.setAttribute( 'title', tip
);
269 * Add a link to one of the portlet menus on the page, including:
271 * p-cactions: Content actions (shown as tabs above the main content in Monobook)
272 * p-personal: Personal tools (shown at the top right of the page in Monobook)
273 * p-navigation: Navigation
276 * This function exists for the convenience of custom JS authors. All
277 * but the first three parameters are optional, though providing at
278 * least an id and a tooltip is recommended.
280 * By default the new link will be added to the end of the list. To
281 * add the link before a given existing item, pass the DOM node of
282 * that item (easily obtained with document.getElementById()) as the
283 * nextnode parameter; to add the link _after_ an existing item, pass
284 * the node's nextSibling instead.
286 * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb")
287 * @param String href -- link URL
288 * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook)
289 * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-")
290 * @param String tooltip -- text to show when hovering over the link, without accesskey suffix
291 * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts)
292 * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list
294 * @return Node -- the DOM node of the new item (an LI element) or null
296 function addPortletLink( portlet
, href
, text
, id
, tooltip
, accesskey
, nextnode
) {
297 var root
= document
.getElementById( portlet
);
301 var node
= root
.getElementsByTagName( 'ul' )[0];
306 // unhide portlet if it was hidden before
307 root
.className
= root
.className
.replace( /(^| )emptyPortlet( |$)/, "$2" );
309 var span
= document
.createElement( 'span' );
310 span
.appendChild( document
.createTextNode( text
) );
312 var link
= document
.createElement( 'a' );
313 link
.appendChild( span
);
316 var item
= document
.createElement( 'li' );
317 item
.appendChild( link
);
323 link
.setAttribute( 'accesskey', accesskey
);
324 tooltip
+= ' [' + accesskey
+ ']';
327 link
.setAttribute( 'title', tooltip
);
329 if ( accesskey
&& tooltip
) {
330 updateTooltipAccessKeys( new Array( link
) );
333 if ( nextnode
&& nextnode
.parentNode
== node
) {
334 node
.insertBefore( item
, nextnode
);
336 node
.appendChild( item
); // IE compatibility (?)
342 function getInnerText( el
) {
343 if ( typeof el
== 'string' ) {
346 if ( typeof el
== 'undefined' ) {
349 if ( el
.textContent
) {
350 return el
.textContent
; // not needed but it is faster
352 if ( el
.innerText
) {
353 return el
.innerText
; // IE doesn't have textContent
357 var cs
= el
.childNodes
;
359 for ( var i
= 0; i
< l
; i
++ ) {
360 switch ( cs
[i
].nodeType
) {
361 case 1: // ELEMENT_NODE
362 str
+= ts_getInnerText( cs
[i
] );
365 str
+= cs
[i
].nodeValue
;
372 /* Dummy for deprecated function */
373 function akeytt( doId
) {
379 function setupCheckboxShiftClick() {
382 var inputs
= document
.getElementsByTagName( 'input' );
383 addCheckboxClickHandlers( inputs
);
386 function addCheckboxClickHandlers( inputs
, start
) {
391 var finish
= start
+ 250;
392 if ( finish
> inputs
.length
) {
393 finish
= inputs
.length
;
396 for ( var i
= start
; i
< finish
; i
++ ) {
398 if ( !cb
.type
|| cb
.type
.toLowerCase() != 'checkbox' ) {
401 var end
= checkboxes
.length
;
402 checkboxes
[end
] = cb
;
404 cb
.onclick
= checkboxClickHandler
;
407 if ( finish
< inputs
.length
) {
408 setTimeout( function() {
409 addCheckboxClickHandlers( inputs
, finish
);
414 function checkboxClickHandler( e
) {
415 if ( typeof e
== 'undefined' ) {
418 if ( !e
.shiftKey
|| lastCheckbox
=== null ) {
419 lastCheckbox
= this.index
;
422 var endState
= this.checked
;
424 if ( this.index
< lastCheckbox
) {
425 start
= this.index
+ 1;
426 finish
= lastCheckbox
;
428 start
= lastCheckbox
;
429 finish
= this.index
- 1;
431 for ( var i
= start
; i
<= finish
; ++i
) {
432 checkboxes
[i
].checked
= endState
;
433 if( i
> start
&& typeof checkboxes
[i
].onchange
== 'function' ) {
434 checkboxes
[i
].onchange(); // fire triggers
437 lastCheckbox
= this.index
;
443 Written by Jonathan Snook, http://www.snook.ca/jonathan
444 Add-ons by Robert Nyman, http://www.robertnyman.com
445 Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"
446 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
448 function getElementsByClassName( oElm
, strTagName
, oClassNames
) {
449 var arrReturnElements
= new Array();
450 if ( typeof( oElm
.getElementsByClassName
) == 'function' ) {
451 /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
452 var arrNativeReturn
= oElm
.getElementsByClassName( oClassNames
);
453 if ( strTagName
== '*' ) {
454 return arrNativeReturn
;
456 for ( var h
= 0; h
< arrNativeReturn
.length
; h
++ ) {
457 if( arrNativeReturn
[h
].tagName
.toLowerCase() == strTagName
.toLowerCase() ) {
458 arrReturnElements
[arrReturnElements
.length
] = arrNativeReturn
[h
];
461 return arrReturnElements
;
463 var arrElements
= ( strTagName
== '*' && oElm
.all
) ? oElm
.all
: oElm
.getElementsByTagName( strTagName
);
464 var arrRegExpClassNames
= new Array();
465 if( typeof oClassNames
== 'object' ) {
466 for( var i
= 0; i
< oClassNames
.length
; i
++ ) {
467 arrRegExpClassNames
[arrRegExpClassNames
.length
] =
468 new RegExp("(^|\\s)" + oClassNames
[i
].replace(/\-/g, "\\-") + "(\\s|$)");
471 arrRegExpClassNames
[arrRegExpClassNames
.length
] =
472 new RegExp("(^|\\s)" + oClassNames
.replace(/\-/g, "\\-") + "(\\s|$)");
476 for( var j
= 0; j
< arrElements
.length
; j
++ ) {
477 oElement
= arrElements
[j
];
479 for( var k
= 0; k
< arrRegExpClassNames
.length
; k
++ ) {
480 if( !arrRegExpClassNames
[k
].test( oElement
.className
) ) {
486 arrReturnElements
[arrReturnElements
.length
] = oElement
;
489 return ( arrReturnElements
);
492 function redirectToFragment( fragment
) {
493 var match
= navigator
.userAgent
.match(/AppleWebKit\/(\d+)/);
495 var webKitVersion
= parseInt( match
[1] );
496 if ( webKitVersion
< 420 ) {
497 // Released Safari w/ WebKit 418.9.1 messes up horribly
498 // Nightlies of 420+ are ok
503 // Mozilla needs to wait until after load, otherwise the window doesn't scroll
504 addOnloadHook(function() {
505 if ( window
.location
.hash
== '' ) {
506 window
.location
.hash
= fragment
;
510 if ( window
.location
.hash
== '' ) {
511 window
.location
.hash
= fragment
;
517 * Table sorting script based on one (c) 1997-2006 Stuart Langridge and Joost
519 * http://www.joostdevalk.nl/code/sortable-table/
520 * http://www.kryogenix.org/code/browser/sorttable/
522 * @todo don't break on colspans/rowspans (bug 8028)
523 * @todo language-specific digit grouping/decimals (bug 8063)
524 * @todo support all accepted date formats (bug 8226)
527 var ts_image_path
= stylepath
+ '/common/images/';
528 var ts_image_up
= 'sort_up.gif';
529 var ts_image_down
= 'sort_down.gif';
530 var ts_image_none
= 'sort_none.gif';
531 var ts_europeandate
= wgContentLanguage
!= 'en'; // The non-American-inclined can change to "true"
532 var ts_alternate_row_colors
= false;
533 var ts_number_transform_table
= null;
534 var ts_number_regex
= null;
536 function sortables_init() {
538 // Find all tables with class sortable and make them sortable
539 var tables
= getElementsByClassName( document
, 'table', 'sortable' );
540 for ( var ti
= 0; ti
< tables
.length
; ti
++ ) {
541 if ( !tables
[ti
].id
) {
542 tables
[ti
].setAttribute( 'id', 'sortable_table_id_' + idnum
);
545 ts_makeSortable( tables
[ti
] );
549 function ts_makeSortable( table
) {
551 if ( table
.rows
&& table
.rows
.length
> 0 ) {
552 if ( table
.tHead
&& table
.tHead
.rows
.length
> 0 ) {
553 firstRow
= table
.tHead
.rows
[table
.tHead
.rows
.length
-1];
555 firstRow
= table
.rows
[0];
562 // We have a first row: assume it's the header, and make its contents clickable links
563 for ( var i
= 0; i
< firstRow
.cells
.length
; i
++ ) {
564 var cell
= firstRow
.cells
[i
];
565 if ( (' ' + cell
.className
+ ' ').indexOf(' unsortable ') == -1 ) {
566 cell
.innerHTML
+= '<a href="#" class="sortheader" '
567 + 'onclick="ts_resortTable(this);return false;">'
568 + '<span class="sortarrow">'
572 + '" alt="↓"/></span></a>';
575 if ( ts_alternate_row_colors
) {
576 ts_alternate( table
);
580 function ts_getInnerText( el
) {
581 return getInnerText( el
);
584 function ts_resortTable( lnk
) {
586 var span
= lnk
.getElementsByTagName('span')[0];
588 var td
= lnk
.parentNode
;
589 var tr
= td
.parentNode
;
590 var column
= td
.cellIndex
;
592 var table
= tr
.parentNode
;
593 while ( table
&& !( table
.tagName
&& table
.tagName
.toLowerCase() == 'table' ) ) {
594 table
= table
.parentNode
;
600 if ( table
.rows
.length
<= 1 ) {
604 // Generate the number transform table if it's not done already
605 if ( ts_number_transform_table
=== null ) {
606 ts_initTransformTable();
609 // Work out a type for the column
610 // Skip the first row if that's where the headings are
611 var rowStart
= ( table
.tHead
&& table
.tHead
.rows
.length
> 0 ? 0 : 1 );
614 for ( var i
= rowStart
; i
< table
.rows
.length
; i
++ ) {
615 if ( table
.rows
[i
].cells
.length
> column
) {
616 itm
= ts_getInnerText(table
.rows
[i
].cells
[column
]);
617 itm
= itm
.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '');
624 // TODO: bug 8226, localised date formats
625 var sortfn
= ts_sort_generic
;
626 var preprocessor
= ts_toLowerCase
;
627 if ( /^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/.test( itm
) ) {
628 preprocessor
= ts_dateToSortKey
;
629 } else if ( /^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/.test( itm
) ) {
630 preprocessor
= ts_dateToSortKey
;
631 } else if ( /^\d\d[\/.-]\d\d[\/.-]\d\d$/.test( itm
) ) {
632 preprocessor
= ts_dateToSortKey
;
633 // (minus sign)([pound dollar euro yen currency]|cents)
634 } else if ( /(^([-\u2212] *)?[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test( itm
) ) {
635 preprocessor
= ts_currencyToSortKey
;
636 } else if ( ts_number_regex
.test( itm
) ) {
637 preprocessor
= ts_parseFloat
;
640 var reverse
= ( span
.getAttribute( 'sortdir' ) == 'down' );
642 var newRows
= new Array();
643 var staticRows
= new Array();
644 for ( var j
= rowStart
; j
< table
.rows
.length
; j
++ ) {
645 var row
= table
.rows
[j
];
646 if( (' ' + row
.className
+ ' ').indexOf(' unsortable ') < 0 ) {
647 var keyText
= ts_getInnerText( row
.cells
[column
] );
648 if( keyText
=== undefined ) {
651 var oldIndex
= ( reverse
? -j
: j
);
652 var preprocessed
= preprocessor( keyText
.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '') );
654 newRows
[newRows
.length
] = new Array( row
, preprocessed
, oldIndex
);
656 staticRows
[staticRows
.length
] = new Array( row
, false, j
-rowStart
);
660 newRows
.sort( sortfn
);
664 arrowHTML
= '<img src="' + ts_image_path
+ ts_image_down
+ '" alt="↓"/>';
666 span
.setAttribute( 'sortdir', 'up' );
668 arrowHTML
= '<img src="' + ts_image_path
+ ts_image_up
+ '" alt="↑"/>';
669 span
.setAttribute( 'sortdir', 'down' );
672 for ( var i
= 0; i
< staticRows
.length
; i
++ ) {
673 var row
= staticRows
[i
];
674 newRows
.splice( row
[2], 0, row
);
677 // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
678 // don't do sortbottom rows
679 for ( var i
= 0; i
< newRows
.length
; i
++ ) {
680 if ( ( ' ' + newRows
[i
][0].className
+ ' ').indexOf(' sortbottom ') == -1 ) {
681 table
.tBodies
[0].appendChild( newRows
[i
][0] );
684 // do sortbottom rows only
685 for ( var i
= 0; i
< newRows
.length
; i
++ ) {
686 if ( ( ' ' + newRows
[i
][0].className
+ ' ').indexOf(' sortbottom ') != -1 ) {
687 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
) {
699 ts_alternate( table
);
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() ) {
800 // default: var month = '00';
802 return date
.substr( 7, 4 ) + month
+ date
.substr( 0, 2 );
803 } else if ( date
.length
== 10 ) {
804 if ( ts_europeandate
== false ) {
805 return date
.substr( 6, 4 ) + date
.substr( 0, 2 ) + date
.substr( 3, 2 );
807 return date
.substr( 6, 4 ) + date
.substr( 3, 2 ) + date
.substr( 0, 2 );
809 } else if ( date
.length
== 8 ) {
810 yr
= date
.substr( 6, 2 );
811 if ( parseInt( yr
) < 50 ) {
816 if ( ts_europeandate
== true ) {
817 return yr
+ date
.substr( 3, 2 ) + date
.substr( 0, 2 );
819 return yr
+ date
.substr( 0, 2 ) + date
.substr( 3, 2 );
825 function ts_parseFloat( s
) {
829 if ( ts_number_transform_table
!= false ) {
832 for ( var p
= 0; p
< s
.length
; p
++ ) {
834 if ( c
in ts_number_transform_table
) {
835 newNum
+= ts_number_transform_table
[c
];
842 num
= parseFloat( s
.replace(/[, ]/g, '').replace("\u2212", '-') );
843 return ( isNaN( num
) ? -Infinity
: num
);
846 function ts_currencyToSortKey( s
) {
847 return ts_parseFloat(s
.replace(/[^-\u22120-9.,]/g,''));
850 function ts_sort_generic( a
, b
) {
851 return a
[1] < b
[1] ? -1 : a
[1] > b
[1] ? 1 : a
[2] - b
[2];
854 function ts_alternate( table
) {
855 // Take object table and get all it's tbodies.
856 var tableBodies
= table
.getElementsByTagName( 'tbody' );
857 // Loop through these tbodies
858 for ( var i
= 0; i
< tableBodies
.length
; i
++ ) {
859 // Take the tbody, and get all it's rows
860 var tableRows
= tableBodies
[i
].getElementsByTagName( 'tr' );
861 // Loop through these rows
862 // Start at 1 because we want to leave the heading row untouched
863 for ( var j
= 0; j
< tableRows
.length
; j
++ ) {
864 // Check if j is even, and apply classes for both possible results
865 var oldClasses
= tableRows
[j
].className
.split(' ');
866 var newClassName
= '';
867 for ( var k
= 0; k
< oldClasses
.length
; k
++ ) {
868 if ( oldClasses
[k
] != '' && oldClasses
[k
] != 'even' && oldClasses
[k
] != 'odd' ) {
869 newClassName
+= oldClasses
[k
] + ' ';
872 tableRows
[j
].className
= newClassName
+ ( j
% 2 == 0 ? 'even' : 'odd' );
878 * End of table sorting code
883 * Add a cute little box at the top of the screen to inform the user of
884 * something, replacing any preexisting message.
886 * @param String -or- Dom Object message HTML to be put inside the right div
887 * @param String className Used in adding a class; should be different for each
888 * call to allow CSS/JS to hide different boxes. null = no class used.
889 * @return Boolean True on success, false on failure
891 function jsMsg( message
, className
) {
892 if ( !document
.getElementById
) {
895 // We special-case skin structures provided by the software. Skins that
896 // choose to abandon or significantly modify our formatting can just define
897 // an mw-js-message div to start with.
898 var messageDiv
= document
.getElementById( 'mw-js-message' );
900 messageDiv
= document
.createElement( 'div' );
901 if ( document
.getElementById( 'column-content' )
902 && document
.getElementById( 'content' ) ) {
903 // MonoBook, presumably
904 document
.getElementById( 'content' ).insertBefore(
906 document
.getElementById( 'content' ).firstChild
908 } else if ( document
.getElementById( 'content' )
909 && document
.getElementById( 'article' ) ) {
910 // Non-Monobook but still recognizable (old-style)
911 document
.getElementById( 'article').insertBefore(
913 document
.getElementById( 'article' ).firstChild
920 messageDiv
.setAttribute( 'id', 'mw-js-message' );
921 messageDiv
.style
.display
= 'block';
923 messageDiv
.setAttribute( 'class', 'mw-js-message-' + className
);
926 if ( typeof message
=== 'object' ) {
927 while ( messageDiv
.hasChildNodes() ) { // Remove old content
928 messageDiv
.removeChild( messageDiv
.firstChild
);
930 messageDiv
.appendChild( message
); // Append new content
932 messageDiv
.innerHTML
= message
;
938 * Inject a cute little progress spinner after the specified element
940 * @param element Element to inject after
941 * @param id Identifier string (for use with removeSpinner(), below)
943 function injectSpinner( element
, id
) {
944 var spinner
= document
.createElement( 'img' );
945 spinner
.id
= 'mw-spinner-' + id
;
946 spinner
.src
= stylepath
+ '/common/images/spinner.gif';
947 spinner
.alt
= spinner
.title
= '...';
948 if( element
.nextSibling
) {
949 element
.parentNode
.insertBefore( spinner
, element
.nextSibling
);
951 element
.parentNode
.appendChild( spinner
);
956 * Remove a progress spinner added with injectSpinner()
958 * @param id Identifier string
960 function removeSpinner( id
) {
961 var spinner
= document
.getElementById( 'mw-spinner-' + id
);
963 spinner
.parentNode
.removeChild( spinner
);
967 function runOnloadHook() {
968 // don't run anything below this for non-dom browsers
969 if ( doneOnloadHook
|| !( document
.getElementById
&& document
.getElementsByTagName
) ) {
973 // set this before running any hooks, since any errors below
974 // might cause the function to terminate prematurely
975 doneOnloadHook
= true;
977 updateTooltipAccessKeys( null );
978 setupCheckboxShiftClick();
981 // Run any added-on functions
982 for ( var i
= 0; i
< onloadFuncts
.length
; i
++ ) {
988 * Add an event handler to an element
990 * @param Element element Element to add handler to
991 * @param String attach Event to attach to
992 * @param callable handler Event handler callback
994 function addHandler( element
, attach
, handler
) {
995 if( window
.addEventListener
) {
996 element
.addEventListener( attach
, handler
, false );
997 } else if( window
.attachEvent
) {
998 element
.attachEvent( 'on' + attach
, handler
);
1003 * Add a click event handler to an element
1005 * @param Element element Element to add handler to
1006 * @param callable handler Event handler callback
1008 function addClickHandler( element
, handler
) {
1009 addHandler( element
, 'click', handler
);
1013 * Removes an event handler from an element
1015 * @param Element element Element to remove handler from
1016 * @param String remove Event to remove
1017 * @param callable handler Event handler callback to remove
1019 function removeHandler( element
, remove
, handler
) {
1020 if( window
.removeEventListener
) {
1021 element
.removeEventListener( remove
, handler
, false );
1022 } else if( window
.detachEvent
) {
1023 element
.detachEvent( 'on' + remove
, handler
);
1026 // note: all skins should call runOnloadHook() at the end of html output,
1027 // so the below should be redundant. It's there just in case.
1028 hookEvent( 'load', runOnloadHook
);
1031 var isMSIE55
= ( window
.showModalDialog
&& window
.clipboardData
&& window
.createPopup
);
1032 var doneIETransform
;
1035 if ( document
.attachEvent
) {
1036 document
.attachEvent( 'onreadystatechange', hookit
);
1040 if ( !doneIETransform
&& document
.getElementById
&& document
.getElementById( 'bodyContent' ) ) {
1041 doneIETransform
= true;
1042 relativeforfloats();
1047 // png alpha transparency fixes
1048 function fixalpha( logoId
) {
1050 if ( isMSIE55
&& !doneIEAlphaFix
) {
1051 var plogo
= document
.getElementById( logoId
|| 'p-logo' );
1056 var logoa
= plogo
.getElementsByTagName('a')[0];
1061 var bg
= logoa
.currentStyle
.backgroundImage
;
1062 var imageUrl
= bg
.substring( 5, bg
.length
- 2 );
1064 doneIEAlphaFix
= true;
1066 if ( imageUrl
.substr( imageUrl
.length
- 4 ).toLowerCase() == '.png' ) {
1067 var logospan
= logoa
.appendChild( document
.createElement( 'span' ) );
1069 logoa
.style
.backgroundImage
= 'none';
1070 logospan
.style
.filter
= 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl
+ ')';
1071 logospan
.style
.height
= '100%';
1072 logospan
.style
.position
= 'absolute';
1073 logospan
.style
.width
= logoa
.currentStyle
.width
;
1074 logospan
.style
.cursor
= 'hand';
1075 // Center image with hack for IE5.5
1076 if ( document
.documentElement
.dir
== 'rtl' ) {
1077 logospan
.style
.right
= '50%';
1078 logospan
.style
.setExpression( 'marginRight', '"-" + (this.offsetWidth / 2) + "px"' );
1080 logospan
.style
.left
= '50%';
1081 logospan
.style
.setExpression( 'marginLeft', '"-" + (this.offsetWidth / 2) + "px"' );
1083 logospan
.style
.top
= '50%';
1084 logospan
.style
.setExpression( 'marginTop', '"-" + (this.offsetHeight / 2) + "px"' );
1086 var linkFix
= logoa
.appendChild( logoa
.cloneNode() );
1087 linkFix
.style
.position
= 'absolute';
1088 linkFix
.style
.height
= '100%';
1089 linkFix
.style
.width
= '100%';
1094 // fix ie6 disappering float bug
1095 function relativeforfloats() {
1096 var bc
= document
.getElementById( 'bodyContent' );
1098 var tables
= bc
.getElementsByTagName( 'table' );
1099 var divs
= bc
.getElementsByTagName( 'div' );
1101 setrelative( tables
);
1102 setrelative( divs
);
1104 function setrelative( nodes
) {
1106 while ( i
< nodes
.length
) {
1107 if( ( ( nodes
[i
].style
.float && nodes
[i
].style
.float != ( 'none' ) ||
1108 ( nodes
[i
].align
&& nodes
[i
].align
!= ( 'none' ) ) ) &&
1109 ( !nodes
[i
].style
.position
|| nodes
[i
].style
.position
!= 'relative' ) ) )
1111 nodes
[i
].style
.position
= 'relative';
1117 // Expand links for printing
1118 String
.prototype.hasClass = function( classWanted
) {
1119 var classArr
= this.split(/\s/);
1120 for ( var i
= 0; i
< classArr
.length
; i
++ ) {
1121 if ( classArr
[i
].toLowerCase() == classWanted
.toLowerCase() ) {
1130 onbeforeprint = function() {
1133 var contentEl
= document
.getElementById( 'content' );
1136 var allLinks
= contentEl
.getElementsByTagName( 'a' );
1138 for ( var i
= 0; i
< allLinks
.length
; i
++ ) {
1139 if ( allLinks
[i
].className
.hasClass( 'external' ) && !allLinks
[i
].className
.hasClass( 'free' ) ) {
1140 var expandedLink
= document
.createElement( 'span' );
1141 var expandedText
= document
.createTextNode( ' (' + allLinks
[i
].href
+ ')' );
1142 expandedLink
.appendChild( expandedText
);
1143 allLinks
[i
].parentNode
.insertBefore( expandedLink
, allLinks
[i
].nextSibling
);
1144 expandedURLs
[i
] = expandedLink
;
1150 onafterprint = function() {
1151 for ( var i
= 0; i
< expandedURLs
.length
; i
++ ) {
1152 if ( expandedURLs
[i
] ) {
1153 expandedURLs
[i
].removeNode( true );