aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2010-01-05 17:01:20 -0500
committerjeresig <jeresig@gmail.com>2010-01-05 17:01:20 -0500
commitffb1867a4364ea65e60dad3469e8c8eb420ebcac (patch)
treed1a66984ba540eb235e4f1fc6326201e37f873a2 /src/core.js
parent3f648c4e3abe236b8ec6a19822313be794e5a9df (diff)
downloadjquery-ffb1867a4364ea65e60dad3469e8c8eb420ebcac.tar.gz
jquery-ffb1867a4364ea65e60dad3469e8c8eb420ebcac.zip
Rewrite of jQuery.browser to become engine-centric, rather than browser-centric. Also attempt to determine the engine version in a smarter fashion, less prone to error. Finally, enhanced the test suite with 255 useragent strings from http://user-agent-string.info/download for testing. jQuery.browser.safari is now deprecated, use jQuery.browser.webkit instead.
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/core.js b/src/core.js
index 93f04ec7d..8bd8044db 100644
--- a/src/core.js
+++ b/src/core.js
@@ -33,7 +33,10 @@ var jQuery = function( selector, context ) {
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
// 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?
readyBound = false,
@@ -618,17 +621,42 @@ jQuery.extend({
// Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser
- browser: {
- version: (/.*?(?:firefox|safari|opera|msie)[\/ ]([\d.]+)/.exec(userAgent) || [0,"0"])[1],
- safari: /safari/.test( userAgent ),
- opera: /opera/.test( userAgent ),
- msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
- firefox: /firefox/.test( userAgent )
- }
+ uaMatch: function( ua ) {
+ var ret = { browser: "" };
+
+ ua = ua.toLowerCase();
+
+ 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
-jQuery.browser.mozilla = /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent );
+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;
+}
if ( indexOf ) {
jQuery.inArray = function( elem, array ) {