/**
* User-agent detection
+ *
+ * @class jQuery.client
+ * @singleton
*/
( function ( $ ) {
- /* Private Members */
-
/**
- * @var {Object} profileCache Keyed by userAgent string,
+ * @private
+ * @property {Object} profileCache Keyed by userAgent string,
* value is the parsed $.client.profile object for that user agent.
*/
var profileCache = {};
- /* Public Methods */
-
$.client = {
/**
* Get an object containing information about the client.
*
- * @param {Object} nav An object with atleast a 'userAgent' and 'platform' key.
- * Defaults to the global Navigator object.
+ * @param {Object} [nav] An object with a 'userAgent' and 'platform' property.
+ * Defaults to the global `navigator` object.
* @return {Object} 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,
+ * }
*/
profile: function ( nav ) {
/*jshint boss: true */
versionNumber,
key = nav.userAgent + '|' + nav.platform,
- /* Configuration */
+ // Configuration
// Name of browsers or layout engines we don't recognize
uk = 'unknown',
// Translations for conforming operating system names
platformTranslations = [ ['sunos', 'solaris'], ['wow64', 'win'] ],
- /* Methods */
-
/**
* Performs multiple replacements on a string
+ * @ignore
*/
translate = function ( source, translations ) {
var i;
return source;
},
- /* Pre-processing */
+ // Pre-processing
ua = nav.userAgent,
match,
// Everything will be in lowercase from now on
ua = ua.toLowerCase();
- /* Extraction */
+ // Extraction
if ( match = new RegExp( '(' + names.join( '|' ) + ')' ).exec( ua ) ) {
name = translate( match[1], nameTranslations );
version = match[3];
}
- /* Edge Cases -- did I mention about how user agent string lie? */
+ // Edge Cases -- did I mention about how user agent string lie?
// Decode Safari's crazy 400+ version numbers
if ( name === 'safari' && version > 400 ) {
versionNumber = parseFloat( version, 10 ) || 0.0;
- /* Caching */
+ // Caching
return profileCache[ key ] = {
name: name,
* algorithm, similar to PHP's version_compare ('1.2' < '1.11').
*
* A browser map is in the following format:
- * {
- * // Multiple rules with configurable operators
- * 'msie': [['>=', 7], ['!=', 9]],
- * // Match no versions
- * 'iphone': false,
- * // Match any version
- * 'android': null
- * }
+ *
+ * {
+ * // Multiple rules with configurable operators
+ * 'msie': [['>=', 7], ['!=', 9]],
+ * // Match no versions
+ * 'iphone': false,
+ * // Match any version
+ * 'android': null
+ * }
*
* It can optionally be split into ltr/rtl sections:
- * {
- * 'ltr': {
- * 'android': null,
- * 'iphone': false
- * },
- * 'rtl': {
- * 'android': false,
- * // rules are not inherited from ltr
- * 'iphone': false
- * }
- * }
+ *
+ * {
+ * 'ltr': {
+ * 'android': null,
+ * 'iphone': false
+ * },
+ * 'rtl': {
+ * 'android': false,
+ * // rules are not inherited from ltr
+ * 'iphone': false
+ * }
+ * }
*
* @param {Object} map Browser support map
* @param {Object} [profile] A client-profile object