From: James D. Forrester Date: Wed, 11 Mar 2015 23:14:46 +0000 (-0700) Subject: resources: Move to library version of jquery.client X-Git-Tag: 1.31.0-rc.0~12129 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=97c4e93eefc7182fb4a166e752d44e8853fe3218;p=lhc%2Fweb%2Fwiklou.git resources: Move to library version of jquery.client The jQuery Client library is no longer mastered in MediaWiki, and is instead a proper, published library, which is now tagged as v1.0.0. Change-Id: Idd19d738b392a5f742fef6f98c885e8c391a5cbf --- diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index d1745d23ec..5e08efdd0e 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -113,6 +113,8 @@ production. links of a group of changes in EnhancedChangesList. * A full interface for StatsD metric reporting has been added to the context interface, reachable via IContextSource::getStats(). +* Move the jQuery Client library from being mastered in MediaWiki as v0.1.0 to a + proper, published library, which is now tagged as v1.0.0. ==== External libraries ==== * MediaWiki now requires certain external libraries to be installed. In the past diff --git a/jsduck.json b/jsduck.json index afd2bd8147..67ab986f82 100644 --- a/jsduck.json +++ b/jsduck.json @@ -25,7 +25,6 @@ "resources/src/jquery/jquery.byteLength.js", "resources/src/jquery/jquery.byteLimit.js", "resources/src/jquery/jquery.checkboxShiftClick.js", - "resources/src/jquery/jquery.client.js", "resources/src/jquery/jquery.colorUtil.js", "resources/src/jquery/jquery.confirmable.js", "resources/src/jquery/jquery.footHovzer.js", @@ -35,6 +34,7 @@ "resources/src/jquery/jquery.makeCollapsible.js", "resources/src/jquery/jquery.spinner.js", "resources/src/jquery/jquery.tabIndex.js", + "resources/lib/jquery.client/jquery.client.js", "resources/lib/oojs", "resources/lib/oojs-ui" ] diff --git a/resources/Resources.php b/resources/Resources.php index 50a03f60d4..005b9c2eb8 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -185,7 +185,7 @@ return array( 'styles' => 'resources/lib/jquery.chosen/chosen.css', ), 'jquery.client' => array( - 'scripts' => 'resources/src/jquery/jquery.client.js', + 'scripts' => 'resources/lib/jquery.client/jquery.client.js', 'targets' => array( 'desktop', 'mobile' ), ), 'jquery.color' => array( diff --git a/resources/lib/jquery.client/AUTHORS.txt b/resources/lib/jquery.client/AUTHORS.txt new file mode 100644 index 0000000000..9f186cac1e --- /dev/null +++ b/resources/lib/jquery.client/AUTHORS.txt @@ -0,0 +1,9 @@ +Trevor Parscal +Timo Tijhof +Roan Kattouw +Derk-Jan Hartman +Bartosz Dziewoński +Rob Moen +Ed Sanders +Alex Monk +James D. Forrester diff --git a/resources/lib/jquery.client/LICENSE-MIT.txt b/resources/lib/jquery.client/LICENSE-MIT.txt new file mode 100644 index 0000000000..f149289d4c --- /dev/null +++ b/resources/lib/jquery.client/LICENSE-MIT.txt @@ -0,0 +1,20 @@ +Copyright 2010-2015 jquery-client maintainers and other contributors. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/resources/lib/jquery.client/README.md b/resources/lib/jquery.client/README.md new file mode 100644 index 0000000000..02b5dd419a --- /dev/null +++ b/resources/lib/jquery.client/README.md @@ -0,0 +1,6 @@ +[![Build Status](https://travis-ci.org/wikimedia/jquery-client.svg?branch=master)](https://travis-ci.org/wikimedia/jquery-client) [![npm](https://img.shields.io/npm/v/jquery-client.svg?style=flat)](https://www.npmjs.com/package/jquery-client) + +jQuery Client +================= + +jQuery Client is a jQuery plugin for user-agent detection. diff --git a/resources/lib/jquery.client/jquery.client.js b/resources/lib/jquery.client/jquery.client.js new file mode 100644 index 0000000000..1560c7d2f4 --- /dev/null +++ b/resources/lib/jquery.client/jquery.client.js @@ -0,0 +1,317 @@ +/*! + * jQuery Client v1.0.0 + * https://www.mediawiki.org/wiki/JQuery_Client + * + * Copyright 2010-2015 jquery-client maintainers and other contributors. + * Released under the MIT license + * http://jquery-client.mit-license.org + */ + +/** + * User-agent detection + * + * @class jQuery.client + * @singleton + */ +( function ( $ ) { + + /** + * @private + * @property {Object} profileCache Keyed by userAgent string, + * value is the parsed $.client.profile object for that user agent. + */ + var profileCache = {}; + + $.client = { + + /** + * Get an object containing information about the client. + * + * @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, + * } + */ + profile: function ( nav ) { + /*jshint boss:true */ + + if ( nav === undefined ) { + nav = window.navigator; + } + + // Use the cached version if possible + if ( profileCache[ nav.userAgent + '|' + nav.platform ] !== undefined ) { + return profileCache[ nav.userAgent + '|' + nav.platform ]; + } + + var + versionNumber, + key = nav.userAgent + '|' + nav.platform, + + // Configuration + + // Name of browsers or layout engines we don't recognize + uk = 'unknown', + // Generic version digit + x = 'x', + // Strings found in user agent strings that need to be conformed + wildUserAgents = ['Opera', 'Navigator', 'Minefield', 'KHTML', 'Chrome', 'PLAYSTATION 3', 'Iceweasel'], + // Translations for conforming user agent strings + userAgentTranslations = [ + // Tons of browsers lie about being something they are not + [/(Firefox|MSIE|KHTML,?\slike\sGecko|Konqueror)/, ''], + // Chrome lives in the shadow of Safari still + ['Chrome Safari', 'Chrome'], + // KHTML is the layout engine not the browser - LIES! + ['KHTML', 'Konqueror'], + // Firefox nightly builds + ['Minefield', 'Firefox'], + // This helps keep different versions consistent + ['Navigator', 'Netscape'], + // This prevents version extraction issues, otherwise translation would happen later + ['PLAYSTATION 3', 'PS3'] + ], + // Strings which precede a version number in a user agent string - combined and used as + // match 1 in version detection + versionPrefixes = [ + 'camino', 'chrome', 'firefox', 'iceweasel', 'netscape', 'netscape6', 'opera', 'version', 'konqueror', + 'lynx', 'msie', 'safari', 'ps3', 'android' + ], + // Used as matches 2, 3 and 4 in version extraction - 3 is used as actual version number + versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)', + // Names of known browsers + names = [ + 'camino', 'chrome', 'firefox', 'iceweasel', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', + 'safari', 'ipod', 'iphone', 'blackberry', 'ps3', 'rekonq', 'android' + ], + // Tanslations for conforming browser names + nameTranslations = [], + // Names of known layout engines + layouts = ['gecko', 'konqueror', 'msie', 'trident', 'edge', 'opera', 'webkit'], + // Translations for conforming layout names + layoutTranslations = [ ['konqueror', 'khtml'], ['msie', 'trident'], ['opera', 'presto'] ], + // Names of supported layout engines for version number + layoutVersions = ['applewebkit', 'gecko', 'trident', 'edge'], + // Names of known operating systems + platforms = ['win', 'wow64', 'mac', 'linux', 'sunos', 'solaris', 'iphone'], + // Translations for conforming operating system names + platformTranslations = [ ['sunos', 'solaris'], ['wow64', 'win'] ], + + /** + * Performs multiple replacements on a string + * @ignore + */ + translate = function ( source, translations ) { + var i; + for ( i = 0; i < translations.length; i++ ) { + source = source.replace( translations[i][0], translations[i][1] ); + } + return source; + }, + + // Pre-processing + + ua = nav.userAgent, + match, + name = uk, + layout = uk, + layoutversion = uk, + platform = uk, + version = x; + + if ( match = new RegExp( '(' + wildUserAgents.join( '|' ) + ')' ).exec( ua ) ) { + // Takes a userAgent string and translates given text into something we can more easily work with + ua = translate( ua, userAgentTranslations ); + } + // Everything will be in lowercase from now on + ua = ua.toLowerCase(); + + // Extraction + + if ( match = new RegExp( '(' + names.join( '|' ) + ')' ).exec( ua ) ) { + name = translate( match[1], nameTranslations ); + } + if ( match = new RegExp( '(' + layouts.join( '|' ) + ')' ).exec( ua ) ) { + layout = translate( match[1], layoutTranslations ); + } + if ( match = new RegExp( '(' + layoutVersions.join( '|' ) + ')\\\/(\\d+)').exec( ua ) ) { + layoutversion = parseInt( match[2], 10 ); + } + if ( match = new RegExp( '(' + platforms.join( '|' ) + ')' ).exec( nav.platform.toLowerCase() ) ) { + platform = translate( match[1], platformTranslations ); + } + if ( match = new RegExp( '(' + versionPrefixes.join( '|' ) + ')' + versionSuffix ).exec( ua ) ) { + version = match[3]; + } + + // Edge Cases -- did I mention about how user agent string lie? + + // Decode Safari's crazy 400+ version numbers + if ( name === 'safari' && version > 400 ) { + version = '2.0'; + } + // Expose Opera 10's lies about being Opera 9.8 + if ( name === 'opera' && version >= 9.8 ) { + match = ua.match( /\bversion\/([0-9\.]*)/ ); + if ( match && match[1] ) { + version = match[1]; + } else { + version = '10'; + } + } + // And Opera 15's lies about being Chrome + if ( name === 'chrome' && ( match = ua.match( /\bopr\/([0-9\.]*)/ ) ) ) { + if ( match[1] ) { + name = 'opera'; + version = match[1]; + } + } + // And IE 11's lies about being not being IE + if ( layout === 'trident' && layoutversion >= 7 && ( match = ua.match( /\brv[ :\/]([0-9\.]*)/ ) ) ) { + if ( match[1] ) { + name = 'msie'; + version = match[1]; + } + } + // And IE 12's different lies about not being IE + if ( name === 'chrome' && ( match = ua.match( /\bedge\/([0-9\.]*)/ ) ) ) { + name = 'msie'; + version = match[1]; + layout = 'edge'; + layoutversion = parseInt( match[1], 10 ); + } + // And Amazon Silk's lies about being Android on mobile or Safari on desktop + if ( match = ua.match( /\bsilk\/([0-9.\-_]*)/ ) ) { + if ( match[1] ) { + name = 'silk'; + version = match[1]; + } + } + + versionNumber = parseFloat( version, 10 ) || 0.0; + + // Caching + + return profileCache[ key ] = { + name: name, + layout: layout, + layoutVersion: layoutversion, + platform: platform, + version: version, + versionBase: ( version !== x ? Math.floor( versionNumber ).toString() : x ), + versionNumber: versionNumber + }; + }, + + /** + * Checks the current browser against a support map object. + * + * Version numbers passed as numeric values will be compared like numbers (1.2 > 1.11). + * Version numbers passed as string values will be compared using a simple component-wise + * 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 + * } + * + * 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 + * } + * } + * + * @param {Object} map Browser support map + * @param {Object} [profile] A client-profile object + * @param {boolean} [exactMatchOnly=false] Only return true if the browser is matched, otherwise + * returns true if the browser is not found. + * + * @return {boolean} The current browser is in the support map + */ + test: function ( map, profile, exactMatchOnly ) { + /*jshint evil:true */ + + var conditions, dir, i, op, val, j, pieceVersion, pieceVal, compare; + profile = $.isPlainObject( profile ) ? profile : $.client.profile(); + if ( map.ltr && map.rtl ) { + dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'; + map = map[dir]; + } + // Check over each browser condition to determine if we are running in a compatible client + if ( typeof map !== 'object' || map[profile.name] === undefined ) { + // Not found, return true if exactMatchOnly not set, false otherwise + return !exactMatchOnly; + } + conditions = map[profile.name]; + if ( conditions === false ) { + // Match no versions + return false; + } + if ( conditions === null ) { + // Match all versions + return true; + } + for ( i = 0; i < conditions.length; i++ ) { + op = conditions[i][0]; + val = conditions[i][1]; + if ( typeof val === 'string' ) { + // Perform a component-wise comparison of versions, similar to PHP's version_compare + // but simpler. '1.11' is larger than '1.2'. + pieceVersion = profile.version.toString().split( '.' ); + pieceVal = val.split( '.' ); + // Extend with zeroes to equal length + while ( pieceVersion.length < pieceVal.length ) { + pieceVersion.push( '0' ); + } + while ( pieceVal.length < pieceVersion.length ) { + pieceVal.push( '0' ); + } + // Compare components + compare = 0; + for ( j = 0; j < pieceVersion.length; j++ ) { + if ( Number( pieceVersion[j] ) < Number( pieceVal[j] ) ) { + compare = -1; + break; + } else if ( Number( pieceVersion[j] ) > Number( pieceVal[j] ) ) { + compare = 1; + break; + } + } + // compare will be -1, 0 or 1, depending on comparison result + if ( !( eval( String( compare + op + '0' ) ) ) ) { + return false; + } + } else if ( typeof val === 'number' ) { + if ( !( eval( 'profile.versionNumber' + op + val ) ) ) { + return false; + } + } + } + + return true; + } + }; +}( jQuery ) ); diff --git a/resources/src/jquery/jquery.client.js b/resources/src/jquery/jquery.client.js deleted file mode 100644 index df0696fac2..0000000000 --- a/resources/src/jquery/jquery.client.js +++ /dev/null @@ -1,308 +0,0 @@ -/** - * User-agent detection - * - * @class jQuery.client - * @singleton - */ -( function ( $ ) { - - /** - * @private - * @property {Object} profileCache Keyed by userAgent string, - * value is the parsed $.client.profile object for that user agent. - */ - var profileCache = {}; - - $.client = { - - /** - * Get an object containing information about the client. - * - * @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, - * } - */ - profile: function ( nav ) { - /*jshint boss: true */ - - if ( nav === undefined ) { - nav = window.navigator; - } - - // Use the cached version if possible - if ( profileCache[ nav.userAgent + '|' + nav.platform ] !== undefined ) { - return profileCache[ nav.userAgent + '|' + nav.platform ]; - } - - var - versionNumber, - key = nav.userAgent + '|' + nav.platform, - - // Configuration - - // Name of browsers or layout engines we don't recognize - uk = 'unknown', - // Generic version digit - x = 'x', - // Strings found in user agent strings that need to be conformed - wildUserAgents = ['Opera', 'Navigator', 'Minefield', 'KHTML', 'Chrome', 'PLAYSTATION 3', 'Iceweasel'], - // Translations for conforming user agent strings - userAgentTranslations = [ - // Tons of browsers lie about being something they are not - [/(Firefox|MSIE|KHTML,?\slike\sGecko|Konqueror)/, ''], - // Chrome lives in the shadow of Safari still - ['Chrome Safari', 'Chrome'], - // KHTML is the layout engine not the browser - LIES! - ['KHTML', 'Konqueror'], - // Firefox nightly builds - ['Minefield', 'Firefox'], - // This helps keep different versions consistent - ['Navigator', 'Netscape'], - // This prevents version extraction issues, otherwise translation would happen later - ['PLAYSTATION 3', 'PS3'] - ], - // Strings which precede a version number in a user agent string - combined and used as - // match 1 in version detection - versionPrefixes = [ - 'camino', 'chrome', 'firefox', 'iceweasel', 'netscape', 'netscape6', 'opera', 'version', 'konqueror', - 'lynx', 'msie', 'safari', 'ps3', 'android' - ], - // Used as matches 2, 3 and 4 in version extraction - 3 is used as actual version number - versionSuffix = '(\\/|\\;?\\s|)([a-z0-9\\.\\+]*?)(\\;|dev|rel|\\)|\\s|$)', - // Names of known browsers - names = [ - 'camino', 'chrome', 'firefox', 'iceweasel', 'netscape', 'konqueror', 'lynx', 'msie', 'opera', - 'safari', 'ipod', 'iphone', 'blackberry', 'ps3', 'rekonq', 'android' - ], - // Tanslations for conforming browser names - nameTranslations = [], - // Names of known layout engines - layouts = ['gecko', 'konqueror', 'msie', 'trident', 'edge', 'opera', 'webkit'], - // Translations for conforming layout names - layoutTranslations = [ ['konqueror', 'khtml'], ['msie', 'trident'], ['opera', 'presto'] ], - // Names of supported layout engines for version number - layoutVersions = ['applewebkit', 'gecko', 'trident', 'edge'], - // Names of known operating systems - platforms = ['win', 'wow64', 'mac', 'linux', 'sunos', 'solaris', 'iphone'], - // Translations for conforming operating system names - platformTranslations = [ ['sunos', 'solaris'], ['wow64', 'win'] ], - - /** - * Performs multiple replacements on a string - * @ignore - */ - translate = function ( source, translations ) { - var i; - for ( i = 0; i < translations.length; i++ ) { - source = source.replace( translations[i][0], translations[i][1] ); - } - return source; - }, - - // Pre-processing - - ua = nav.userAgent, - match, - name = uk, - layout = uk, - layoutversion = uk, - platform = uk, - version = x; - - if ( match = new RegExp( '(' + wildUserAgents.join( '|' ) + ')' ).exec( ua ) ) { - // Takes a userAgent string and translates given text into something we can more easily work with - ua = translate( ua, userAgentTranslations ); - } - // Everything will be in lowercase from now on - ua = ua.toLowerCase(); - - // Extraction - - if ( match = new RegExp( '(' + names.join( '|' ) + ')' ).exec( ua ) ) { - name = translate( match[1], nameTranslations ); - } - if ( match = new RegExp( '(' + layouts.join( '|' ) + ')' ).exec( ua ) ) { - layout = translate( match[1], layoutTranslations ); - } - if ( match = new RegExp( '(' + layoutVersions.join( '|' ) + ')\\\/(\\d+)').exec( ua ) ) { - layoutversion = parseInt( match[2], 10 ); - } - if ( match = new RegExp( '(' + platforms.join( '|' ) + ')' ).exec( nav.platform.toLowerCase() ) ) { - platform = translate( match[1], platformTranslations ); - } - if ( match = new RegExp( '(' + versionPrefixes.join( '|' ) + ')' + versionSuffix ).exec( ua ) ) { - version = match[3]; - } - - // Edge Cases -- did I mention about how user agent string lie? - - // Decode Safari's crazy 400+ version numbers - if ( name === 'safari' && version > 400 ) { - version = '2.0'; - } - // Expose Opera 10's lies about being Opera 9.8 - if ( name === 'opera' && version >= 9.8 ) { - match = ua.match( /\bversion\/([0-9\.]*)/ ); - if ( match && match[1] ) { - version = match[1]; - } else { - version = '10'; - } - } - // And Opera 15's lies about being Chrome - if ( name === 'chrome' && ( match = ua.match( /\bopr\/([0-9\.]*)/ ) ) ) { - if ( match[1] ) { - name = 'opera'; - version = match[1]; - } - } - // And IE 11's lies about being not being IE - if ( layout === 'trident' && layoutversion >= 7 && ( match = ua.match( /\brv[ :\/]([0-9\.]*)/ ) ) ) { - if ( match[1] ) { - name = 'msie'; - version = match[1]; - } - } - // And IE 12's different lies about not being IE - if ( name === 'chrome' && ( match = ua.match( /\bedge\/([0-9\.]*)/ ) ) ) { - name = 'msie'; - version = match[1]; - layout = 'edge'; - layoutversion = parseInt( match[1], 10 ); - } - // And Amazon Silk's lies about being Android on mobile or Safari on desktop - if ( match = ua.match( /\bsilk\/([0-9.\-_]*)/ ) ) { - if ( match[1] ) { - name = 'silk'; - version = match[1]; - } - } - - versionNumber = parseFloat( version, 10 ) || 0.0; - - // Caching - - return profileCache[ key ] = { - name: name, - layout: layout, - layoutVersion: layoutversion, - platform: platform, - version: version, - versionBase: ( version !== x ? Math.floor( versionNumber ).toString() : x ), - versionNumber: versionNumber - }; - }, - - /** - * Checks the current browser against a support map object. - * - * Version numbers passed as numeric values will be compared like numbers (1.2 > 1.11). - * Version numbers passed as string values will be compared using a simple component-wise - * 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 - * } - * - * 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 - * } - * } - * - * @param {Object} map Browser support map - * @param {Object} [profile] A client-profile object - * @param {boolean} [exactMatchOnly=false] Only return true if the browser is matched, otherwise - * returns true if the browser is not found. - * - * @return {boolean} The current browser is in the support map - */ - test: function ( map, profile, exactMatchOnly ) { - /*jshint evil: true */ - - var conditions, dir, i, op, val, j, pieceVersion, pieceVal, compare; - profile = $.isPlainObject( profile ) ? profile : $.client.profile(); - if ( map.ltr && map.rtl ) { - dir = $( 'body' ).is( '.rtl' ) ? 'rtl' : 'ltr'; - map = map[dir]; - } - // Check over each browser condition to determine if we are running in a compatible client - if ( typeof map !== 'object' || map[profile.name] === undefined ) { - // Not found, return true if exactMatchOnly not set, false otherwise - return !exactMatchOnly; - } - conditions = map[profile.name]; - if ( conditions === false ) { - // Match no versions - return false; - } - if ( conditions === null ) { - // Match all versions - return true; - } - for ( i = 0; i < conditions.length; i++ ) { - op = conditions[i][0]; - val = conditions[i][1]; - if ( typeof val === 'string' ) { - // Perform a component-wise comparison of versions, similar to PHP's version_compare - // but simpler. '1.11' is larger than '1.2'. - pieceVersion = profile.version.toString().split( '.' ); - pieceVal = val.split( '.' ); - // Extend with zeroes to equal length - while ( pieceVersion.length < pieceVal.length ) { - pieceVersion.push( '0' ); - } - while ( pieceVal.length < pieceVersion.length ) { - pieceVal.push( '0' ); - } - // Compare components - compare = 0; - for ( j = 0; j < pieceVersion.length; j++ ) { - if ( Number( pieceVersion[j] ) < Number( pieceVal[j] ) ) { - compare = -1; - break; - } else if ( Number( pieceVersion[j] ) > Number( pieceVal[j] ) ) { - compare = 1; - break; - } - } - // compare will be -1, 0 or 1, depending on comparison result - if ( !( eval( String( compare + op + '0' ) ) ) ) { - return false; - } - } else if ( typeof val === 'number' ) { - if ( !( eval( 'profile.versionNumber' + op + val ) ) ) { - return false; - } - } - } - - return true; - } - }; -}( jQuery ) ); diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index 4bcd8149ef..494727a1e1 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -48,7 +48,6 @@ return array( 'tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js', 'tests/qunit/suites/resources/jquery/jquery.byteLength.test.js', 'tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js', - 'tests/qunit/suites/resources/jquery/jquery.client.test.js', 'tests/qunit/suites/resources/jquery/jquery.color.test.js', 'tests/qunit/suites/resources/jquery/jquery.colorUtil.test.js', 'tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js', @@ -86,7 +85,6 @@ return array( 'jquery.autoEllipsis', 'jquery.byteLength', 'jquery.byteLimit', - 'jquery.client', 'jquery.color', 'jquery.colorUtil', 'jquery.getAttrs', diff --git a/tests/qunit/suites/resources/jquery/jquery.client.test.js b/tests/qunit/suites/resources/jquery/jquery.client.test.js deleted file mode 100644 index ee0f060cfa..0000000000 --- a/tests/qunit/suites/resources/jquery/jquery.client.test.js +++ /dev/null @@ -1,656 +0,0 @@ -( function ( $ ) { - - QUnit.module( 'jquery.client', QUnit.newMwEnvironment() ); - - var uacount = 0, - // Object keyed by userAgent. Value is an array (human-readable name, client-profile object, navigator.platform value) - uas = { - // Internet Explorer 6 - // Internet Explorer 7 - 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)': { - title: 'Internet Explorer 7', - platform: 'Win32', - profile: { - name: 'msie', - layout: 'trident', - layoutVersion: 'unknown', - platform: 'win', - version: '7.0', - versionBase: '7', - versionNumber: 7 - }, - wikiEditor: { - ltr: true, - rtl: false - } - }, - // Internet Explorer 8 - // Internet Explorer 9 - // Internet Explorer 10 - 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)': { - title: 'Internet Explorer 10', - platform: 'Win32', - profile: { - name: 'msie', - layout: 'trident', - layoutVersion: 6, - platform: 'win', - version: '10.0', - versionBase: '10', - versionNumber: 10 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Internet Explorer 11 - 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko': { - title: 'Internet Explorer 11', - platform: 'Win32', - profile: { - name: 'msie', - layout: 'trident', - layoutVersion: 7, - platform: 'win', - version: '11.0', - versionBase: '11', - versionNumber: 11 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Internet Explorer 11 - Windows 8.1 x64 Modern UI - 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; rv:11.0) like Gecko': { - title: 'Internet Explorer 11', - platform: 'Win64', - profile: { - name: 'msie', - layout: 'trident', - layoutVersion: 7, - platform: 'win', - version: '11.0', - versionBase: '11', - versionNumber: 11 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Internet Explorer 11 - Windows 8.1 x64 desktop UI - 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko': { - title: 'Internet Explorer 11', - platform: 'WOW64', - profile: { - name: 'msie', - layout: 'trident', - layoutVersion: 7, - platform: 'win', - version: '11.0', - versionBase: '11', - versionNumber: 11 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Internet Explorer 12 - 'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 Edge/12.0': { - title: 'Internet Explorer 12', - platform: 'WOW64', - profile: { - name: 'msie', - layout: 'edge', - layoutVersion: 12, - platform: 'win', - version: '12.0', - versionBase: '12', - versionNumber: 12 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Firefox 2 - // Firefox 3.5 - 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.19) Gecko/20110420 Firefox/3.5.19': { - title: 'Firefox 3.5', - platform: 'MacIntel', - profile: { - name: 'firefox', - layout: 'gecko', - layoutVersion: 20110420, - platform: 'mac', - version: '3.5.19', - versionBase: '3', - versionNumber: 3.5 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Firefox 3.6 - 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110422 Ubuntu/10.10 (maverick) Firefox/3.6.17': { - title: 'Firefox 3.6', - platform: 'Linux i686', - profile: { - name: 'firefox', - layout: 'gecko', - layoutVersion: 20110422, - platform: 'linux', - version: '3.6.17', - versionBase: '3', - versionNumber: 3.6 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Firefox 4 - 'Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1': { - title: 'Firefox 4', - platform: 'Win32', - profile: { - name: 'firefox', - layout: 'gecko', - layoutVersion: 20100101, - platform: 'win', - version: '4.0.1', - versionBase: '4', - versionNumber: 4 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Firefox 10 nightly build - 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0a1) Gecko/20111103 Firefox/10.0a1': { - title: 'Firefox 10 nightly', - platform: 'Linux', - profile: { - name: 'firefox', - layout: 'gecko', - layoutVersion: 20111103, - platform: 'linux', - version: '10.0a1', - versionBase: '10', - versionNumber: 10 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Iceweasel 10.0.6 - 'Mozilla/5.0 (X11; Linux i686; rv:10.0.6) Gecko/20100101 Iceweasel/10.0.6': { - title: 'Iceweasel 10.0.6', - platform: 'Linux', - profile: { - name: 'iceweasel', - layout: 'gecko', - layoutVersion: 20100101, - platform: 'linux', - version: '10.0.6', - versionBase: '10', - versionNumber: 10 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Iceweasel 15.0.1 - 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1': { - title: 'Iceweasel 15.0.1', - platform: 'Linux', - profile: { - name: 'iceweasel', - layout: 'gecko', - layoutVersion: 20100101, - platform: 'linux', - version: '15.0.1', - versionBase: '15', - versionNumber: 15 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Firefox 5 - // Safari 3 - // Safari 4 - 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; nl-nl) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': { - title: 'Safari 4', - platform: 'MacIntel', - profile: { - name: 'safari', - layout: 'webkit', - layoutVersion: 531, - platform: 'mac', - version: '4.0.5', - versionBase: '4', - versionNumber: 4 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - 'Mozilla/5.0 (Windows; U; Windows NT 6.0; cs-CZ) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7': { - title: 'Safari 4', - platform: 'Win32', - profile: { - name: 'safari', - layout: 'webkit', - layoutVersion: 533, - platform: 'win', - version: '4.0.5', - versionBase: '4', - versionNumber: 4 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Safari 5 - // Safari 6 - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.29.13 (KHTML, like Gecko) Version/6.0.4 Safari/536.29.13': { - title: 'Safari 6', - platform: 'MacIntel', - profile: { - name: 'safari', - layout: 'webkit', - layoutVersion: 536, - platform: 'mac', - version: '6.0.4', - versionBase: '6', - versionNumber: 6 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Safari 6.0.5+ (doesn't have the comma in "KHTML, like Gecko") - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1': { - title: 'Safari 6', - platform: 'MacIntel', - profile: { - name: 'safari', - layout: 'webkit', - layoutVersion: 536, - platform: 'mac', - version: '6.0.5', - versionBase: '6', - versionNumber: 6 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Opera 10+ - 'Opera/9.80 (Windows NT 5.1)': { - title: 'Opera 10+ (exact version unspecified)', - platform: 'Win32', - profile: { - name: 'opera', - layout: 'presto', - layoutVersion: 'unknown', - platform: 'win', - version: '10', - versionBase: '10', - versionNumber: 10 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Opera 12 - 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.11': { - title: 'Opera 12', - platform: 'Win32', - profile: { - name: 'opera', - layout: 'presto', - layoutVersion: 'unknown', - platform: 'win', - version: '12.11', - versionBase: '12', - versionNumber: 12.11 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Opera 15 (WebKit-based) - 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.130': { - title: 'Opera 15', - platform: 'Win32', - profile: { - name: 'opera', - layout: 'webkit', - layoutVersion: 537, - platform: 'win', - version: '15.0.1147.130', - versionBase: '15', - versionNumber: 15 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Chrome 5 - // Chrome 6 - // Chrome 7 - // Chrome 8 - // Chrome 9 - // Chrome 10 - // Chrome 11 - // Chrome 12 - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30': { - title: 'Chrome 12', - platform: 'MacIntel', - profile: { - name: 'chrome', - layout: 'webkit', - layoutVersion: 534, - platform: 'mac', - version: '12.0.742.112', - versionBase: '12', - versionNumber: 12 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.68 Safari/534.30': { - title: 'Chrome 12', - platform: 'Linux i686', - profile: { - name: 'chrome', - layout: 'webkit', - layoutVersion: 534, - platform: 'linux', - version: '12.0.742.68', - versionBase: '12', - versionNumber: 12 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Android WebKit Browser 2.3 - 'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1': { - title: 'Android WebKit Browser 2.3', - platform: 'Linux armv7l', - profile: { - name: 'android', - layout: 'webkit', - layoutVersion: 533, - platform: 'linux', - version: '2.3.5', - versionBase: '2', - versionNumber: 2.3 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Rekonq (bug 34924) - 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) rekonq Safari/534.34': { - title: 'Rekonq', - platform: 'Linux i686', - profile: { - name: 'rekonq', - layout: 'webkit', - layoutVersion: 534, - platform: 'linux', - version: '534.34', - versionBase: '534', - versionNumber: 534.34 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - // Konqueror - 'Mozilla/5.0 (X11; Linux i686) KHTML/4.9.1 (like Gecko) Konqueror/4.9': { - title: 'Konqueror', - platform: 'Linux i686', - profile: { - name: 'konqueror', - layout: 'khtml', - layoutVersion: 'unknown', - platform: 'linux', - version: '4.9.1', - versionBase: '4', - versionNumber: 4.9 - }, - wikiEditor: { - // '4.9' is less than '4.11'. - ltr: false, - rtl: false - }, - wikiEditorLegacy: { - // The check is missing in legacyTestMap - ltr: true, - rtl: true - } - }, - // Amazon Silk - 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.13.81_10003810) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true': { - title: 'Silk', - platform: 'Desktop', - profile: { - name: 'silk', - layout: 'webkit', - layoutVersion: 533, - platform: 'unknown', - version: '1.0.13.81_10003810', - versionBase: '1', - versionNumber: 1 - }, - wikiEditor: { - ltr: true, - rtl: true - } - }, - 'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.1 Mobile Safari/535.19 Silk-Accelerated=true': { - title: 'Silk', - platform: 'Mobile', - profile: { - name: 'silk', - layout: 'webkit', - layoutVersion: 535, - platform: 'unknown', - version: '2.1', - versionBase: '2', - versionNumber: 2.1 - }, - wikiEditor: { - ltr: true, - rtl: true - } - } - }, - testMap = { - // Example from WikiEditor, modified to provide version identifiers as strings and with - // Konqueror 4.11 check added. - 'ltr': { - 'msie': [['>=', '7.0']], - 'firefox': [['>=', '2']], - 'opera': [['>=', '9.6']], - 'safari': [['>=', '3']], - 'chrome': [['>=', '3']], - 'netscape': [['>=', '9']], - 'konqueror': [['>=', '4.11']], - 'blackberry': false, - 'ipod': false, - 'iphone': false - }, - 'rtl': { - 'msie': [['>=', '8']], - 'firefox': [['>=', '2']], - 'opera': [['>=', '9.6']], - 'safari': [['>=', '3']], - 'chrome': [['>=', '3']], - 'netscape': [['>=', '9']], - 'konqueror': [['>=', '4.11']], - 'blackberry': false, - 'ipod': false, - 'iphone': false - } - }, - legacyTestMap = { - // Original example from WikiEditor. - // This is using the old, but still supported way of providing version identifiers as numbers - // instead of strings; with this method, 4.9 would be considered larger than 4.11. - 'ltr': { - 'msie': [['>=', 7.0]], - 'firefox': [['>=', 2]], - 'opera': [['>=', 9.6]], - 'safari': [['>=', 3]], - 'chrome': [['>=', 3]], - 'netscape': [['>=', 9]], - 'blackberry': false, - 'ipod': false, - 'iphone': false - }, - 'rtl': { - 'msie': [['>=', 8]], - 'firefox': [['>=', 2]], - 'opera': [['>=', 9.6]], - 'safari': [['>=', 3]], - 'chrome': [['>=', 3]], - 'netscape': [['>=', 9]], - 'blackberry': false, - 'ipod': false, - 'iphone': false - } - } - ; - - // Count test cases - $.each( uas, function () { - uacount++; - } ); - - QUnit.test( 'profile( navObject )', 7, function ( assert ) { - var p = $.client.profile(); - - function unknownOrType( val, type, summary ) { - assert.ok( typeof val === type || val === 'unknown', summary ); - } - - assert.equal( typeof p, 'object', 'profile returns an object' ); - unknownOrType( p.layout, 'string', 'p.layout is a string (or "unknown")' ); - unknownOrType( p.layoutVersion, 'number', 'p.layoutVersion is a number (or "unknown")' ); - unknownOrType( p.platform, 'string', 'p.platform is a string (or "unknown")' ); - unknownOrType( p.version, 'string', 'p.version is a string (or "unknown")' ); - unknownOrType( p.versionBase, 'string', 'p.versionBase is a string (or "unknown")' ); - assert.equal( typeof p.versionNumber, 'number', 'p.versionNumber is a number' ); - } ); - - QUnit.test( 'profile( navObject ) - samples', uacount, function ( assert ) { - // Loop through and run tests - $.each( uas, function ( rawUserAgent, data ) { - // Generate a client profile object and compare recursively - var ret = $.client.profile( { - userAgent: rawUserAgent, - platform: data.platform - } ); - assert.deepEqual( ret, data.profile, 'Client profile support check for ' + data.title + ' (' + data.platform + '): ' + rawUserAgent ); - } ); - } ); - - QUnit.test( 'test( testMap )', 4, function ( assert ) { - // .test() uses eval, make sure no exceptions are thrown - // then do a basic return value type check - var testMatch = $.client.test( testMap ), - ie7Profile = $.client.profile( { - 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)', - 'platform': '' - } ); - - assert.equal( typeof testMatch, 'boolean', 'map with ltr/rtl split returns a boolean value' ); - - testMatch = $.client.test( testMap.ltr ); - - assert.equal( typeof testMatch, 'boolean', 'simple map (without ltr/rtl split) returns a boolean value' ); - - assert.equal( $.client.test( { - 'msie': null - }, ie7Profile ), true, 'returns true if any version of a browser are allowed (null)' ); - - assert.equal( $.client.test( { - 'msie': false - }, ie7Profile ), false, 'returns false if all versions of a browser are not allowed (false)' ); - } ); - - QUnit.test( 'test( testMap, exactMatchOnly )', 2, function ( assert ) { - var ie7Profile = $.client.profile( { - 'userAgent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)', - 'platform': '' - } ); - - assert.equal( $.client.test( { - 'firefox': [['>=', 2]] - }, ie7Profile, false ), true, 'returns true if browser not found and exactMatchOnly not set' ); - - assert.equal( $.client.test( { - 'firefox': [['>=', 2]] - }, ie7Profile, true ), false, 'returns false if browser not found and exactMatchOnly is set' ); - } ); - - QUnit.test( 'test( testMap ), test( legacyTestMap ) - WikiEditor sample', uacount * 2 * 2, function ( assert ) { - var $body = $( 'body' ), - bodyClasses = $body.attr( 'class' ); - - // Loop through and run tests - $.each( uas, function ( agent, data ) { - $.each( ['ltr', 'rtl'], function ( i, dir ) { - var profile, testMatch, legacyTestMatch; - $body.removeClass( 'ltr rtl' ).addClass( dir ); - profile = $.client.profile( { - userAgent: agent, - platform: data.platform - } ); - testMatch = $.client.test( testMap, profile ); - legacyTestMatch = $.client.test( legacyTestMap, profile ); - $body.removeClass( dir ); - - assert.equal( - testMatch, - data.wikiEditor[dir], - 'testing comparison based on ' + dir + ', ' + agent - ); - assert.equal( - legacyTestMatch, - data.wikiEditorLegacy ? data.wikiEditorLegacy[dir] : data.wikiEditor[dir], - 'testing comparison based on ' + dir + ', ' + agent + ' (legacyTestMap)' - ); - } ); - } ); - - // Restore body classes - $body.attr( 'class', bodyClasses ); - } ); -}( jQuery ) );