Removing unneeded wraps and using $ and mw instead of jQuery or mediaWiki since r7924...
[lhc/web/wiklou.git] / resources / jquery / jquery.client.js
index 3ff4a40..81f220e 100644 (file)
@@ -1,22 +1,23 @@
-/*
- * User-agent detection 
+/**
+ * User-agent detection
  */
-jQuery.client = new ( function() {
-       
+$.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:
-        *  {
-        *              'browser': 'firefox',
+        *      {
+        *              'name': 'firefox',
         *              'layout': 'gecko',
-        *              'os': 'linux'
+        *              'layoutVersion': '20101026',
+        *              'platform': 'linux'
         *              'version': '3.5.1',
         *              'versionBase': '3',
         *              'versionNumber': 3.5,
@@ -25,9 +26,9 @@ jQuery.client = new ( function() {
        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
@@ -56,25 +57,27 @@ jQuery.client = new ( function() {
                                'msie', 'safari', 'ps3'
                        ];
                        // Used as matches 2, 3 and 4 in version extraction - 3 is used as actual version number
-                       var versionSuffix = '(\/|\;?\s|)([a-z0-9\.\+]*?)(\;|dev|rel|\\)|\s|$)';
+                       var versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)';
                        // Names of known browsers
-                       var browserNames = [
+                       var names = [
                                'camino', 'chrome', 'firefox', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', 'safari', 'ipod',
                                'iphone', 'blackberry', 'ps3'
                        ];
                        // Tanslations for conforming browser names
-                       var browserTranslations = [];
+                       var nameTranslations = [];
                        // Names of known layout engines
-                       var layoutNames = ['gecko', 'konqueror', 'msie', 'opera', 'webkit'];
+                       var layouts = ['gecko', 'konqueror', 'msie', 'opera', 'webkit'];
                        // Translations for conforming layout names
                        var layoutTranslations = [['konqueror', 'khtml'], ['msie', 'trident'], ['opera', 'presto']];
+                       // Names of supported layout engines for version number
+                       var layoutVersions = ['applewebkit', 'gecko'];
                        // Names of known operating systems
-                       var osNames = ['win', 'mac', 'linux', 'sunos', 'solaris', 'iphone'];
+                       var platforms = ['win', 'mac', 'linux', 'sunos', 'solaris', 'iphone'];
                        // Translations for conforming operating system names
-                       var osTranslations = [['sunos', 'solaris']];
-                       
+                       var platformTranslations = [['sunos', 'solaris']];
+
                        /* Methods */
-                       
+
                        // Performs multiple replacements on a string
                        function translate( source, translations ) {
                                for ( var i = 0; i < translations.length; i++ ) {
@@ -82,34 +85,37 @@ jQuery.client = new ( function() {
                                }
                                return source;
                        };
-                       
+
                        /* Pre-processing  */
-                       
-                       var userAgent = navigator.userAgent, match, browser = uk, layout = uk, os = uk, version = x;
+
+                       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
                                userAgent = translate( userAgent, userAgentTranslations );
                        }
                        // Everything will be in lowercase from now on
                        userAgent = userAgent.toLowerCase();
-                       
+
                        /* Extraction */
-                       
-                       if ( match = new RegExp( '(' + browserNames.join( '|' ) + ')' ).exec( userAgent ) ) {
-                               browser = translate( match[1], browserTranslations );
+
+                       if ( match = new RegExp( '(' + names.join( '|' ) + ')' ).exec( userAgent ) ) {
+                               name = translate( match[1], nameTranslations );
                        }
-                       if ( match = new RegExp( '(' + layoutNames.join( '|' ) + ')' ).exec( userAgent ) ) {
+                       if ( match = new RegExp( '(' + layouts.join( '|' ) + ')' ).exec( userAgent ) ) {
                                layout = translate( match[1], layoutTranslations );
                        }
-                       if ( match = new RegExp( '(' + osNames.join( '|' ) + ')' ).exec( navigator.platform.toLowerCase() ) ) {
-                               var os = translate( match[1], osTranslations );
+                       if ( match = new RegExp( '(' + layoutVersions.join( '|' ) + ')\\\/(\\d+)').exec( navigator.userAgent.toLowerCase() ) ) {
+                               layoutversion = parseInt(match[2]);
+                       }
+                       if ( match = new RegExp( '(' + platforms.join( '|' ) + ')' ).exec( navigator.platform.toLowerCase() ) ) {
+                               platform = translate( match[1], platformTranslations );
                        }
                        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';
@@ -118,13 +124,14 @@ jQuery.client = new ( function() {
                        if ( name === 'opera' && version >= 9.8) {
                                version = userAgent.match( /version\/([0-9\.]*)/i )[1] || 10;
                        }
-                       
+
                        /* Caching */
-                       
+
                        profile = {
-                               'browser': browser,
+                               'name': name,
                                'layout': layout,
-                               'os': os,
+                               'layoutVersion': layoutversion,
+                               'platform': platform,
                                'version': version,
                                'versionBase': ( version !== x ? new String( version ).substr( 0, 1 ) : x ),
                                'versionNumber': ( parseFloat( version, 10 ) || 0.0 )
@@ -132,12 +139,12 @@ jQuery.client = new ( function() {
                }
                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': {
@@ -153,23 +160,23 @@ jQuery.client = new ( function() {
         *                      '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 ) {
-               var profile = jQuery.client.profile();
-               var dir = jQuery( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr';
+               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.browser] !== 'object' ) {
+               if ( typeof map[dir] !== 'object' || map[dir][profile.name] !== 'object' ) {
                        // Unknown, so we assume it's working
                        return true;
                }
-               var browser = map[dir][profile.browser];
-               for ( var condition in browser ) {
-                       var op = browser[condition][0];
-                       var val = browser[condition][1];
+               var name = map[dir][profile.name];
+               for ( var condition in name ) {
+                       var op = name[condition][0];
+                       var val = name[condition][1];
                        if ( val === false ) {
                                return false;
                        } else if ( typeof val == 'string' ) {