r113895 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113894‎ | r113895 | r113896 >
Date:06:44, 15 March 2012
Author:krinkle
Status:ok
Tags:
Comment:
[jquery.client] clean up
* Move translate() out of the if-block, no need to re-define
* `else` after return in `if`
* update js coding style
* remove bogus '=' in comment
* line-wrapping of long arrays
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.client.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.client.js
@@ -1,7 +1,7 @@
22 /**
33 * User-agent detection
44 */
5 -( function( $ ) {
 5+( function ( $ ) {
66
77 /* Private Members */
88
@@ -18,7 +18,7 @@
1919 /**
2020 * Get an object containing information about the client.
2121 *
22 - * @param nav {Object} An object with atleast a 'userAgent' and 'platform' key.=
 22+ * @param nav {Object} An object with atleast a 'userAgent' and 'platform' key.
2323 * Defaults to the global Navigator object.
2424 * @return {Object} The resulting client object will be in the following format:
2525 * {
@@ -31,7 +31,7 @@
3232 * 'versionNumber': 3.5,
3333 * }
3434 */
35 - profile: function( nav ) {
 35+ profile: function ( nav ) {
3636 if ( nav === undefined ) {
3737 nav = window.navigator;
3838 }
@@ -64,15 +64,15 @@
6565 // Strings which precede a version number in a user agent string - combined and used as match 1 in
6666 // version detectection
6767 var versionPrefixes = [
68 - 'camino', 'chrome', 'firefox', 'netscape', 'netscape6', 'opera', 'version', 'konqueror', 'lynx',
69 - 'msie', 'safari', 'ps3'
 68+ 'camino', 'chrome', 'firefox', 'netscape', 'netscape6', 'opera', 'version', 'konqueror',
 69+ 'lynx', 'msie', 'safari', 'ps3'
7070 ];
7171 // Used as matches 2, 3 and 4 in version extraction - 3 is used as actual version number
7272 var versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)';
7373 // Names of known browsers
7474 var names = [
75 - 'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
76 - 'iphone', 'blackberry', 'ps3', 'rekonq'
 75+ 'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera',
 76+ 'safari', 'ipod', 'iphone', 'blackberry', 'ps3', 'rekonq'
7777 ];
7878 // Tanslations for conforming browser names
7979 var nameTranslations = [];
@@ -89,9 +89,12 @@
9090
9191 /* Methods */
9292
93 - // Performs multiple replacements on a string
94 - var translate = function( source, translations ) {
95 - for ( var i = 0; i < translations.length; i++ ) {
 93+ /**
 94+ * Performs multiple replacements on a string
 95+ */
 96+ var translate = function ( source, translations ) {
 97+ var i;
 98+ for ( i = 0; i < translations.length; i++ ) {
9699 source = source.replace( translations[i][0], translations[i][1] );
97100 }
98101 return source;
@@ -147,13 +150,13 @@
148151 /* Caching */
149152
150153 profileCache[nav.userAgent] = {
151 - 'name': name,
152 - 'layout': layout,
153 - 'layoutVersion': layoutversion,
154 - 'platform': platform,
155 - 'version': version,
156 - 'versionBase': ( version !== x ? Math.floor( versionNumber ).toString() : x ),
157 - 'versionNumber': versionNumber
 154+ name: name,
 155+ layout: layout,
 156+ layoutVersion: layoutversion,
 157+ platform: platform,
 158+ version: version,
 159+ versionBase: ( version !== x ? Math.floor( versionNumber ).toString() : x ),
 160+ versionNumber: versionNumber
158161 };
159162 }
160163 return profileCache[nav.userAgent];
@@ -185,26 +188,28 @@
186189 *
187190 * @return Boolean true if browser known or assumed to be supported, false if blacklisted
188191 */
189 - test: function( map, profile ) {
 192+ test: function ( map, profile ) {
 193+ var conditions, dir, i, op, val;
190194 profile = $.isPlainObject( profile ) ? profile : $.client.profile();
191195
192 - var dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr';
 196+ dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr';
193197 // Check over each browser condition to determine if we are running in a compatible client
194 - if ( typeof map[dir] !== 'object' || typeof map[dir][profile.name] === 'undefined' ) {
 198+ if ( typeof map[dir] !== 'object' || map[dir][profile.name] === undefined ) {
195199 // Unknown, so we assume it's working
196200 return true;
197201 }
198 - var conditions = map[dir][profile.name];
199 - for ( var i = 0; i < conditions.length; i++ ) {
200 - var op = conditions[i][0];
201 - var val = conditions[i][1];
 202+ conditions = map[dir][profile.name];
 203+ for ( i = 0; i < conditions.length; i++ ) {
 204+ op = conditions[i][0];
 205+ val = conditions[i][1];
202206 if ( val === false ) {
203207 return false;
204 - } else if ( typeof val == 'string' ) {
 208+ }
 209+ if ( typeof val === 'string' ) {
205210 if ( !( eval( 'profile.version' + op + '"' + val + '"' ) ) ) {
206211 return false;
207212 }
208 - } else if ( typeof val == 'number' ) {
 213+ } else if ( typeof val === 'number' ) {
209214 if ( !( eval( 'profile.versionNumber' + op + val ) ) ) {
210215 return false;
211216 }
@@ -213,4 +218,4 @@
214219 return true;
215220 }
216221 };
217 -} )( jQuery );
 222+}( jQuery ) );

Status & tagging log