/*
- * User-agent detection
+ * User-agent detection
*/
jQuery.client = new ( function() {
-
+
/* Private Members */
-
+
var profile;
-
+
/* Public Functions */
-
+
/**
* Returns an object containing information about the browser
- *
+ *
* The resulting client object will be in the following format:
* {
* 'name': 'firefox',
this.profile = function() {
// Use the cached version if possible
if ( typeof profile === 'undefined' ) {
-
+
/* Configuration */
-
+
// Name of browsers or layout engines we don't recognize
var uk = 'unknown';
// Generic version digit
var platforms = ['win', 'mac', 'linux', 'sunos', 'solaris', 'iphone'];
// Translations for conforming operating system names
var platformTranslations = [['sunos', 'solaris']];
-
+
/* Methods */
-
+
// Performs multiple replacements on a string
function translate( source, translations ) {
for ( var i = 0; i < translations.length; i++ ) {
}
return source;
};
-
+
/* Pre-processing */
-
+
var userAgent = navigator.userAgent, match, name = uk, layout = uk, layoutversion = uk, platform = uk, version = x;
if ( match = new RegExp( '(' + wildUserAgents.join( '|' ) + ')' ).exec( userAgent ) ) {
// Takes a userAgent string and translates given text into something we can more easily work with
}
// Everything will be in lowercase from now on
userAgent = userAgent.toLowerCase();
-
+
/* Extraction */
-
+
if ( match = new RegExp( '(' + names.join( '|' ) + ')' ).exec( userAgent ) ) {
name = translate( match[1], nameTranslations );
}
if ( match = new RegExp( '(' + versionPrefixes.join( '|' ) + ')' + versionSuffix ).exec( userAgent ) ) {
version = match[3];
}
-
+
/* Edge Cases -- did I mention about how user agent string lie? */
-
+
// Decode Safari's crazy 400+ version numbers
if ( name.match( /safari/ ) && version > 400 ) {
version = '2.0';
if ( name === 'opera' && version >= 9.8) {
version = userAgent.match( /version\/([0-9\.]*)/i )[1] || 10;
}
-
+
/* Caching */
-
+
profile = {
'name': name,
'layout': layout,
}
return profile;
};
-
+
/**
* Checks the current browser against a support map object to determine if the browser has been black-listed or
* not. If the browser was not configured specifically it is assumed to work. It is assumed that the body
* element is classified as either "ltr" or "rtl". If neither is set, "ltr" is assumed.
- *
+ *
* A browser map is in the following format:
* {
* 'ltr': {
* 'iphone': false
* }
* }
- *
+ *
* @param map Object of browser support map
- *
+ *
* @return Boolean true if browser known or assumed to be supported, false if blacklisted
*/
this.test = function( map ) {
// Any initialisation after the DOM is ready
$(function () {
-
+
// Populate clientProfile var
mw.util.clientProfile = $.client.profile();
- var webkit = navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
// Set tooltipAccessKeyPrefix
-
+
// Opera on any platform
if ( mw.util.isBrowser('opera') ) {
this.tooltipAccessKeyPrefix = 'shift-esc-';
-
+
// Chrome on any platform
} else if ( mw.util.isBrowser('chrome') ) {
// Chrome on Mac or Chrome on other platform ?
this.tooltipAccessKeyPrefix = mw.util.isPlatform('mac') ? 'ctrl-option-' : 'alt-';
-
+
// Non-Windows Safari with webkit_version > 526
} else if ( !mw.util.isPlatform('win') && mw.util.isBrowser('safari') && webkit_version > 526 ) {
this.tooltipAccessKeyPrefix = 'ctrl-alt-';
-
+
// Safari/Konqueror on any platform, or any browser on Mac (but not Safari on Windows)
} else if ( !( mw.util.isPlatform('win') && mw.util.isBrowser('safari') )
&& ( mw.util.isBrowser('safari')
|| mw.util.isPlatform('mac')
|| mw.util.isBrowser('konqueror') ) ) {
this.tooltipAccessKeyPrefix = 'ctrl-';
-
+
// Firefox 2.x
} else if ( mw.util.isBrowser('firefox') && mw.util.isBrowserVersion('2') ) {
this.tooltipAccessKeyPrefix = 'alt-shift-';
mw.util.$content = $('#article');
} else {
mw.util.$content = $('#content');
- }
+ }
});