r81276 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81275‎ | r81276 | r81277 >
Date:22:02, 31 January 2011
Author:krinkle
Status:ok
Tags:
Comment:
Applying conventions and some JSLint good practices in core modules.
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.async.js (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.autoEllipsis.js (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.client.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.autoEllipsis.js
@@ -17,29 +17,29 @@
1818 'matchText': null
1919 }, options );
2020 $(this).each( function() {
21 - var $this = $(this);
 21+ var $el = $(this);
2222 if ( options.restoreText ) {
23 - if ( ! $this.data( 'autoEllipsis.originalText' ) ) {
24 - $this.data( 'autoEllipsis.originalText', $this.text() );
 23+ if ( !$el.data( 'autoEllipsis.originalText' ) ) {
 24+ $el.data( 'autoEllipsis.originalText', $el.text() );
2525 } else {
26 - $this.text( $this.data( 'autoEllipsis.originalText' ) );
 26+ $el.text( $el.data( 'autoEllipsis.originalText' ) );
2727 }
2828 }
2929
3030 // container element - used for measuring against
31 - var $container = $this;
 31+ var $container = $el;
3232 // trimmable text element - only the text within this element will be trimmed
3333 var $trimmableText = null;
3434 // protected text element - the width of this element is counted, but next is never trimmed from it
3535 var $protectedText = null;
3636
3737 if ( options.hasSpan ) {
38 - $trimmableText = $this.children( options.selector );
 38+ $trimmableText = $el.children( options.selector );
3939 } else {
4040 $trimmableText = $( '<span />' )
4141 .css( 'whiteSpace', 'nowrap' )
42 - .text( $this.text() );
43 - $this
 42+ .text( $el.text() );
 43+ $el
4444 .empty()
4545 .append( $trimmableText );
4646 }
@@ -60,14 +60,16 @@
6161 }
6262 if ( !options.matchText && w in cache[text] ) {
6363 $container.html( cache[text][w] );
64 - if ( options.tooltip )
 64+ if ( options.tooltip ) {
6565 $container.attr( 'title', text );
 66+ }
6667 return;
6768 }
6869 if( options.matchText && options.matchText in matchTextCache[text] && w in matchTextCache[text][options.matchText] ) {
6970 $container.html( matchTextCache[text][options.matchText][w] );
70 - if ( options.tooltip )
 71+ if ( options.tooltip ) {
7172 $container.attr( 'title', text );
 73+ }
7274 return;
7375 }
7476 if ( $trimmableText.width() + pw > w ) {
@@ -94,7 +96,7 @@
9597 while ( $trimmableText.outerWidth() + pw > w && i[0] > 0 ) {
9698 $trimmableText.text( trimmableText.substr( 0, i[0] ) + '...' + trimmableText.substr( i[1] ) );
9799 // Alternate between trimming the end and begining
98 - if ( side == 0 ) {
 100+ if ( side === 0 ) {
99101 // Make the begining shorter
100102 i[0]--;
101103 side = 1;
Index: trunk/phase3/resources/jquery/jquery.async.js
@@ -13,33 +13,28 @@
1414 // opts.test : (default true) function to test in the while test part
1515 // opts.loop : (default empty) function to call in the while loop part
1616 // opts.end : (default empty) function to call at the end of the while loop
17 -$.whileAsync = function(opts)
18 -{
 17+$.whileAsync = function(opts) {
1918 var delay = Math.abs(opts.delay) || 10,
2019 bulk = isNaN(opts.bulk) ? 500 : Math.abs(opts.bulk),
2120 test = opts.test || function(){ return true; },
2221 loop = opts.loop || function(){},
23 - end = opts.end || function(){};
 22+ end = opts.end || function(){};
2423
2524 (function(){
2625
2726 var t = false,
2827 begin = new Date();
2928
30 - while( t = test() )
31 - {
 29+ while( t = test() ) {
3230 loop();
33 - if( bulk === 0 || (new Date() - begin) > bulk )
34 - {
 31+ if( bulk === 0 || (new Date() - begin) > bulk ) {
3532 break;
3633 }
3734 }
38 - if( t )
39 - {
 35+ if( t ) {
4036 setTimeout(arguments.callee, delay);
4137 }
42 - else
43 - {
 38+ else {
4439 end();
4540 }
4641
@@ -50,17 +45,15 @@
5146 // opts.bulk : (default 500) delay during which the loop can continue synchronously without yielding the CPU
5247 // opts.loop : (default empty) function to call in the each loop part, signature: function(index, value) this = value
5348 // opts.end : (default empty) function to call at the end of the each loop
54 -$.eachAsync = function(array, opts)
55 -{
56 - var i = 0,
 49+$.eachAsync = function(array, opts) {
 50+ var i = 0,
5751 l = array.length,
5852 loop = opts.loop || function(){};
5953
6054 $.whileAsync(
6155 $.extend(opts, {
62 - test: function(){ return i < l; },
63 - loop: function()
64 - {
 56+ test: function() { return i < l; },
 57+ loop: function() {
6558 var val = array[i];
6659 return loop.call(val, i++, val);
6760 }
@@ -68,11 +61,9 @@
6962 );
7063 };
7164
72 -$.fn.eachAsync = function(opts)
73 -{
 65+$.fn.eachAsync = function(opts) {
7466 $.eachAsync(this, opts);
7567 return this;
7668 }
7769
78 -})(jQuery);
79 -
 70+})(jQuery);
\ No newline at end of file
Index: trunk/phase3/resources/jquery/jquery.client.js
@@ -1,7 +1,6 @@
22 /**
33 * User-agent detection
44 */
5 - */
65 ( function( $ ) {
76 $.client = new ( function() {
87
@@ -15,15 +14,15 @@
1615 * Returns an object containing information about the browser
1716 *
1817 * The resulting client object will be in the following format:
19 - * {
20 - * 'name': 'firefox',
21 - * 'layout': 'gecko',
22 - * 'layoutVersion': '20101026',
23 - * 'platform': 'linux'
24 - * 'version': '3.5.1',
25 - * 'versionBase': '3',
26 - * 'versionNumber': 3.5,
27 - * }
 18+ * {
 19+ * 'name': 'firefox',
 20+ * 'layout': 'gecko',
 21+ * 'layoutVersion': '20101026',
 22+ * 'platform': 'linux'
 23+ * 'version': '3.5.1',
 24+ * 'versionBase': '3',
 25+ * 'versionNumber': 3.5,
 26+ * }
2827 */
2928 this.profile = function() {
3029 // Use the cached version if possible
@@ -50,7 +49,7 @@
5150 // This helps keep differnt versions consistent
5251 ['Navigator', 'Netscape'],
5352 // This prevents version extraction issues, otherwise translation would happen later
54 - ['PLAYSTATION 3', 'PS3'],
 53+ ['PLAYSTATION 3', 'PS3']
5554 ];
5655 // Strings which precede a version number in a user agent string - combined and used as match 1 in
5756 // version detectection
@@ -62,8 +61,8 @@
6362 var versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)';
6463 // Names of known browsers
6564 var names = [
66 - 'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
67 - 'iphone', 'blackberry', 'ps3'
 65+ 'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
 66+ 'iphone', 'blackberry', 'ps3'
6867 ];
6968 // Tanslations for conforming browser names
7069 var nameTranslations = [];
@@ -81,7 +80,7 @@
8281 /* Methods */
8382
8483 // Performs multiple replacements on a string
85 - function translate( source, translations ) {
 84+ var translate = function( source, translations ) {
8685 for ( var i = 0; i < translations.length; i++ ) {
8786 source = source.replace( translations[i][0], translations[i][1] );
8887 }
@@ -107,7 +106,7 @@
108107 layout = translate( match[1], layoutTranslations );
109108 }
110109 if ( match = new RegExp( '(' + layoutVersions.join( '|' ) + ')\\\/(\\d+)').exec( navigator.userAgent.toLowerCase() ) ) {
111 - layoutversion = parseInt(match[2]);
 110+ layoutversion = parseInt( match[2], 10 );
112111 }
113112 if ( match = new RegExp( '(' + platforms.join( '|' ) + ')' ).exec( navigator.platform.toLowerCase() ) ) {
114113 platform = translate( match[1], platformTranslations );
@@ -148,20 +147,20 @@
149148 * element is classified as either "ltr" or "rtl". If neither is set, "ltr" is assumed.
150149 *
151150 * A browser map is in the following format:
152 - * {
153 - * 'ltr': {
154 - * // Multiple rules with configurable operators
155 - * 'msie': [['>=', 7], ['!=', 9]],
156 - * // Blocked entirely
157 - * 'iphone': false
158 - * },
159 - * 'rtl': {
160 - * // Test against a string
161 - * 'msie': [['!==', '8.1.2.3']],
162 - * // RTL rules do not fall through to LTR rules, you must explicity set each of them
163 - * 'iphone': false
164 - * }
165 - * }
 151+ * {
 152+ * 'ltr': {
 153+ * // Multiple rules with configurable operators
 154+ * 'msie': [['>=', 7], ['!=', 9]],
 155+ * // Blocked entirely
 156+ * 'iphone': false
 157+ * },
 158+ * 'rtl': {
 159+ * // Test against a string
 160+ * 'msie': [['!==', '8.1.2.3']],
 161+ * // RTL rules do not fall through to LTR rules, you must explicity set each of them
 162+ * 'iphone': false
 163+ * }
 164+ * }
166165 *
167166 * @param map Object of browser support map
168167 *

Status & tagging log