adding layoutversion to $.client and isLayoutVersion to mw.util. Follow-up of r75593
authorKrinkle <krinkle@users.mediawiki.org>
Fri, 29 Oct 2010 15:27:53 +0000 (15:27 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Fri, 29 Oct 2010 15:27:53 +0000 (15:27 +0000)
resources/jquery/jquery.client.js
resources/mediawiki.util/mediawiki.util.js

index 8b3575e..1395771 100644 (file)
@@ -16,6 +16,7 @@ jQuery.client = new ( function() {
         *  {
         *              'name': 'firefox',
         *              'layout': 'gecko',
+        *              'layoutVersion': '20101026',
         *              'platform': 'linux'
         *              'version': '3.5.1',
         *              'versionBase': '3',
@@ -68,6 +69,8 @@ jQuery.client = new ( function() {
                        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 platforms = ['win', 'mac', 'linux', 'sunos', 'solaris', 'iphone'];
                        // Translations for conforming operating system names
@@ -85,7 +88,7 @@ jQuery.client = new ( function() {
                        
                        /* Pre-processing  */
                        
-                       var userAgent = navigator.userAgent, match, name = uk, layout = uk, platform = 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 );
@@ -101,6 +104,9 @@ jQuery.client = new ( function() {
                        if ( match = new RegExp( '(' + layouts.join( '|' ) + ')' ).exec( userAgent ) ) {
                                layout = translate( match[1], layoutTranslations );
                        }
+                       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 );
                        }
@@ -124,6 +130,7 @@ jQuery.client = new ( function() {
                        profile = {
                                'name': name,
                                'layout': layout,
+                               'layoutVersion': layoutversion,
                                'platform': platform,
                                'version': version,
                                'versionBase': ( version !== x ? new String( version ).substr( 0, 1 ) : x ),
index edcf047..621a5e9 100644 (file)
                                        
                                        // 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-';
-                                               }
+                                       // 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-';
+                                       }
 
                                        // Enable CheckboxShiftClick
                                        $('input[type=checkbox]:not(.noshiftselect)').checkboxShiftClick();
@@ -75,7 +76,7 @@
                *
                * @example      mw.util.isBrowser( 'safari' );
                * @param        String  str     name of a browser (case insensitive). Check jquery.client.js for possible values
-               * @return       Boolean         true of the browsername matches the clients browser
+               * @return       Boolean         true if the browsername matches the clients browser
                */
                'isBrowser' : function( str ) {
                        str = (str + '').toLowerCase();
                *
                * @example      mw.util.isLayout( 'webkit' );
                * @param        String  str     name of a layout engine (case insensitive). Check jquery.client.js for possible values
-               * @return       Boolean         true of the layout engine matches the clients browser
+               * @return       Boolean         true if the layout engine matches the clients browser
                */
                'isLayout' : function( str ) {
                        str = (str + '').toLowerCase();
                        return this.clientProfile.layout == str;
                },
 
+               /**
+               * Checks if the current layout engine version matches
+               *
+               * @example      mw.util.isLayoutVersion( 533 );
+               * @param        Number  num     version number of a layout engine.
+               * @return       Boolean         true if the layout engine matches the clients browser
+               */
+               'isLayoutVersion' : function( num ) {
+                       return this.clientProfile.layoutVersion == num;
+               },
+
                /**
                * Checks if the current layout matches
                *
                * @example      mw.util.isPlatform( 'mac' );
                * @param        String  str     name of a platform (case insensitive). Check jquery.client.js for possible values
-               * @return       Boolean         true of the platform matches the clients platform
+               * @return       Boolean         true if the platform matches the clients platform
                */
                'isPlatform' : function( str ) {
                        str = (str + '').toLowerCase();
                *
                * @example      mw.util.isBrowserVersion( '5' );
                * @param        String  str     version number without decimals
-               * @return       Boolean         true of the version number matches the clients browser
+               * @return       Boolean         true if the version number matches the clients browser
                */
                'isBrowserVersion' : function( str ) {
                        return this.clientProfile.versionBase === str;