Commit 0645b71e authored by jeresig's avatar jeresig

Merge branch 'useragent'

parents ff3645ee ffb1867a
...@@ -33,7 +33,10 @@ var jQuery = function( selector, context ) { ...@@ -33,7 +33,10 @@ var jQuery = function( selector, context ) {
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
// Keep a UserAgent string for use with jQuery.browser // Keep a UserAgent string for use with jQuery.browser
userAgent = navigator.userAgent.toLowerCase(), userAgent = navigator.userAgent,
// For matching the engine and version of thte browser
browserMatch,
// Has the ready events already been bound? // Has the ready events already been bound?
readyBound = false, readyBound = false,
...@@ -618,17 +621,42 @@ jQuery.extend({ ...@@ -618,17 +621,42 @@ jQuery.extend({
// Use of jQuery.browser is frowned upon. // Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser // More details: http://docs.jquery.com/Utilities/jQuery.browser
browser: { uaMatch: function( ua ) {
version: (/.*?(?:firefox|safari|opera|msie)[\/ ]([\d.]+)/.exec(userAgent) || [0,"0"])[1], var ret = { browser: "" };
safari: /safari/.test( userAgent ),
opera: /opera/.test( userAgent ), ua = ua.toLowerCase();
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
firefox: /firefox/.test( userAgent ) if ( /webkit/.test( ua ) ) {
} ret = { browser: "webkit", version: /webkit[\/ ]([\w.]+)/ };
} else if ( /opera/.test( ua ) ) {
ret = { browser: "opera", version: /opera[\/ ]([\w.]+)/ };
} else if ( /msie/.test( ua ) ) {
ret = { browser: "msie", version: /msie ([\w.]+)/ };
} else if ( /mozilla/.test( ua ) && !/compatible/.test( ua ) ) {
ret = { browser: "mozilla", version: /rv:([\w.]+)/ };
}
ret.version = (ret.version && ret.version.exec( ua ) || [0, "0"])[1];
return ret;
},
browser: {}
}); });
// Deprecated browserMatch = jQuery.uaMatch( userAgent );
jQuery.browser.mozilla = /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( 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;
}
if ( indexOf ) { if ( indexOf ) {
jQuery.inArray = function( elem, array ) { jQuery.inArray = function( elem, array ) {
......
This diff is collapsed.
...@@ -154,41 +154,27 @@ test("selector state", function() { ...@@ -154,41 +154,27 @@ test("selector state", function() {
); );
}); });
if ( !isLocal ) {
test("browser", function() { test("browser", function() {
expect(13); stop();
var browsers = {
//Internet Explorer jQuery.get("data/ua.txt", function(data){
"Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0", var uas = data.split("\n");
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0", expect( (uas.length - 1) * 2 );
/** Failing #1876
* "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0", jQuery.each(uas, function(){
*/ var parts = this.split("\t");
//Browsers with Gecko engine if ( parts[2] ) {
//Mozilla var ua = jQuery.uaMatch( parts[2] );
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12", equals( ua.browser, parts[0], "Checking browser for " + parts[2] );
//Firefox equals( ua.version, parts[1], "Checking version string for " + parts[2] );
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3", }
//Netscape });
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5",
//Flock start();
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11", });
//Opera browser
"Opera/9.20 (X11; Linux x86_64; U; en)": "9.20",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20",
"Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20",
//WebKit engine
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9",
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8",
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8",
//Other user agent string
"Other browser's user agent 1.0":null
};
for (var i in browsers) {
var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check
var version = v ? v[1] : null;
equals( version, browsers[i], "Checking UA string" );
}
}); });
}
test("noConflict", function() { test("noConflict", function() {
expect(6); expect(6);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment