/**
* User-agent detection
*/
+( function( $ ) {
$.client = new ( function() {
/* Private Members */
* Returns an object containing information about the browser
*
* The resulting client object will be in the following format:
- * {
- * 'name': 'firefox',
- * 'layout': 'gecko',
- * 'layoutVersion': '20101026',
- * 'platform': 'linux'
- * 'version': '3.5.1',
- * 'versionBase': '3',
- * 'versionNumber': 3.5,
- * }
+ * {
+ * 'name': 'firefox',
+ * 'layout': 'gecko',
+ * 'layoutVersion': '20101026',
+ * 'platform': 'linux'
+ * 'version': '3.5.1',
+ * 'versionBase': '3',
+ * 'versionNumber': 3.5,
+ * }
*/
this.profile = function() {
// Use the cached version if possible
// This helps keep differnt versions consistent
['Navigator', 'Netscape'],
// This prevents version extraction issues, otherwise translation would happen later
- ['PLAYSTATION 3', 'PS3'],
+ ['PLAYSTATION 3', 'PS3']
];
// Strings which precede a version number in a user agent string - combined and used as match 1 in
// version detectection
var versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)';
// Names of known browsers
var names = [
- 'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
- 'iphone', 'blackberry', 'ps3'
+ 'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
+ 'iphone', 'blackberry', 'ps3'
];
// Tanslations for conforming browser names
var nameTranslations = [];
/* Methods */
// Performs multiple replacements on a string
- function translate( source, translations ) {
+ var translate = function( source, translations ) {
for ( var i = 0; i < translations.length; i++ ) {
source = source.replace( translations[i][0], translations[i][1] );
}
layout = translate( match[1], layoutTranslations );
}
if ( match = new RegExp( '(' + layoutVersions.join( '|' ) + ')\\\/(\\d+)').exec( navigator.userAgent.toLowerCase() ) ) {
- layoutversion = parseInt(match[2]);
+ layoutversion = parseInt( match[2], 10 );
}
if ( match = new RegExp( '(' + platforms.join( '|' ) + ')' ).exec( navigator.platform.toLowerCase() ) ) {
platform = translate( match[1], platformTranslations );
* element is classified as either "ltr" or "rtl". If neither is set, "ltr" is assumed.
*
* A browser map is in the following format:
- * {
- * 'ltr': {
- * // Multiple rules with configurable operators
- * 'msie': [['>=', 7], ['!=', 9]],
- * // Blocked entirely
- * 'iphone': false
- * },
- * 'rtl': {
- * // Test against a string
- * 'msie': [['!==', '8.1.2.3']],
- * // RTL rules do not fall through to LTR rules, you must explicity set each of them
- * 'iphone': false
- * }
- * }
+ * {
+ * 'ltr': {
+ * // Multiple rules with configurable operators
+ * 'msie': [['>=', 7], ['!=', 9]],
+ * // Blocked entirely
+ * 'iphone': false
+ * },
+ * 'rtl': {
+ * // Test against a string
+ * 'msie': [['!==', '8.1.2.3']],
+ * // RTL rules do not fall through to LTR rules, you must explicity set each of them
+ * 'iphone': false
+ * }
+ * }
*
* @param map Object of browser support map
*
var profile = $.client.profile();
var dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr';
// Check over each browser condition to determine if we are running in a compatible client
- if ( typeof map[dir] !== 'object' || map[dir][profile.name] !== 'object' ) {
+ if ( typeof map[dir] !== 'object' || typeof map[dir][profile.name] === 'undefined' ) {
// Unknown, so we assume it's working
return true;
}
.addClass( 'client-' + profile.name )
.addClass( 'client-' + profile.name + '-' + profile.versionBase )
.addClass( 'client-' + profile.layout )
- .addClass( 'client-' + profile.platform )
+ .addClass( 'client-' + profile.platform );
} );
+
+} )( jQuery );
\ No newline at end of file