Improve user agent matching code in PaperScript.

Fixes #511.
This commit is contained in:
Jürg Lehni 2014-08-20 18:54:00 +02:00
parent 88c035eb95
commit 4b19f99183

View file

@ -25,17 +25,27 @@ Base.exports.PaperScript = (function() {
/*#*/ if (__options.environment == 'browser') { /*#*/ if (__options.environment == 'browser') {
// We need some browser info for dealing with source maps and code offsets // We need some browser info for dealing with source maps and code offsets
var ua = navigator.userAgent, var ua = navigator.userAgent,
match = ua.match(/(opera|chrome|safari|firefox|msie|trident)\/?\s*([.\d]+)(?:.*rv\:([.\d]+))?/i) || [], browser = {};
name = match[1].toLowerCase(), // Use replace() to get all matches, and deal with overlaps (e.g. Chrome)
version = match[2]; ua.toLowerCase().replace(
if (name === 'trident') { /(opera|chrome|safari|webkit|firefox|msie|trident)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:([.\d]+))?/g,
version = match[3]; // Use rv: and rename to msie function(all, n, v1, v2, rv) {
name = 'msie'; // Do not set additional browsers once chrome is detected.
} else if (match = ua.match(/version\/([.\d]+)/i)) { if (!browser.chrome) {
version = match[1]; var v = n === 'opera' ? v2 : v1;
} if (n === 'trident') {
var browser = { name: name, version: parseFloat(version) }; // Use rv: and rename to msie
browser[name] = true; v = rv;
n = 'msie';
}
browser.version = parseFloat(v);
browser.name = n;
browser[n] = true;
if (browser.chrome)
delete browser.webkit;
}
}
);
/*#*/ } // __options.environment == 'browser' /*#*/ } // __options.environment == 'browser'
// Operators to overload // Operators to overload
@ -259,7 +269,7 @@ Base.exports.PaperScript = (function() {
// TODO: Verify these browser versions for source map support, and check // TODO: Verify these browser versions for source map support, and check
// other browsers. // other browsers.
if (browser.chrome && version >= 30 if (browser.chrome && version >= 30
|| browser.safari && version >= 7 || browser.webkit && version >= 537.76 // >= Safari 7.0.4
|| browser.firefox && version >= 23) { || browser.firefox && version >= 23) {
var offset = 0; var offset = 0;
if (url === window.location.href) { if (url === window.location.href) {