From 77424c1f5057b9beb8c10dbf84ff921999369a2f Mon Sep 17 00:00:00 2001 From: Krinkle Date: Fri, 29 Oct 2010 15:27:53 +0000 Subject: [PATCH] adding layoutversion to $.client and isLayoutVersion to mw.util. Follow-up of r75593 --- resources/jquery/jquery.client.js | 9 ++- resources/mediawiki.util/mediawiki.util.js | 68 +++++++++++++--------- 2 files changed, 48 insertions(+), 29 deletions(-) diff --git a/resources/jquery/jquery.client.js b/resources/jquery/jquery.client.js index 8b3575e1b5..1395771323 100644 --- a/resources/jquery/jquery.client.js +++ b/resources/jquery/jquery.client.js @@ -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 ), diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index edcf047f1d..621a5e9913 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -17,33 +17,34 @@ // 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(); @@ -87,19 +88,30 @@ * * @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(); @@ -111,7 +123,7 @@ * * @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; -- 2.20.1