Created
February 3, 2011 22:16
-
-
Save Akkuma/810342 to your computer and use it in GitHub Desktop.
Updated jQuery Browser to take browsers with a version number > 9 into account and use opera's built-in .version over regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
jQuery Browser Plugin | |
* Version 2.4 | |
* 2010-02-03 | |
* URL: http://jquery.thewikies.com/browser | |
* Description: jQuery Browser Plugin extends browser detection capabilities and can assign browser selectors to CSS classes. | |
* Author: Nate Cavanaugh, Minhchau Dang, Jonathan Neal, & Gregory Waxman | |
* Copyright: Copyright (c) 2008 Jonathan Neal under dual MIT/GPL license. | |
* JSLint: This javascript file passes JSLint verification. | |
*//*jslint | |
bitwise: true, | |
browser: true, | |
eqeqeq: true, | |
forin: true, | |
nomen: true, | |
plusplus: true, | |
undef: true, | |
white: true | |
*//*global | |
jQuery | |
*/ | |
(function ($) { | |
$.browserTest = function (a, z) { | |
var u = 'unknown', | |
x = 'X', | |
m = function (r, h) { | |
for (var i = 0; i < h.length; i = i + 1) { | |
r = r.replace(h[i][0], h[i][1]); | |
} | |
return r; | |
}, c = function (i, a, b, c) { | |
var r = { | |
name: m((a.exec(i) || [u, u])[1], b) | |
}; | |
r[r.name] = true; | |
if (!r.opera) { | |
r.version = (c.exec(i) || [x, x, x, x])[3]; | |
} | |
else { | |
r.version = window.opera.version(); | |
} | |
if (/safari/.test(r.name) && r.version > 400) { | |
r.version = '2.0'; | |
} | |
else if (r.name === 'presto') { | |
r.version = ($.browser.version > 9.27) ? 'futhark' : 'linear_b'; | |
} | |
r.versionNumber = parseFloat(r.version, 10) || 0; | |
var minorStart = 1; | |
if (r.versionNumber < 100 && r.versionNumber > 9) { | |
minorStart = 2; | |
} | |
r.versionX = (r.version !== x) ? r.version.substr(0, minorStart) : x; | |
r.className = r.name + r.versionX; | |
return r; | |
}; | |
a = (/Opera|Navigator|Minefield|KHTML|Chrome/.test(a) ? m(a, [ | |
[/(Firefox|MSIE|KHTML,\slike\sGecko|Konqueror)/, ''], | |
['Chrome Safari', 'Chrome'], | |
['KHTML', 'Konqueror'], | |
['Minefield', 'Firefox'], | |
['Navigator', 'Netscape'] | |
]) : a).toLowerCase(); | |
$.browser = $.extend((!z) ? $.browser : {}, c(a, /(camino|chrome|firefox|netscape|konqueror|lynx|msie|opera|safari)/, [], /(camino|chrome|firefox|netscape|netscape6|opera|version|konqueror|lynx|msie|safari)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/)); | |
$.layout = c(a, /(gecko|konqueror|msie|opera|webkit)/, [ | |
['konqueror', 'khtml'], | |
['msie', 'trident'], | |
['opera', 'presto'] | |
], /(applewebkit|rv|konqueror|msie)(\:|\/|\s)([a-z0-9\.]*?)(\;|\)|\s)/); | |
$.os = { | |
name: (/(win|mac|linux|sunos|solaris|iphone)/.exec(navigator.platform.toLowerCase()) || [u])[0].replace('sunos', 'solaris') | |
}; | |
if (!z) { | |
$('html').addClass([$.os.name, $.browser.name, $.browser.className, $.layout.name, $.layout.className].join(' ')); | |
} | |
}; | |
$.browserTest(navigator.userAgent); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in line 56 there is a missing ";" - with that it is working great, thanks!
the script works with jQuery 1.5.1, too.
Is there a possibility to detect wether the visitor uses firefox 3.0, 3.5 or 3.6 ?