Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -1,3 +1,5 @@ |
| 2 | +/*jslint browser: true, continue: true, white: true, forin: true*/ |
| 3 | +/*global jQuery*/ |
2 | 4 | /* |
3 | 5 | * Core MediaWiki JavaScript Library |
4 | 6 | */ |
— | — | @@ -3,5 +5,5 @@ |
4 | 6 | |
5 | 7 | var mw = ( function ( $, undefined ) { |
6 | | -"use strict"; |
| 8 | + "use strict"; |
7 | 9 | |
8 | 10 | /* Private Members */ |
— | — | @@ -49,7 +51,9 @@ |
50 | 52 | results[selection[i]] = this.get( selection[i], fallback ); |
51 | 53 | } |
52 | 54 | return results; |
53 | | - } else if ( typeof selection === 'string' ) { |
| 55 | + } |
| 56 | + |
| 57 | + if ( typeof selection === 'string' ) { |
54 | 58 | if ( this.values[selection] === undefined ) { |
55 | 59 | if ( fallback !== undefined ) { |
56 | 60 | return fallback; |
— | — | @@ -58,11 +62,13 @@ |
59 | 63 | } |
60 | 64 | return this.values[selection]; |
61 | 65 | } |
| 66 | + |
62 | 67 | if ( selection === undefined ) { |
63 | 68 | return this.values; |
64 | | - } else { |
65 | | - return null; // invalid selection key |
66 | 69 | } |
| 70 | + |
| 71 | + // invalid selection key |
| 72 | + return null; |
67 | 73 | }, |
68 | 74 | |
69 | 75 | /** |
— | — | @@ -80,7 +86,8 @@ |
81 | 87 | this.values[s] = selection[s]; |
82 | 88 | } |
83 | 89 | return true; |
84 | | - } else if ( typeof selection === 'string' && value !== undefined ) { |
| 90 | + } |
| 91 | + if ( typeof selection === 'string' && value !== undefined ) { |
85 | 92 | this.values[selection] = value; |
86 | 93 | return true; |
87 | 94 | } |
— | — | @@ -103,9 +110,8 @@ |
104 | 111 | } |
105 | 112 | } |
106 | 113 | return true; |
107 | | - } else { |
108 | | - return this.values[selection] !== undefined; |
109 | 114 | } |
| 115 | + return this.values[selection] !== undefined; |
110 | 116 | } |
111 | 117 | }; |
112 | 118 | |
— | — | @@ -308,7 +314,7 @@ |
309 | 315 | * each a parameter for $N replacement in messages. |
310 | 316 | * @return String. |
311 | 317 | */ |
312 | | - msg: function ( key, parameters ) { |
| 318 | + msg: function ( /* key, parameter_1, parameter_2, .. */ ) { |
313 | 319 | return mw.message.apply( mw.message, arguments ).toString(); |
314 | 320 | }, |
315 | 321 | |
— | — | @@ -379,15 +385,16 @@ |
380 | 386 | // Cached ? |
381 | 387 | if ( $marker ) { |
382 | 388 | return $marker; |
383 | | - } else { |
384 | | - $marker = $( 'meta[name="ResourceLoaderDynamicStyles"]' ); |
385 | | - if ( $marker.length ) { |
386 | | - return $marker; |
387 | | - } |
388 | | - mw.log( 'getMarker> No <meta name="ResourceLoaderDynamicStyles"> found, inserting dynamically.' ); |
389 | | - $marker = $( '<meta>' ).attr( 'name', 'ResourceLoaderDynamicStyles' ).appendTo( 'head' ); |
| 389 | + } |
| 390 | + |
| 391 | + $marker = $( 'meta[name="ResourceLoaderDynamicStyles"]' ); |
| 392 | + if ( $marker.length ) { |
390 | 393 | return $marker; |
391 | 394 | } |
| 395 | + mw.log( 'getMarker> No <meta name="ResourceLoaderDynamicStyles"> found, inserting dynamically.' ); |
| 396 | + $marker = $( '<meta>' ).attr( 'name', 'ResourceLoaderDynamicStyles' ).appendTo( 'head' ); |
| 397 | + |
| 398 | + return $marker; |
392 | 399 | } |
393 | 400 | |
394 | 401 | /** |
— | — | @@ -531,11 +538,14 @@ |
532 | 539 | } |
533 | 540 | } |
534 | 541 | return modules; |
535 | | - } else if ( typeof module === 'string' ) { |
| 542 | + } |
| 543 | + |
| 544 | + if ( typeof module === 'string' ) { |
536 | 545 | resolved = []; |
537 | 546 | recurse( module, resolved, [] ); |
538 | 547 | return resolved; |
539 | 548 | } |
| 549 | + |
540 | 550 | throw new Error( 'Invalid module argument: ' + module ); |
541 | 551 | } |
542 | 552 | |
— | — | @@ -816,8 +826,9 @@ |
817 | 827 | } |
818 | 828 | } |
819 | 829 | } |
| 830 | + |
820 | 831 | // Add ready and error callbacks if they were given |
821 | | - if ( arguments.length > 1 ) { |
| 832 | + if ( ready !== undefined || error !== undefined ) { |
822 | 833 | jobs[jobs.length] = { |
823 | 834 | 'dependencies': filter( |
824 | 835 | ['registered', 'loading', 'loaded'], |
— | — | @@ -827,6 +838,7 @@ |
828 | 839 | 'error': error |
829 | 840 | }; |
830 | 841 | } |
| 842 | + |
831 | 843 | // Queue up any dependencies that are registered |
832 | 844 | dependencies = filter( ['registered'], dependencies ); |
833 | 845 | for ( n = 0; n < dependencies.length; n += 1 ) { |
— | — | @@ -838,6 +850,7 @@ |
839 | 851 | } |
840 | 852 | } |
841 | 853 | } |
| 854 | + |
842 | 855 | // Work the queue |
843 | 856 | mw.loader.work(); |
844 | 857 | } |
— | — | @@ -1231,7 +1244,8 @@ |
1232 | 1245 | href: modules |
1233 | 1246 | } ) ); |
1234 | 1247 | return; |
1235 | | - } else if ( type === 'text/javascript' || type === undefined ) { |
| 1248 | + } |
| 1249 | + if ( type === 'text/javascript' || type === undefined ) { |
1236 | 1250 | addScript( modules, null, async ); |
1237 | 1251 | return; |
1238 | 1252 | } |
— | — | @@ -1260,14 +1274,12 @@ |
1261 | 1275 | return; |
1262 | 1276 | } |
1263 | 1277 | // If any modules have errors |
1264 | | - else if ( filter( ['error'], filtered ).length ) { |
| 1278 | + if ( filter( ['error'], filtered ).length ) { |
1265 | 1279 | return; |
1266 | 1280 | } |
1267 | 1281 | // Since some modules are not yet ready, queue up a request |
1268 | | - else { |
1269 | | - request( filtered, null, null, async ); |
1270 | | - return; |
1271 | | - } |
| 1282 | + request( filtered, null, null, async ); |
| 1283 | + return; |
1272 | 1284 | }, |
1273 | 1285 | |
1274 | 1286 | /** |
— | — | @@ -1460,7 +1472,7 @@ |
1461 | 1473 | } |
1462 | 1474 | }; |
1463 | 1475 | |
1464 | | -})( jQuery ); |
| 1476 | +}( jQuery ) ); |
1465 | 1477 | |
1466 | 1478 | // Alias $j to jQuery for backwards compatibility |
1467 | 1479 | window.$j = jQuery; |
— | — | @@ -1469,7 +1481,7 @@ |
1470 | 1482 | window.mw = window.mediaWiki = mw; |
1471 | 1483 | |
1472 | 1484 | // Auto-register from pre-loaded startup scripts |
1473 | | -if ( typeof startUp !== 'undefined' && jQuery.isFunction( startUp ) ) { |
1474 | | - startUp(); |
1475 | | - startUp = undefined; |
| 1485 | +if ( jQuery.isFunction( window.startUp ) ) { |
| 1486 | + window.startUp(); |
| 1487 | + window.startUp = undefined; |
1476 | 1488 | } |