diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index c0cbc424..df7a6683 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -60,16 +60,49 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{ // Assign a unique id to each scope . this._id = PaperScope._id++; PaperScope._scopes[this._id] = this; + var proto = PaperScope.prototype; if (!this.support) { // Set up paper.support, as an object containing properties that // describe the support of various features. var ctx = CanvasProvider.getContext(1, 1); - PaperScope.prototype.support = { + proto.support = { nativeDash: 'setLineDash' in ctx || 'mozDash' in ctx, nativeBlendModes: BlendMode.nativeModes }; CanvasProvider.release(ctx); } + +/*#*/ if (__options.environment == 'browser') { + if (!this.browser) { + var browser = proto.browser = {}; + // Use replace() to get all matches, and deal with Chrome/Webkit + // overlap: + // TODO: Do we need Mozilla next to Firefox? Other than the + // different treatment of the Chrome/Webkit overlap + // here: { chrome: true, webkit: false }, mozilla missing is the + // only difference to jQuery.browser + navigator.userAgent.toLowerCase().replace( + /(opera|chrome|safari|webkit|firefox|msie|trident)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:([.\d]+))?/g, + function(all, n, v1, v2, rv) { + // Do not set additional browsers once chrome is detected. + if (!browser.chrome) { + var v = n === 'opera' ? v2 : v1; + if (n === 'trident') { + // Use rv: and rename to msie + v = rv; + n = 'msie'; + }  + browser.version = v; + browser.versionNumber = parseFloat(v); + browser.name = n; + browser[n] = true; + } + } + ); + if (browser.chrome) + delete browser.webkit; + } +/*#*/ } // __options.environment == 'browser' }, /** diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index dc46f2b4..de76926d 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -22,32 +22,6 @@ Base.exports.PaperScript = (function() { scope = this; /*#*/ include('../../bower_components/acorn/acorn.min.js', { exports: false }); -/*#*/ if (__options.environment == 'browser') { - // We need some browser info for dealing with source maps and code offsets - var ua = navigator.userAgent, - browser = {}; - // Use replace() to get all matches, and deal with overlaps (e.g. Chrome) - ua.toLowerCase().replace( - /(opera|chrome|safari|webkit|firefox|msie|trident)\/?\s*([.\d]+)(?:.*version\/([.\d]+))?(?:.*rv\:([.\d]+))?/g, - function(all, n, v1, v2, rv) { - // Do not set additional browsers once chrome is detected. - if (!browser.chrome) { - var v = n === 'opera' ? v2 : v1; - if (n === 'trident') { - // Use rv: and rename to msie - v = rv; - n = 'msie'; - } - browser.version = parseFloat(v); - browser.name = n; - browser[n] = true; - if (browser.chrome) - delete browser.webkit; - } - } - ); -/*#*/ } // __options.environment == 'browser' - // Operators to overload var binaryOperators = { @@ -264,7 +238,8 @@ Base.exports.PaperScript = (function() { /*#*/ if (__options.environment == 'browser') { // Source-map support: var sourceMap = null, - version = browser.version, + browser = paper.browser, + version = browser.versionNumber, lineBreaks = /\r\n|\n|\r/mg; // TODO: Verify these browser versions for source map support, and check // other browsers. @@ -396,6 +371,7 @@ Base.exports.PaperScript = (function() { if (handlers) code += '\nreturn { ' + handlers + ' };'; /*#*/ if (__options.environment == 'browser') { + var browser = paper.browser; if (browser.chrome || browser.firefox) { // On Firefox, all error numbers inside dynamically compiled code // are relative to the line where the eval / compilation happened.