r112665 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112664‎ | r112665 | r112666 >
Date:01:52, 29 February 2012
Author:krinkle
Status:ok
Tags:
Comment:
[mediawiki.js] minor improvements based on recently added features to JSLint

* Fix with help of JSLint:
-- else statement after a return at the end of a connected if statement
* Using arguments.length incorrectly
* Added JSLint settings to the file
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -1,3 +1,5 @@
 2+/*jslint browser: true, continue: true, white: true, forin: true*/
 3+/*global jQuery*/
24 /*
35 * Core MediaWiki JavaScript Library
46 */
@@ -3,5 +5,5 @@
46
57 var mw = ( function ( $, undefined ) {
6 -"use strict";
 8+ "use strict";
79
810 /* Private Members */
@@ -49,7 +51,9 @@
5052 results[selection[i]] = this.get( selection[i], fallback );
5153 }
5254 return results;
53 - } else if ( typeof selection === 'string' ) {
 55+ }
 56+
 57+ if ( typeof selection === 'string' ) {
5458 if ( this.values[selection] === undefined ) {
5559 if ( fallback !== undefined ) {
5660 return fallback;
@@ -58,11 +62,13 @@
5963 }
6064 return this.values[selection];
6165 }
 66+
6267 if ( selection === undefined ) {
6368 return this.values;
64 - } else {
65 - return null; // invalid selection key
6669 }
 70+
 71+ // invalid selection key
 72+ return null;
6773 },
6874
6975 /**
@@ -80,7 +86,8 @@
8187 this.values[s] = selection[s];
8288 }
8389 return true;
84 - } else if ( typeof selection === 'string' && value !== undefined ) {
 90+ }
 91+ if ( typeof selection === 'string' && value !== undefined ) {
8592 this.values[selection] = value;
8693 return true;
8794 }
@@ -103,9 +110,8 @@
104111 }
105112 }
106113 return true;
107 - } else {
108 - return this.values[selection] !== undefined;
109114 }
 115+ return this.values[selection] !== undefined;
110116 }
111117 };
112118
@@ -308,7 +314,7 @@
309315 * each a parameter for $N replacement in messages.
310316 * @return String.
311317 */
312 - msg: function ( key, parameters ) {
 318+ msg: function ( /* key, parameter_1, parameter_2, .. */ ) {
313319 return mw.message.apply( mw.message, arguments ).toString();
314320 },
315321
@@ -379,15 +385,16 @@
380386 // Cached ?
381387 if ( $marker ) {
382388 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 ) {
390393 return $marker;
391394 }
 395+ mw.log( 'getMarker> No <meta name="ResourceLoaderDynamicStyles"> found, inserting dynamically.' );
 396+ $marker = $( '<meta>' ).attr( 'name', 'ResourceLoaderDynamicStyles' ).appendTo( 'head' );
 397+
 398+ return $marker;
392399 }
393400
394401 /**
@@ -531,11 +538,14 @@
532539 }
533540 }
534541 return modules;
535 - } else if ( typeof module === 'string' ) {
 542+ }
 543+
 544+ if ( typeof module === 'string' ) {
536545 resolved = [];
537546 recurse( module, resolved, [] );
538547 return resolved;
539548 }
 549+
540550 throw new Error( 'Invalid module argument: ' + module );
541551 }
542552
@@ -816,8 +826,9 @@
817827 }
818828 }
819829 }
 830+
820831 // Add ready and error callbacks if they were given
821 - if ( arguments.length > 1 ) {
 832+ if ( ready !== undefined || error !== undefined ) {
822833 jobs[jobs.length] = {
823834 'dependencies': filter(
824835 ['registered', 'loading', 'loaded'],
@@ -827,6 +838,7 @@
828839 'error': error
829840 };
830841 }
 842+
831843 // Queue up any dependencies that are registered
832844 dependencies = filter( ['registered'], dependencies );
833845 for ( n = 0; n < dependencies.length; n += 1 ) {
@@ -838,6 +850,7 @@
839851 }
840852 }
841853 }
 854+
842855 // Work the queue
843856 mw.loader.work();
844857 }
@@ -1231,7 +1244,8 @@
12321245 href: modules
12331246 } ) );
12341247 return;
1235 - } else if ( type === 'text/javascript' || type === undefined ) {
 1248+ }
 1249+ if ( type === 'text/javascript' || type === undefined ) {
12361250 addScript( modules, null, async );
12371251 return;
12381252 }
@@ -1260,14 +1274,12 @@
12611275 return;
12621276 }
12631277 // If any modules have errors
1264 - else if ( filter( ['error'], filtered ).length ) {
 1278+ if ( filter( ['error'], filtered ).length ) {
12651279 return;
12661280 }
12671281 // 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;
12721284 },
12731285
12741286 /**
@@ -1460,7 +1472,7 @@
14611473 }
14621474 };
14631475
1464 -})( jQuery );
 1476+}( jQuery ) );
14651477
14661478 // Alias $j to jQuery for backwards compatibility
14671479 window.$j = jQuery;
@@ -1469,7 +1481,7 @@
14701482 window.mw = window.mediaWiki = mw;
14711483
14721484 // 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;
14761488 }

Sign-offs

UserFlagDate
Santhosh.thottingalinspected04:16, 29 February 2012

Status & tagging log