r73050 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73049‎ | r73050 | r73051 >
Date:02:34, 15 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Swtiched to using a more robust object to properly store a cached profile
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.client.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.client.js
@@ -1,8 +1,14 @@
22 /*
33 * User-agent detection
44 */
5 -
6 -jQuery.client = {
 5+jQuery.client = new ( function() {
 6+
 7+ /* Private Members */
 8+
 9+ var profile;
 10+
 11+ /* Public Functions */
 12+
713 /**
814 * Returns an object containing information about the browser
915 *
@@ -16,9 +22,9 @@
1723 * 'versionNumber': 3.5,
1824 * }
1925 */
20 - 'profile': function() {
 26+ this.profile = function() {
2127 // Use the cached version if possible
22 - if ( typeof this.profile === 'undefined' ) {
 28+ if ( typeof profile === 'undefined' ) {
2329
2430 /* Configuration */
2531
@@ -115,7 +121,7 @@
116122
117123 /* Caching */
118124
119 - this.profile = {
 125+ profile = {
120126 'browser': browser,
121127 'layout': layout,
122128 'os': os,
@@ -124,8 +130,9 @@
125131 'versionNumber': ( parseFloat( version, 10 ) || 0.0 )
126132 };
127133 }
128 - return this.profile;
129 - },
 134+ return profile;
 135+ };
 136+
130137 /**
131138 * Checks the current browser against a support map object to determine if the browser has been black-listed or
132139 * not. If the browser was not configured specifically it is assumed to work. It is assumed that the body
@@ -151,14 +158,15 @@
152159 *
153160 * @return Boolean true if browser known or assumed to be supported, false if blacklisted
154161 */
155 - 'test': function( map ) {
156 - var profile = $.client.profile();
 162+ this.test = function( map ) {
 163+ var profile = jQuery.client.profile();
 164+ var dir = jQuery( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr';
157165 // Check over each browser condition to determine if we are running in a compatible client
158 - var browser = map[$( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'][profile.browser];
159 - if ( typeof browser !== 'object' ) {
 166+ if ( typeof map[dir] !== 'object' || map[dir][profile.browser] !== 'object' ) {
160167 // Unknown, so we assume it's working
161168 return true;
162169 }
 170+ var browser = map[dir][profile.browser];
163171 for ( var condition in browser ) {
164172 var op = browser[condition][0];
165173 var val = browser[condition][1];
@@ -176,4 +184,4 @@
177185 }
178186 return true;
179187 }
180 -};
\ No newline at end of file
 188+} )();
\ No newline at end of file

Status & tagging log