diff options
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | grunt.js | 3 | ||||
-rw-r--r-- | src/core.js | 41 | ||||
-rw-r--r-- | src/deprecated.js | 41 | ||||
-rw-r--r-- | test/data/ua.txt | 4 | ||||
-rw-r--r-- | test/index.html | 1 | ||||
-rw-r--r-- | test/unit/ajax.js | 31 | ||||
-rw-r--r-- | test/unit/core.js | 22 | ||||
-rw-r--r-- | test/unit/deprecated.js | 28 |
9 files changed, 100 insertions, 77 deletions
@@ -95,6 +95,12 @@ Exclude **css**: grunt custom:-css ``` +Exclude **deprecated**: + +```bash +grunt custom:-deprecated +``` + Exclude **dimensions**: ```bash @@ -63,6 +63,8 @@ module.exports = function( grunt ) { "src/selector.js", "src/traversing.js", "src/manipulation.js", + + { flag: "deprecated", src: "src/deprecated.js" }, { flag: "css", src: "src/css.js" }, { flag: "ajax", src: "src/ajax.js" }, { flag: "ajax/jsonp", src: "src/ajax/jsonp.js", needs: [ "ajax", "ajax/script" ] }, @@ -71,6 +73,7 @@ module.exports = function( grunt ) { { flag: "effects", src: "src/effects.js", needs: ["css"] }, { flag: "offset", src: "src/offset.js", needs: ["css"] }, { flag: "dimensions", src: "src/dimensions.js", needs: ["css"] }, + "src/exports.js", "src/outro.js" ] diff --git a/src/core.js b/src/core.js index 9558fd060..bf972ed9f 100644 --- a/src/core.js +++ b/src/core.js @@ -30,9 +30,6 @@ var // The deferred used on DOM ready readyList, - // For matching the engine and version of the browser - browserMatch, - // Used for detecting and trimming whitespace core_rnotwhite = /\S/, core_rspace = /\s+/, @@ -53,12 +50,6 @@ var rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g, rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, - // Useragent RegExp - rmsie = /(msie) ([\w.]+)/, - rwebkit = /(webkit)[ \/]([\w.]+)/, - rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/, - ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/, - // Matches dashed string for camelizing rmsPrefix = /^-ms-/, rdashAlpha = /-([\da-z])/gi, @@ -68,9 +59,6 @@ var return ( letter + "" ).toUpperCase(); }, - // Keep a UserAgent string for use with jQuery.browser - userAgent = navigator.userAgent, - // The ready event handler and self cleanup method DOMContentLoaded = function() { if ( document.addEventListener ) { @@ -802,20 +790,6 @@ jQuery.extend({ return ( new Date() ).getTime(); }, - // Use of jQuery.browser is frowned upon. - // More details: http://docs.jquery.com/Utilities/jQuery.browser - uaMatch: function( ua ) { - ua = ua.toLowerCase(); - - var match = rwebkit.exec( ua ) || - ropera.exec( ua ) || - rmsie.exec( ua ) || - ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || - []; - - return { browser: match[1] || "", version: match[2] || "0" }; - }, - sub: function() { function jQuerySub( selector, context ) { return new jQuerySub.fn.init( selector, context ); @@ -835,9 +809,7 @@ jQuery.extend({ jQuerySub.fn.init.prototype = jQuerySub.fn; var rootjQuerySub = jQuerySub(document); return jQuerySub; - }, - - browser: {} + } }); jQuery.ready.promise = function( object ) { @@ -903,16 +875,5 @@ jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" ") class2type[ "[object " + name + "]" ] = name.toLowerCase(); }); -browserMatch = jQuery.uaMatch( userAgent ); -if ( browserMatch.browser ) { - jQuery.browser[ browserMatch.browser ] = true; - jQuery.browser.version = browserMatch.version; -} - -// Deprecated, use jQuery.browser.webkit instead -if ( jQuery.browser.webkit ) { - jQuery.browser.safari = true; -} - // All jQuery objects should point back to these rootjQuery = jQuery(document); diff --git a/src/deprecated.js b/src/deprecated.js new file mode 100644 index 000000000..04bf5bad0 --- /dev/null +++ b/src/deprecated.js @@ -0,0 +1,41 @@ +// Limit scope pollution from any deprecated API +(function() { + +var matched, browser; + +// Use of jQuery.browser is frowned upon. +// More details: http://api.jquery.com/jQuery.browser +// jQuery.uaMatch maintained for back-compat +jQuery.uaMatch = function( ua ) { + ua = ua.toLowerCase(); + + var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || + /(webkit)[ \/]([\w.]+)/.exec( ua ) || + /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || + /(msie) ([\w.]+)/.exec( ua ) || + ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || + []; + + return { + browser: match[ 1 ] || "", + version: match[ 2 ] || "0" + }; +}; + +matched = jQuery.uaMatch( navigator.userAgent ); +browser = {}; + +if ( matched.browser ) { + browser[ matched.browser ] = true; + browser.version = matched.version; +} + +// Deprecated, use jQuery.browser.webkit instead +// Maintained for back-compat only +if ( browser.webkit ) { + browser.safari = true; +} + +jQuery.browser = browser; + +})(); diff --git a/test/data/ua.txt b/test/data/ua.txt index b6a9dff66..95e522e25 100644 --- a/test/data/ua.txt +++ b/test/data/ua.txt @@ -37,8 +37,8 @@ mozilla 1.0.1 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.0.1) G mozilla 1.8.0.10 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.10) Gecko/20070228 Camino/1.0.4 webkit 418.9 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.9 (KHTML, like Gecko, Safari) Safari/419.3 Cheshire/1.0.ALPHA webkit 419 Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/419 (KHTML, like Gecko, Safari/419.3) Cheshire/1.0.ALPHA -webkit 525.19 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.36 Safari/525.19 -webkit 525.19 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19 +chrome 1.0.154.36 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.36 Safari/525.19 +chrome 1.0.154.53 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19 mozilla 1.9.0.10 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2009042815 Firefox/3.0.10 CometBird/3.0.10 mozilla 1.9.0.5 Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2009011615 Firefox/3.0.5 CometBird/3.0.5 msie 7.0 Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Crazy Browser 3.0.0 Beta2) diff --git a/test/index.html b/test/index.html index 9d1e70344..a3a2b6f58 100644 --- a/test/index.html +++ b/test/index.html @@ -49,6 +49,7 @@ <script src="unit/effects.js"></script> <script src="unit/offset.js"></script> <script src="unit/dimensions.js"></script> + <script src="unit/deprecated.js"></script> <script src="unit/exports.js"></script> <script> diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 1293f2c83..e5eae9a47 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -2,6 +2,8 @@ module("ajax", { teardown: moduleTeardown }); if ( jQuery.ajax && ( !isLocal || hasPHP ) ) { +var isOpera = !!window.opera; + test("jQuery.ajax() - success callbacks", function() { expect( 8 ); @@ -381,7 +383,8 @@ test(".ajax() - headers" , function() { headers: requestHeaders, success: function( data , _ , xhr ) { - var tmp = [], i; + var i, emptyHeader, + tmp = []; for ( i in requestHeaders ) { tmp.push( i , ": " , requestHeaders[ i ] , "\n" ); } @@ -390,10 +393,12 @@ test(".ajax() - headers" , function() { strictEqual( data , tmp , "Headers were sent" ); strictEqual( xhr.getResponseHeader( "Sample-Header" ) , "Hello World" , "Sample header received" ); - if ( jQuery.browser.mozilla ) { + + emptyHeader = xhr.getResponseHeader( "Empty-Header" ); + if ( emptyHeader === null ) { ok( true, "Firefox doesn't support empty headers" ); } else { - strictEqual( xhr.getResponseHeader( "Empty-Header" ) , "" , "Empty header received" ); + strictEqual( emptyHeader , "" , "Empty header received" ); } strictEqual( xhr.getResponseHeader( "Sample-Header2" ) , "Hello World 2" , "Second sample header received" ); }, @@ -2124,8 +2129,8 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache cache: cache, success: function(data, status) { if ( data === "FAIL" ) { - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); + ok(isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); + ok(isOpera, "Opera is incapable of doing .setRequestHeader('If-Modified-Since')."); } else { equal(status, "notmodified"); ok(data == null, "response body should be empty"); @@ -2136,8 +2141,8 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache // Do this because opera simply refuses to implement 304 handling :( // A feature-driven way of detecting this would be appreciated // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); - ok(jQuery.browser.opera, "error"); + ok(isOpera, "error"); + ok(isOpera, "error"); start(); } }); @@ -2147,7 +2152,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache // Do this because opera simply refuses to implement 304 handling :( // A feature-driven way of detecting this would be appreciated // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); + ok(isOpera, "error"); start(); } }); @@ -2173,8 +2178,8 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache cache: cache, success: function(data, status) { if ( data === "FAIL" ) { - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); - ok(jQuery.browser.opera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); + ok(isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); + ok(isOpera, "Opera is incapable of doing .setRequestHeader('If-None-Match')."); } else { equal(status, "notmodified"); ok(data == null, "response body should be empty"); @@ -2185,8 +2190,8 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache // Do this because opera simply refuses to implement 304 handling :( // A feature-driven way of detecting this would be appreciated // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); - ok(jQuery.browser.opera, "error"); + ok(isOpera, "error"); + ok(isOpera, "error"); start(); } }); @@ -2195,7 +2200,7 @@ jQuery.each( { " (cache)": true, " (no cache)": false }, function( label, cache // Do this because opera simply refuses to implement 304 handling :( // A feature-driven way of detecting this would be appreciated // See: http://gist.github.com/599419 - ok(jQuery.browser.opera, "error"); + ok(isOpera, "error"); start(); } }); diff --git a/test/unit/core.js b/test/unit/core.js index f2f5f41c4..7b2ad27e7 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -236,28 +236,6 @@ test( "globalEval", function() { window.globalEvalTest = undefined; }); -if ( jQuery.get && !isLocal ) { - test("browser", function() { - stop(); - - jQuery.get("data/ua.txt", function(data){ - var uas = data.split("\n"); - expect( (uas.length - 1) * 2 ); - - jQuery.each(uas, function(){ - var parts = this.split("\t"); - if ( parts[2] ) { - var ua = jQuery.uaMatch( parts[2] ); - equal( ua.browser, parts[0], "Checking browser for " + parts[2] ); - equal( ua.version, parts[1], "Checking version string for " + parts[2] ); - } - }); - - start(); - }); - }); -} - test("noConflict", function() { expect(7); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js new file mode 100644 index 000000000..0f77040c1 --- /dev/null +++ b/test/unit/deprecated.js @@ -0,0 +1,28 @@ +module("deprecated"); + +// Start jQuery.browser tests +if ( jQuery.browser && jQuery.uaMatch ) { + if ( jQuery.get && !isLocal ) { + asyncTest( "browser", function() { + jQuery.get( "data/ua.txt", function( data ) { + var uas = data.split( "\n" ); + expect( (uas.length - 1) * 2 ); + + jQuery.each(uas, function() { + var parts = this.split( "\t" ), + agent = parts[2], + ua; + + if ( agent ) { + ua = jQuery.uaMatch( agent ); + equal( ua.browser, parts[0], "browser (" + agent + ")" ); + equal( ua.version, parts[1], "version (" + agent + ")" ); + } + }); + + start(); + }); + }); + } +} +// End of jQuery.browser tests |