r64501 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64500‎ | r64501 | r64502 >
Date:20:37, 1 April 2010
Author:dale
Status:deferred
Tags:
Comment:
added already defined check to mw = {} in wikibits.js
Modified paths:
  • /branches/js2-work/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: branches/js2-work/phase3/skins/common/wikibits.js
@@ -25,6 +25,8 @@
2626 var opera7_bugs = is_opera_seven && !is_opera_95;
2727 var opera95_bugs = /opera\/(9\.5)/.test( clientPC );
2828 }
 29+// Start at 4 to minimize the chance of breaking on IE10 :)
 30+var ie6_bugs = /msie [4-6]/.test( clientPC );
2931
3032 // Global external objects used by this script.
3133 /*extern ta, stylepath, skin */
@@ -36,144 +38,145 @@
3739 var onloadFuncts = [];
3840 }
3941
40 -// code that is dependent on js2 functions should use mw.ready
41 -function addOnloadHook(hookFunct) {
 42+function addOnloadHook( hookFunct ) {
4243 // Allows add-on scripts to add onload functions
43 - if(!doneOnloadHook) {
 44+ if( !doneOnloadHook ) {
4445 onloadFuncts[onloadFuncts.length] = hookFunct;
4546 } else {
4647 hookFunct(); // bug in MSIE script loading
4748 }
4849 }
4950
50 -
51 -function hookEvent(hookName, hookFunct) {
52 - addHandler(window, hookName, hookFunct);
 51+function hookEvent( hookName, hookFunct ) {
 52+ addHandler( window, hookName, hookFunct );
5353 }
5454
55 -function importScript(page) {
 55+function importScript( page ) {
5656 // TODO: might want to introduce a utility function to match wfUrlencode() in PHP
5757 var uri = wgScript + '?title=' +
5858 encodeURIComponent(page.replace(/ /g,'_')).replace(/%2F/ig,'/').replace(/%3A/ig,':') +
5959 '&action=raw&ctype=text/javascript';
60 - return importScriptURI(uri);
 60+ return importScriptURI( uri );
6161 }
6262
6363 var loadedScripts = {}; // included-scripts tracker
64 -function importScriptURI(url) {
65 - if (loadedScripts[url]) {
 64+function importScriptURI( url ) {
 65+ if ( loadedScripts[url] ) {
6666 return null;
6767 }
6868 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);
 69+ var s = document.createElement( 'script' );
 70+ s.setAttribute( 'src', url );
 71+ s.setAttribute( 'type', 'text/javascript' );
 72+ document.getElementsByTagName('head')[0].appendChild( s );
7373 return s;
7474 }
7575
76 -function importStylesheet(page) {
77 - return importStylesheetURI(wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent(page.replace(/ /g,'_')));
 76+function importStylesheet( page ) {
 77+ return importStylesheetURI( wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent( page.replace(/ /g,'_') ) );
7878 }
7979
80 -function importStylesheetURI(url,media) {
81 - var l = document.createElement('link');
 80+function importStylesheetURI( url, media ) {
 81+ var l = document.createElement( 'link' );
8282 l.type = 'text/css';
8383 l.rel = 'stylesheet';
8484 l.href = url;
85 - if(media) l.media = media
86 - document.getElementsByTagName('head')[0].appendChild(l);
 85+ if( media ) {
 86+ l.media = media;
 87+ }
 88+ document.getElementsByTagName('head')[0].appendChild( l );
8789 return l;
8890 }
8991
90 -function appendCSS(text) {
91 - var s = document.createElement('style');
 92+function appendCSS( text ) {
 93+ var s = document.createElement( 'style' );
9294 s.type = 'text/css';
9395 s.rel = 'stylesheet';
94 - if (s.styleSheet) s.styleSheet.cssText = text //IE
95 - else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null
96 - document.getElementsByTagName('head')[0].appendChild(s);
 96+ if ( s.styleSheet ) {
 97+ s.styleSheet.cssText = text; // IE
 98+ } else {
 99+ s.appendChild( document.createTextNode( text + '' ) ); // Safari sometimes borks on null
 100+ }
 101+ document.getElementsByTagName('head')[0].appendChild( s );
97102 return s;
98103 }
99104
100 -// special stylesheet links
101 -if (typeof stylepath != 'undefined' && typeof skin != 'undefined') {
102 - // FIXME: This tries to load the stylesheets even for skins where they
103 - // don't exist, i.e., everything but Monobook.
104 - if (opera6_bugs) {
105 - importStylesheetURI(stylepath+'/'+skin+'/Opera6Fixes.css');
106 - } else if (opera7_bugs) {
107 - importStylesheetURI(stylepath+'/'+skin+'/Opera7Fixes.css');
108 - } else if (opera95_bugs) {
109 - importStylesheetURI(stylepath+'/'+skin+'/Opera9Fixes.css');
110 - } else if (ff2_bugs) {
111 - importStylesheetURI(stylepath+'/'+skin+'/FF2Fixes.css');
 105+// Special stylesheet links for Monobook only (see bug 14717)
 106+if ( typeof stylepath != 'undefined' && skin == 'monobook' ) {
 107+ if ( opera6_bugs ) {
 108+ importStylesheetURI( stylepath + '/' + skin + '/Opera6Fixes.css' );
 109+ } else if ( opera7_bugs ) {
 110+ importStylesheetURI( stylepath + '/' + skin + '/Opera7Fixes.css' );
 111+ } else if ( opera95_bugs ) {
 112+ importStylesheetURI( stylepath + '/' + skin + '/Opera9Fixes.css' );
 113+ } else if ( ff2_bugs ) {
 114+ importStylesheetURI( stylepath + '/' + skin + '/FF2Fixes.css' );
112115 }
113116 }
114117
115118
116 -if (wgBreakFrames) {
 119+if ( wgBreakFrames ) {
117120 // Un-trap us from framesets
118 - if (window.top != window) {
 121+ if ( window.top != window ) {
119122 window.top.location = window.location;
120123 }
121124 }
122125
123126 function showTocToggle() {
124 - if (document.createTextNode) {
 127+ if ( document.createTextNode ) {
125128 // Uses DOM calls to avoid document.write + XHTML issues
126129
127 - var linkHolder = document.getElementById('toctitle');
128 - var existingLink = document.getElementById('togglelink');
129 - if (!linkHolder || existingLink) {
 130+ var linkHolder = document.getElementById( 'toctitle' );
 131+ var existingLink = document.getElementById( 'togglelink' );
 132+ if ( !linkHolder || existingLink ) {
130133 // Don't add the toggle link twice
131134 return;
132135 }
133136
134 - var outerSpan = document.createElement('span');
 137+ var outerSpan = document.createElement( 'span' );
135138 outerSpan.className = 'toctoggle';
136139
137 - var toggleLink = document.createElement('a');
 140+ var toggleLink = document.createElement( 'a' );
138141 toggleLink.id = 'togglelink';
139142 toggleLink.className = 'internal';
140143 toggleLink.href = 'javascript:toggleToc()';
141 - toggleLink.appendChild(document.createTextNode(tocHideText));
 144+ toggleLink.appendChild( document.createTextNode( tocHideText ) );
142145
143 - outerSpan.appendChild(document.createTextNode('['));
144 - outerSpan.appendChild(toggleLink);
145 - outerSpan.appendChild(document.createTextNode(']'));
 146+ outerSpan.appendChild( document.createTextNode( '[' ) );
 147+ outerSpan.appendChild( toggleLink );
 148+ outerSpan.appendChild( document.createTextNode( ']' ) );
146149
147 - linkHolder.appendChild(document.createTextNode(' '));
148 - linkHolder.appendChild(outerSpan);
 150+ linkHolder.appendChild( document.createTextNode( ' ' ) );
 151+ linkHolder.appendChild( outerSpan );
149152
150 - var cookiePos = document.cookie.indexOf("hidetoc=");
151 - if (cookiePos > -1 && document.cookie.charAt(cookiePos + 8) == 1) {
 153+ var cookiePos = document.cookie.indexOf( "hidetoc=" );
 154+ if ( cookiePos > -1 && document.cookie.charAt( cookiePos + 8 ) == 1 ) {
152155 toggleToc();
153156 }
154157 }
155158 }
156159
157 -function changeText(el, newText) {
 160+function changeText( el, newText ) {
158161 // Safari work around
159 - if (el.innerText) {
 162+ if ( el.innerText ) {
160163 el.innerText = newText;
161 - } else if (el.firstChild && el.firstChild.nodeValue) {
 164+ } else if ( el.firstChild && el.firstChild.nodeValue ) {
162165 el.firstChild.nodeValue = newText;
163166 }
164167 }
165168
166169 function toggleToc() {
167 - var tocmain = document.getElementById('toc');
 170+ var tocmain = document.getElementById( 'toc' );
168171 var toc = document.getElementById('toc').getElementsByTagName('ul')[0];
169 - var toggleLink = document.getElementById('togglelink');
 172+ var toggleLink = document.getElementById( 'togglelink' );
170173
171 - if (toc && toggleLink && toc.style.display == 'none') {
172 - changeText(toggleLink, tocHideText);
 174+ if ( toc && toggleLink && toc.style.display == 'none' ) {
 175+ changeText( toggleLink, tocHideText );
173176 toc.style.display = 'block';
174177 document.cookie = "hidetoc=0";
175178 tocmain.className = 'toc';
176179 } else {
177 - changeText(toggleLink, tocShowText);
 180+ changeText( toggleLink, tocShowText );
178181 toc.style.display = 'none';
179182 document.cookie = "hidetoc=1";
180183 tocmain.className = 'toc tochidden';
@@ -183,40 +186,39 @@
184187 var mwEditButtons = [];
185188 var mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js
186189
187 -function escapeQuotes(text) {
188 - var re = new RegExp("'","g");
189 - text = text.replace(re,"\\'");
190 - re = new RegExp("\\n","g");
191 - text = text.replace(re,"\\n");
192 - return escapeQuotesHTML(text);
 190+function escapeQuotes( text ) {
 191+ var re = new RegExp( "'", "g" );
 192+ text = text.replace( re, "\\'" );
 193+ re = new RegExp( "\\n", "g" );
 194+ text = text.replace( re, "\\n" );
 195+ return escapeQuotesHTML( text );
193196 }
194197
195 -function escapeQuotesHTML(text) {
196 - var re = new RegExp('&',"g");
197 - text = text.replace(re,"&");
198 - re = new RegExp('"',"g");
199 - text = text.replace(re,""");
200 - re = new RegExp('<',"g");
201 - text = text.replace(re,"&lt;");
202 - re = new RegExp('>',"g");
203 - text = text.replace(re,"&gt;");
 198+function escapeQuotesHTML( text ) {
 199+ var re = new RegExp( '&', "g" );
 200+ text = text.replace( re, "&amp;" );
 201+ re = new RegExp( '"', "g" );
 202+ text = text.replace( re, "&quot;" );
 203+ re = new RegExp( '<', "g" );
 204+ text = text.replace( re, "&lt;" );
 205+ re = new RegExp( '>', "g" );
 206+ text = text.replace( re, "&gt;" );
204207 return text;
205208 }
206209
207 -
208210 /**
209211 * Set the accesskey prefix based on browser detection.
210212 */
211213 var tooltipAccessKeyPrefix = 'alt-';
212 -if (is_opera) {
 214+if ( is_opera ) {
213215 tooltipAccessKeyPrefix = 'shift-esc-';
214 -} else if (!is_safari_win && is_safari && webkit_version > 526) {
 216+} else if ( !is_safari_win && is_safari && webkit_version > 526 ) {
215217 tooltipAccessKeyPrefix = 'ctrl-alt-';
216 -} else if (!is_safari_win && (is_safari
 218+} else if ( !is_safari_win && ( is_safari
217219 || clientPC.indexOf('mac') != -1
218 - || clientPC.indexOf('konqueror') != -1 )) {
 220+ || clientPC.indexOf('konqueror') != -1 ) ) {
219221 tooltipAccessKeyPrefix = 'ctrl-';
220 -} else if (is_ff2) {
 222+} else if ( is_ff2 ) {
221223 tooltipAccessKeyPrefix = 'alt-shift-';
222224 }
223225 var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/;
@@ -235,28 +237,28 @@
236238 // containers which contain the relevant links. This is really just an
237239 // optimization technique.
238240 var linkContainers = [
239 - "column-one", // Monobook and Modern
240 - "head", "panel", "p-logo" // Vector
 241+ 'column-one', // Monobook and Modern
 242+ 'head', 'panel', 'p-logo' // Vector
241243 ];
242244 for ( var i in linkContainers ) {
243245 var linkContainer = document.getElementById( linkContainers[i] );
244246 if ( linkContainer ) {
245 - updateTooltipAccessKeys( linkContainer.getElementsByTagName("a") );
 247+ updateTooltipAccessKeys( linkContainer.getElementsByTagName( 'a' ) );
246248 }
247249 }
248250 // these are rare enough that no such optimization is needed
249 - updateTooltipAccessKeys( document.getElementsByTagName("input") );
250 - updateTooltipAccessKeys( document.getElementsByTagName("label") );
 251+ updateTooltipAccessKeys( document.getElementsByTagName( 'input' ) );
 252+ updateTooltipAccessKeys( document.getElementsByTagName( 'label' ) );
251253 return;
252254 }
253255
254256 for ( var i = 0; i < nodeList.length; i++ ) {
255257 var element = nodeList[i];
256 - var tip = element.getAttribute("title");
257 - if ( tip && tooltipAccessKeyRegexp.exec(tip) ) {
 258+ var tip = element.getAttribute( 'title' );
 259+ if ( tip && tooltipAccessKeyRegexp.exec( tip ) ) {
258260 tip = tip.replace(tooltipAccessKeyRegexp,
259 - "["+tooltipAccessKeyPrefix+"$5]");
260 - element.setAttribute("title", tip );
 261+ '[' + tooltipAccessKeyPrefix + "$5]");
 262+ element.setAttribute( 'title', tip );
261263 }
262264 }
263265 }
@@ -289,60 +291,75 @@
290292 *
291293 * @return Node -- the DOM node of the new item (an LI element) or null
292294 */
293 -function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {
294 - var root = document.getElementById(portlet);
295 - if ( !root ) return null;
296 - var node = root.getElementsByTagName( "ul" )[0];
297 - if ( !node ) return null;
 295+function addPortletLink( portlet, href, text, id, tooltip, accesskey, nextnode ) {
 296+ var root = document.getElementById( portlet );
 297+ if ( !root ) {
 298+ return null;
 299+ }
 300+ var node = root.getElementsByTagName( 'ul' )[0];
 301+ if ( !node ) {
 302+ return null;
 303+ }
298304
299305 // unhide portlet if it was hidden before
300306 root.className = root.className.replace( /(^| )emptyPortlet( |$)/, "$2" );
301307
302 - var span = document.createElement( "span" );
 308+ var span = document.createElement( 'span' );
303309 span.appendChild( document.createTextNode( text ) );
304310
305 - var link = document.createElement( "a" );
 311+ var link = document.createElement( 'a' );
306312 link.appendChild( span );
307313 link.href = href;
308314
309 - var item = document.createElement( "li" );
 315+ var item = document.createElement( 'li' );
310316 item.appendChild( link );
311 - if ( id ) item.id = id;
 317+ if ( id ) {
 318+ item.id = id;
 319+ }
312320
313321 if ( accesskey ) {
314 - link.setAttribute( "accesskey", accesskey );
315 - tooltip += " ["+accesskey+"]";
 322+ link.setAttribute( 'accesskey', accesskey );
 323+ tooltip += ' [' + accesskey + ']';
316324 }
317325 if ( tooltip ) {
318 - link.setAttribute( "title", tooltip );
 326+ link.setAttribute( 'title', tooltip );
319327 }
320328 if ( accesskey && tooltip ) {
321329 updateTooltipAccessKeys( new Array( link ) );
322330 }
323331
324 - if ( nextnode && nextnode.parentNode == node )
 332+ if ( nextnode && nextnode.parentNode == node ) {
325333 node.insertBefore( item, nextnode );
326 - else
 334+ } else {
327335 node.appendChild( item ); // IE compatibility (?)
 336+ }
328337
329338 return item;
330339 }
331340
332 -function getInnerText(el) {
333 - if (typeof el == "string") return el;
334 - if (typeof el == "undefined") { return el };
335 - if (el.textContent) return el.textContent; // not needed but it is faster
336 - if (el.innerText) return el.innerText; // IE doesn't have textContent
337 - var str = "";
 341+function getInnerText( el ) {
 342+ if ( typeof el == 'string' ) {
 343+ return el;
 344+ }
 345+ if ( typeof el == 'undefined' ) {
 346+ return el;
 347+ }
 348+ if ( el.textContent ) {
 349+ return el.textContent; // not needed but it is faster
 350+ }
 351+ if ( el.innerText ) {
 352+ return el.innerText; // IE doesn't have textContent
 353+ }
 354+ var str = '';
338355
339356 var cs = el.childNodes;
340357 var l = cs.length;
341 - for (var i = 0; i < l; i++) {
342 - switch (cs[i].nodeType) {
343 - case 1: //ELEMENT_NODE
344 - str += ts_getInnerText(cs[i]);
 358+ for ( var i = 0; i < l; i++ ) {
 359+ switch ( cs[i].nodeType ) {
 360+ case 1: // ELEMENT_NODE
 361+ str += ts_getInnerText( cs[i] );
345362 break;
346 - case 3: //TEXT_NODE
 363+ case 3: // TEXT_NODE
347364 str += cs[i].nodeValue;
348365 break;
349366 }
@@ -360,21 +377,25 @@
361378 function setupCheckboxShiftClick() {
362379 checkboxes = [];
363380 lastCheckbox = null;
364 - var inputs = document.getElementsByTagName('input');
365 - addCheckboxClickHandlers(inputs);
 381+ var inputs = document.getElementsByTagName( 'input' );
 382+ addCheckboxClickHandlers( inputs );
366383 }
367384
368 -function addCheckboxClickHandlers(inputs, start) {
369 - if ( !start) start = 0;
 385+function addCheckboxClickHandlers( inputs, start ) {
 386+ if ( !start ) {
 387+ start = 0;
 388+ }
370389
371390 var finish = start + 250;
372 - if ( finish > inputs.length )
 391+ if ( finish > inputs.length ) {
373392 finish = inputs.length;
 393+ }
374394
375395 for ( var i = start; i < finish; i++ ) {
376396 var cb = inputs[i];
377 - if ( !cb.type || cb.type.toLowerCase() != 'checkbox' )
 397+ if ( !cb.type || cb.type.toLowerCase() != 'checkbox' ) {
378398 continue;
 399+ }
379400 var end = checkboxes.length;
380401 checkboxes[end] = cb;
381402 cb.index = end;
@@ -382,14 +403,14 @@
383404 }
384405
385406 if ( finish < inputs.length ) {
386 - setTimeout( function () {
387 - addCheckboxClickHandlers(inputs, finish);
 407+ setTimeout( function() {
 408+ addCheckboxClickHandlers( inputs, finish );
388409 }, 200 );
389410 }
390411 }
391412
392 -function checkboxClickHandler(e) {
393 - if (typeof e == 'undefined') {
 413+function checkboxClickHandler( e ) {
 414+ if ( typeof e == 'undefined' ) {
394415 e = window.event;
395416 }
396417 if ( !e.shiftKey || lastCheckbox === null ) {
@@ -405,10 +426,11 @@
406427 start = lastCheckbox;
407428 finish = this.index - 1;
408429 }
409 - for (var i = start; i <= finish; ++i ) {
 430+ for ( var i = start; i <= finish; ++i ) {
410431 checkboxes[i].checked = endState;
411 - if( i > start && typeof checkboxes[i].onchange == 'function' )
 432+ if( i > start && typeof checkboxes[i].onchange == 'function' ) {
412433 checkboxes[i].onchange(); // fire triggers
 434+ }
413435 }
414436 lastCheckbox = this.index;
415437 return true;
@@ -421,68 +443,76 @@
422444 Author says "The credit comment is all it takes, no license. Go crazy with it!:-)"
423445 From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
424446 */
425 -function getElementsByClassName(oElm, strTagName, oClassNames){
 447+function getElementsByClassName( oElm, strTagName, oClassNames ) {
426448 var arrReturnElements = new Array();
427 - if ( typeof( oElm.getElementsByClassName ) == "function" ) {
 449+ if ( typeof( oElm.getElementsByClassName ) == 'function' ) {
428450 /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
429451 var arrNativeReturn = oElm.getElementsByClassName( oClassNames );
430 - if ( strTagName == "*" )
 452+ if ( strTagName == '*' ) {
431453 return arrNativeReturn;
432 - for ( var h=0; h < arrNativeReturn.length; h++ ) {
433 - if( arrNativeReturn[h].tagName.toLowerCase() == strTagName.toLowerCase() )
 454+ }
 455+ for ( var h = 0; h < arrNativeReturn.length; h++ ) {
 456+ if( arrNativeReturn[h].tagName.toLowerCase() == strTagName.toLowerCase() ) {
434457 arrReturnElements[arrReturnElements.length] = arrNativeReturn[h];
 458+ }
435459 }
436460 return arrReturnElements;
437461 }
438 - var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
 462+ var arrElements = ( strTagName == '*' && oElm.all ) ? oElm.all : oElm.getElementsByTagName( strTagName );
439463 var arrRegExpClassNames = new Array();
440 - if(typeof oClassNames == "object"){
441 - for(var i=0; i<oClassNames.length; i++){
 464+ if( typeof oClassNames == 'object' ) {
 465+ for( var i = 0; i < oClassNames.length; i++ ) {
442466 arrRegExpClassNames[arrRegExpClassNames.length] =
443467 new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)");
444468 }
445 - }
446 - else{
 469+ } else {
447470 arrRegExpClassNames[arrRegExpClassNames.length] =
448471 new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)");
449472 }
450473 var oElement;
451474 var bMatchesAll;
452 - for(var j=0; j<arrElements.length; j++){
 475+ for( var j = 0; j < arrElements.length; j++ ) {
453476 oElement = arrElements[j];
454477 bMatchesAll = true;
455 - for(var k=0; k<arrRegExpClassNames.length; k++){
456 - if(!arrRegExpClassNames[k].test(oElement.className)){
 478+ for( var k = 0; k < arrRegExpClassNames.length; k++ ) {
 479+ if( !arrRegExpClassNames[k].test( oElement.className ) ) {
457480 bMatchesAll = false;
458481 break;
459482 }
460483 }
461 - if(bMatchesAll){
 484+ if( bMatchesAll ) {
462485 arrReturnElements[arrReturnElements.length] = oElement;
463486 }
464487 }
465 - return (arrReturnElements)
 488+ return ( arrReturnElements );
466489 }
467490
468 -function redirectToFragment(fragment) {
 491+function redirectToFragment( fragment ) {
469492 var match = navigator.userAgent.match(/AppleWebKit\/(\d+)/);
470 - if (match) {
471 - var webKitVersion = parseInt(match[1]);
472 - if (webKitVersion < 420) {
 493+ if ( match ) {
 494+ var webKitVersion = parseInt( match[1] );
 495+ if ( webKitVersion < 420 ) {
473496 // Released Safari w/ WebKit 418.9.1 messes up horribly
474497 // Nightlies of 420+ are ok
475498 return;
476499 }
477500 }
478 - if (is_gecko) {
479 - // Mozilla needs to wait until after load, otherwise the window doesn't scroll
480 - addOnloadHook(function () {
481 - if (window.location.hash == "")
482 - window.location.hash = fragment;
483 - });
484 - } else {
485 - if (window.location.hash == "")
486 - window.location.hash = fragment;
 501+ if ( window.location.hash == '' ) {
 502+ window.location.hash = fragment;
 503+
 504+ // Mozilla needs to wait until after load, otherwise the window doesn't
 505+ // scroll. See <https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
 506+ // There's no obvious way to detect this programmatically, so we use
 507+ // version-testing. If Firefox fixes the bug, they'll jump twice, but
 508+ // better twice than not at all, so make the fix hit future versions as
 509+ // well.
 510+ if ( is_gecko ) {
 511+ addOnloadHook(function() {
 512+ if ( window.location.hash == fragment ) {
 513+ window.location.hash = fragment;
 514+ }
 515+ });
 516+ }
487517 }
488518 }
489519
@@ -497,11 +527,11 @@
498528 * @todo support all accepted date formats (bug 8226)
499529 */
500530
501 -var ts_image_path = stylepath+"/common/images/";
502 -var ts_image_up = "sort_up.gif";
503 -var ts_image_down = "sort_down.gif";
504 -var ts_image_none = "sort_none.gif";
505 -var ts_europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"
 531+var ts_image_path = stylepath + '/common/images/';
 532+var ts_image_up = 'sort_up.gif';
 533+var ts_image_down = 'sort_down.gif';
 534+var ts_image_none = 'sort_none.gif';
 535+var ts_europeandate = wgContentLanguage != 'en'; // The non-American-inclined can change to "true"
506536 var ts_alternate_row_colors = false;
507537 var ts_number_transform_table = null;
508538 var ts_number_regex = null;
@@ -509,31 +539,33 @@
510540 function sortables_init() {
511541 var idnum = 0;
512542 // Find all tables with class sortable and make them sortable
513 - var tables = getElementsByClassName(document, "table", "sortable");
514 - for (var ti = 0; ti < tables.length ; ti++) {
515 - if (!tables[ti].id) {
516 - tables[ti].setAttribute('id','sortable_table_id_'+idnum);
 543+ var tables = getElementsByClassName( document, 'table', 'sortable' );
 544+ for ( var ti = 0; ti < tables.length ; ti++ ) {
 545+ if ( !tables[ti].id ) {
 546+ tables[ti].setAttribute( 'id', 'sortable_table_id_' + idnum );
517547 ++idnum;
518548 }
519 - ts_makeSortable(tables[ti]);
 549+ ts_makeSortable( tables[ti] );
520550 }
521551 }
522552
523 -function ts_makeSortable(table) {
 553+function ts_makeSortable( table ) {
524554 var firstRow;
525 - if (table.rows && table.rows.length > 0) {
526 - if (table.tHead && table.tHead.rows.length > 0) {
 555+ if ( table.rows && table.rows.length > 0 ) {
 556+ if ( table.tHead && table.tHead.rows.length > 0 ) {
527557 firstRow = table.tHead.rows[table.tHead.rows.length-1];
528558 } else {
529559 firstRow = table.rows[0];
530560 }
531561 }
532 - if (!firstRow) return;
 562+ if ( !firstRow ) {
 563+ return;
 564+ }
533565
534566 // We have a first row: assume it's the header, and make its contents clickable links
535 - for (var i = 0; i < firstRow.cells.length; i++) {
 567+ for ( var i = 0; i < firstRow.cells.length; i++ ) {
536568 var cell = firstRow.cells[i];
537 - if ((" "+cell.className+" ").indexOf(" unsortable ") == -1) {
 569+ if ( (' ' + cell.className + ' ').indexOf(' unsortable ') == -1 ) {
538570 cell.innerHTML += '<a href="#" class="sortheader" '
539571 + 'onclick="ts_resortTable(this);return false;">'
540572 + '<span class="sortarrow">'
@@ -543,16 +575,16 @@
544576 + '" alt="&darr;"/></span></a>';
545577 }
546578 }
547 - if (ts_alternate_row_colors) {
548 - ts_alternate(table);
 579+ if ( ts_alternate_row_colors ) {
 580+ ts_alternate( table );
549581 }
550582 }
551583
552 -function ts_getInnerText(el) {
 584+function ts_getInnerText( el ) {
553585 return getInnerText( el );
554586 }
555587
556 -function ts_resortTable(lnk) {
 588+function ts_resortTable( lnk ) {
557589 // get the span
558590 var span = lnk.getElementsByTagName('span')[0];
559591
@@ -561,107 +593,118 @@
562594 var column = td.cellIndex;
563595
564596 var table = tr.parentNode;
565 - while (table && !(table.tagName && table.tagName.toLowerCase() == 'table'))
 597+ while ( table && !( table.tagName && table.tagName.toLowerCase() == 'table' ) ) {
566598 table = table.parentNode;
567 - if (!table) return;
 599+ }
 600+ if ( !table ) {
 601+ return;
 602+ }
568603
569 - if (table.rows.length <= 1) return;
 604+ if ( table.rows.length <= 1 ) {
 605+ return;
 606+ }
570607
571608 // Generate the number transform table if it's not done already
572 - if (ts_number_transform_table == null) {
 609+ if ( ts_number_transform_table === null ) {
573610 ts_initTransformTable();
574611 }
575612
576613 // Work out a type for the column
577614 // Skip the first row if that's where the headings are
578 - var rowStart = (table.tHead && table.tHead.rows.length > 0 ? 0 : 1);
 615+ var rowStart = ( table.tHead && table.tHead.rows.length > 0 ? 0 : 1 );
579616
580 - var itm = "";
581 - for (var i = rowStart; i < table.rows.length; i++) {
582 - if (table.rows[i].cells.length > column) {
 617+ var itm = '';
 618+ for ( var i = rowStart; i < table.rows.length; i++ ) {
 619+ if ( table.rows[i].cells.length > column ) {
583620 itm = ts_getInnerText(table.rows[i].cells[column]);
584 - itm = itm.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "");
585 - if (itm != "") break;
 621+ itm = itm.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '');
 622+ if ( itm != '' ) {
 623+ break;
 624+ }
586625 }
587626 }
588627
589628 // TODO: bug 8226, localised date formats
590629 var sortfn = ts_sort_generic;
591630 var preprocessor = ts_toLowerCase;
592 - if (/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/.test(itm)) {
 631+ if ( /^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/.test( itm ) ) {
593632 preprocessor = ts_dateToSortKey;
594 - } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/.test(itm)) {
 633+ } else if ( /^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/.test( itm ) ) {
595634 preprocessor = ts_dateToSortKey;
596 - } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d$/.test(itm)) {
 635+ } else if ( /^\d\d[\/.-]\d\d[\/.-]\d\d$/.test( itm ) ) {
597636 preprocessor = ts_dateToSortKey;
598 - // pound dollar euro yen currency cents
599 - } else if (/(^[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test(itm)) {
 637+ // (minus sign)([pound dollar euro yen currency]|cents)
 638+ } else if ( /(^([-\u2212] *)?[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test( itm ) ) {
600639 preprocessor = ts_currencyToSortKey;
601 - } else if (ts_number_regex.test(itm)) {
 640+ } else if ( ts_number_regex.test( itm ) ) {
602641 preprocessor = ts_parseFloat;
603642 }
604643
605 - var reverse = (span.getAttribute("sortdir") == 'down');
 644+ var reverse = ( span.getAttribute( 'sortdir' ) == 'down' );
606645
607646 var newRows = new Array();
608647 var staticRows = new Array();
609 - for (var j = rowStart; j < table.rows.length; j++) {
 648+ for ( var j = rowStart; j < table.rows.length; j++ ) {
610649 var row = table.rows[j];
611 - if((" "+row.className+" ").indexOf(" unsortable ") < 0) {
612 - var keyText = ts_getInnerText(row.cells[column]);
613 - if(keyText == undefined) {
614 - keyText = "";
 650+ if( (' ' + row.className + ' ').indexOf(' unsortable ') < 0 ) {
 651+ var keyText = ts_getInnerText( row.cells[column] );
 652+ if( keyText === undefined ) {
 653+ keyText = '';
615654 }
616 - var oldIndex = (reverse ? -j : j);
617 - var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "") );
 655+ var oldIndex = ( reverse ? -j : j );
 656+ var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '') );
618657
619 - newRows[newRows.length] = new Array(row, preprocessed, oldIndex);
620 - } else staticRows[staticRows.length] = new Array(row, false, j-rowStart);
 658+ newRows[newRows.length] = new Array( row, preprocessed, oldIndex );
 659+ } else {
 660+ staticRows[staticRows.length] = new Array( row, false, j-rowStart );
 661+ }
621662 }
622663
623 - newRows.sort(sortfn);
 664+ newRows.sort( sortfn );
624665
625666 var arrowHTML;
626 - if (reverse) {
627 - arrowHTML = '<img src="'+ ts_image_path + ts_image_down + '" alt="&darr;"/>';
 667+ if ( reverse ) {
 668+ arrowHTML = '<img src="' + ts_image_path + ts_image_down + '" alt="&darr;"/>';
628669 newRows.reverse();
629 - span.setAttribute('sortdir','up');
 670+ span.setAttribute( 'sortdir', 'up' );
630671 } else {
631 - arrowHTML = '<img src="'+ ts_image_path + ts_image_up + '" alt="&uarr;"/>';
632 - span.setAttribute('sortdir','down');
 672+ arrowHTML = '<img src="' + ts_image_path + ts_image_up + '" alt="&uarr;"/>';
 673+ span.setAttribute( 'sortdir', 'down' );
633674 }
634675
635 - for (var i = 0; i < staticRows.length; i++) {
 676+ for ( var i = 0; i < staticRows.length; i++ ) {
636677 var row = staticRows[i];
637 - newRows.splice(row[2], 0, row);
 678+ newRows.splice( row[2], 0, row );
638679 }
639680
640681 // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones
641682 // don't do sortbottom rows
642 - for (var i = 0; i < newRows.length; i++) {
643 - if ((" "+newRows[i][0].className+" ").indexOf(" sortbottom ") == -1)
644 - table.tBodies[0].appendChild(newRows[i][0]);
 683+ for ( var i = 0; i < newRows.length; i++ ) {
 684+ if ( ( ' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') == -1 ) {
 685+ table.tBodies[0].appendChild( newRows[i][0] );
 686+ }
645687 }
646688 // do sortbottom rows only
647 - for (var i = 0; i < newRows.length; i++) {
648 - if ((" "+newRows[i][0].className+" ").indexOf(" sortbottom ") != -1)
649 - table.tBodies[0].appendChild(newRows[i][0]);
 689+ for ( var i = 0; i < newRows.length; i++ ) {
 690+ if ( ( ' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') != -1 ) {
 691+ table.tBodies[0].appendChild( newRows[i][0] );
 692+ }
650693 }
651694
652695 // Delete any other arrows there may be showing
653 - var spans = getElementsByClassName(tr, "span", "sortarrow");
654 - for (var i = 0; i < spans.length; i++) {
655 - spans[i].innerHTML = '<img src="'+ ts_image_path + ts_image_none + '" alt="&darr;"/>';
 696+ var spans = getElementsByClassName( tr, 'span', 'sortarrow' );
 697+ for ( var i = 0; i < spans.length; i++ ) {
 698+ spans[i].innerHTML = '<img src="' + ts_image_path + ts_image_none + '" alt="&darr;"/>';
656699 }
657700 span.innerHTML = arrowHTML;
658701
659 - if (ts_alternate_row_colors) {
660 - ts_alternate(table);
 702+ if ( ts_alternate_row_colors ) {
 703+ ts_alternate( table );
661704 }
662705 }
663706
664707 function ts_initTransformTable() {
665 - if ( typeof wgSeparatorTransformTable == "undefined"
 708+ if ( typeof wgSeparatorTransformTable == 'undefined'
666709 || ( wgSeparatorTransformTable[0] == '' && wgDigitTransformTable[2] == '' ) )
667710 {
668711 digitClass = "[0-9,.]";
@@ -691,7 +734,7 @@
692735 digit.replace( /[\\\\$\*\+\?\.\(\)\|\{\}\[\]\-]/,
693736 function( s ) { return '\\' + s; } )
694737 );
695 - if (digit.length > maxDigitLength) {
 738+ if ( digit.length > maxDigitLength ) {
696739 maxDigitLength = digit.length;
697740 }
698741 }
@@ -706,9 +749,9 @@
707750 // if percents and regular numbers aren't being mixed.
708751 ts_number_regex = new RegExp(
709752 "^(" +
710 - "[+-]?[0-9][0-9,]*(\\.[0-9,]*)?(E[+-]?[0-9][0-9,]*)?" + // Fortran-style scientific
 753+ "[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
711754 "|" +
712 - "[+-]?" + digitClass + "+%?" + // Generic localised
 755+ "[-+\u2212]?" + digitClass + "+%?" + // Generic localised
713756 ")$", "i"
714757 );
715758 }
@@ -717,57 +760,81 @@
718761 return s.toLowerCase();
719762 }
720763
721 -function ts_dateToSortKey(date) {
 764+function ts_dateToSortKey( date ) {
722765 // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX
723 - if (date.length == 11) {
724 - switch (date.substr(3,3).toLowerCase()) {
725 - case "jan": var month = "01"; break;
726 - case "feb": var month = "02"; break;
727 - case "mar": var month = "03"; break;
728 - case "apr": var month = "04"; break;
729 - case "may": var month = "05"; break;
730 - case "jun": var month = "06"; break;
731 - case "jul": var month = "07"; break;
732 - case "aug": var month = "08"; break;
733 - case "sep": var month = "09"; break;
734 - case "oct": var month = "10"; break;
735 - case "nov": var month = "11"; break;
736 - case "dec": var month = "12"; break;
737 - // default: var month = "00";
 766+ if ( date.length == 11 ) {
 767+ switch ( date.substr( 3, 3 ).toLowerCase() ) {
 768+ case 'jan':
 769+ var month = '01';
 770+ break;
 771+ case 'feb':
 772+ var month = '02';
 773+ break;
 774+ case 'mar':
 775+ var month = '03';
 776+ break;
 777+ case 'apr':
 778+ var month = '04';
 779+ break;
 780+ case 'may':
 781+ var month = '05';
 782+ break;
 783+ case 'jun':
 784+ var month = '06';
 785+ break;
 786+ case 'jul':
 787+ var month = '07';
 788+ break;
 789+ case 'aug':
 790+ var month = '08';
 791+ break;
 792+ case 'sep':
 793+ var month = '09';
 794+ break;
 795+ case 'oct':
 796+ var month = '10';
 797+ break;
 798+ case 'nov':
 799+ var month = '11';
 800+ break;
 801+ case 'dec':
 802+ var month = '12';
 803+ break;
 804+ // default: var month = '00';
738805 }
739 - return date.substr(7,4)+month+date.substr(0,2);
740 - } else if (date.length == 10) {
741 - if (ts_europeandate == false) {
742 - return date.substr(6,4)+date.substr(0,2)+date.substr(3,2);
 806+ return date.substr( 7, 4 ) + month + date.substr( 0, 2 );
 807+ } else if ( date.length == 10 ) {
 808+ if ( ts_europeandate == false ) {
 809+ return date.substr( 6, 4 ) + date.substr( 0, 2 ) + date.substr( 3, 2 );
743810 } else {
744 - return date.substr(6,4)+date.substr(3,2)+date.substr(0,2);
 811+ return date.substr( 6, 4 ) + date.substr( 3, 2 ) + date.substr( 0, 2 );
745812 }
746 - } else if (date.length == 8) {
747 - yr = date.substr(6,2);
748 - if (parseInt(yr) < 50) {
749 - yr = '20'+yr;
 813+ } else if ( date.length == 8 ) {
 814+ yr = date.substr( 6, 2 );
 815+ if ( parseInt( yr ) < 50 ) {
 816+ yr = '20' + yr;
750817 } else {
751 - yr = '19'+yr;
 818+ yr = '19' + yr;
752819 }
753 - if (ts_europeandate == true) {
754 - return yr+date.substr(3,2)+date.substr(0,2);
 820+ if ( ts_europeandate == true ) {
 821+ return yr + date.substr( 3, 2 ) + date.substr( 0, 2 );
755822 } else {
756 - return yr+date.substr(0,2)+date.substr(3,2);
 823+ return yr + date.substr( 0, 2 ) + date.substr( 3, 2 );
757824 }
758825 }
759 - return "00000000";
 826+ return '00000000';
760827 }
761828
762829 function ts_parseFloat( s ) {
763830 if ( !s ) {
764831 return 0;
765832 }
766 - if (ts_number_transform_table != false) {
 833+ if ( ts_number_transform_table != false ) {
767834 var newNum = '', c;
768835
769836 for ( var p = 0; p < s.length; p++ ) {
770837 c = s.charAt( p );
771 - if (c in ts_number_transform_table) {
 838+ if ( c in ts_number_transform_table ) {
772839 newNum += ts_number_transform_table[c];
773840 } else {
774841 newNum += c;
@@ -775,37 +842,37 @@
776843 }
777844 s = newNum;
778845 }
779 -
780 - num = parseFloat(s.replace(/,/g, ""));
781 - return (isNaN(num) ? 0 : num);
 846+ num = parseFloat( s.replace(/[, ]/g, '').replace("\u2212", '-') );
 847+ return ( isNaN( num ) ? -Infinity : num );
782848 }
783849
784850 function ts_currencyToSortKey( s ) {
785 - return ts_parseFloat(s.replace(/[^0-9.,]/g,''));
 851+ return ts_parseFloat(s.replace(/[^-\u22120-9.,]/g,''));
786852 }
787853
788 -function ts_sort_generic(a, b) {
 854+function ts_sort_generic( a, b ) {
789855 return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : a[2] - b[2];
790856 }
791857
792 -function ts_alternate(table) {
 858+function ts_alternate( table ) {
793859 // Take object table and get all it's tbodies.
794 - var tableBodies = table.getElementsByTagName("tbody");
 860+ var tableBodies = table.getElementsByTagName( 'tbody' );
795861 // Loop through these tbodies
796 - for (var i = 0; i < tableBodies.length; i++) {
 862+ for ( var i = 0; i < tableBodies.length; i++ ) {
797863 // Take the tbody, and get all it's rows
798 - var tableRows = tableBodies[i].getElementsByTagName("tr");
 864+ var tableRows = tableBodies[i].getElementsByTagName( 'tr' );
799865 // Loop through these rows
800866 // Start at 1 because we want to leave the heading row untouched
801 - for (var j = 0; j < tableRows.length; j++) {
 867+ for ( var j = 0; j < tableRows.length; j++ ) {
802868 // Check if j is even, and apply classes for both possible results
803 - var oldClasses = tableRows[j].className.split(" ");
804 - var newClassName = "";
805 - for (var k = 0; k < oldClasses.length; k++) {
806 - if (oldClasses[k] != "" && oldClasses[k] != "even" && oldClasses[k] != "odd")
807 - newClassName += oldClasses[k] + " ";
 869+ var oldClasses = tableRows[j].className.split(' ');
 870+ var newClassName = '';
 871+ for ( var k = 0; k < oldClasses.length; k++ ) {
 872+ if ( oldClasses[k] != '' && oldClasses[k] != 'even' && oldClasses[k] != 'odd' ) {
 873+ newClassName += oldClasses[k] + ' ';
 874+ }
808875 }
809 - tableRows[j].className = newClassName + (j % 2 == 0 ? "even" : "odd");
 876+ tableRows[j].className = newClassName + ( j % 2 == 0 ? 'even' : 'odd' );
810877 }
811878 }
812879 }
@@ -841,7 +908,7 @@
842909 messageDiv,
843910 document.getElementById( 'content' ).firstChild
844911 );
845 - } else if ( document.getElementById('content')
 912+ } else if ( document.getElementById( 'content' )
846913 && document.getElementById( 'article' ) ) {
847914 // Non-Monobook but still recognizable (old-style)
848915 document.getElementById( 'article').insertBefore(
@@ -856,15 +923,15 @@
857924 messageDiv.setAttribute( 'id', 'mw-js-message' );
858925 messageDiv.style.display = 'block';
859926 if( className ) {
860 - messageDiv.setAttribute( 'class', 'mw-js-message-'+className );
 927+ messageDiv.setAttribute( 'class', 'mw-js-message-' + className );
861928 }
862929
863 - if (typeof message === 'object') {
864 - while (messageDiv.hasChildNodes()) // Remove old content
865 - messageDiv.removeChild(messageDiv.firstChild);
866 - messageDiv.appendChild (message); // Append new content
867 - }
868 - else {
 930+ if ( typeof message === 'object' ) {
 931+ while ( messageDiv.hasChildNodes() ) { // Remove old content
 932+ messageDiv.removeChild( messageDiv.firstChild );
 933+ }
 934+ messageDiv.appendChild( message ); // Append new content
 935+ } else {
869936 messageDiv.innerHTML = message;
870937 }
871938 return true;
@@ -877,10 +944,10 @@
878945 * @param id Identifier string (for use with removeSpinner(), below)
879946 */
880947 function injectSpinner( element, id ) {
881 - var spinner = document.createElement( "img" );
882 - spinner.id = "mw-spinner-" + id;
883 - spinner.src = stylepath + "/common/images/spinner.gif";
884 - spinner.alt = spinner.title = "...";
 948+ var spinner = document.createElement( 'img' );
 949+ spinner.id = 'mw-spinner-' + id;
 950+ spinner.src = stylepath + '/common/images/spinner.gif';
 951+ spinner.alt = spinner.title = '...';
885952 if( element.nextSibling ) {
886953 element.parentNode.insertBefore( spinner, element.nextSibling );
887954 } else {
@@ -894,7 +961,7 @@
895962 * @param id Identifier string
896963 */
897964 function removeSpinner( id ) {
898 - var spinner = document.getElementById( "mw-spinner-" + id );
 965+ var spinner = document.getElementById( 'mw-spinner-' + id );
899966 if( spinner ) {
900967 spinner.parentNode.removeChild( spinner );
901968 }
@@ -902,7 +969,7 @@
903970
904971 function runOnloadHook() {
905972 // don't run anything below this for non-dom browsers
906 - if (doneOnloadHook || !(document.getElementById && document.getElementsByTagName)) {
 973+ if ( doneOnloadHook || !( document.getElementById && document.getElementsByTagName ) ) {
907974 return;
908975 }
909976
@@ -915,7 +982,7 @@
916983 sortables_init();
917984
918985 // Run any added-on functions
919 - for (var i = 0; i < onloadFuncts.length; i++) {
 986+ for ( var i = 0; i < onloadFuncts.length; i++ ) {
920987 onloadFuncts[i]();
921988 }
922989 }
@@ -959,6 +1026,17 @@
9601027 element.detachEvent( 'on' + remove, handler );
9611028 }
9621029 }
963 -//note: all skins should call runOnloadHook() at the end of html output,
 1030+// note: all skins should call runOnloadHook() at the end of html output,
9641031 // so the below should be redundant. It's there just in case.
965 -hookEvent("load", runOnloadHook);
 1032+hookEvent( 'load', runOnloadHook );
 1033+
 1034+if ( ie6_bugs ) {
 1035+ importScriptURI( stylepath + '/common/IEFixes.js' );
 1036+}
 1037+
 1038+// For future use.
 1039+if ( typeof mw == 'undefined' ) {
 1040+ mw = {};
 1041+}
 1042+
 1043+

Status & tagging log