diff options
author | Eric Guzman | 2012-02-16 14:20:40 -0800 |
---|---|---|
committer | Eric Guzman | 2012-02-16 14:20:40 -0800 |
commit | 6960f62a84b946c92a59e5f5dc537a818f9f62b8 (patch) | |
tree | 49cbff3fdd8dab11846e5a278406915ec0ec1508 /node_modules/montage/require/browser.js | |
parent | 82b1a273219f0ae3d119e156c7acccdbe478f441 (diff) | |
parent | 81942bd52f0713c9ff5d479ebd12fce577f45e45 (diff) | |
download | ninja-6960f62a84b946c92a59e5f5dc537a818f9f62b8.tar.gz |
Merge branch 'refs/heads/master' into PresetsPanel
Diffstat (limited to 'node_modules/montage/require/browser.js')
-rwxr-xr-x | node_modules/montage/require/browser.js | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/node_modules/montage/require/browser.js b/node_modules/montage/require/browser.js index e249d355..3fdd58d4 100755 --- a/node_modules/montage/require/browser.js +++ b/node_modules/montage/require/browser.js | |||
@@ -5,11 +5,13 @@ | |||
5 | </copyright> */ | 5 | </copyright> */ |
6 | bootstrap("require/browser", function (require) { | 6 | bootstrap("require/browser", function (require) { |
7 | 7 | ||
8 | var Require = require("require/require"); | 8 | var Require = require("require/require"), |
9 | var Promise = require("core/promise").Promise; | 9 | Promise = require("core/promise").Promise, |
10 | var URL = require("core/mini-url"); | 10 | URL = require("core/mini-url"), |
11 | 11 | GET = "GET", | |
12 | var global = typeof global !== "undefined" ? global : window; | 12 | APPLICATION_JAVASCRIPT_MIMETYPE = "application/javascript", |
13 | FILE_PROTOCOL = "file:", | ||
14 | global = typeof global !== "undefined" ? global : window; | ||
13 | 15 | ||
14 | Require.getLocation = function() { | 16 | Require.getLocation = function() { |
15 | return URL.resolve(window.location, "."); | 17 | return URL.resolve(window.location, "."); |
@@ -24,7 +26,7 @@ Require.overlays = ["browser", "montage"]; | |||
24 | // http://dl.dropbox.com/u/131998/yui/misc/get/browser-capabilities.html | 26 | // http://dl.dropbox.com/u/131998/yui/misc/get/browser-capabilities.html |
25 | Require.read = function (url) { | 27 | Require.read = function (url) { |
26 | 28 | ||
27 | if (URL.resolve(window.location, url).indexOf("file:") === 0) { | 29 | if (URL.resolve(window.location, url).indexOf(FILE_PROTOCOL) === 0) { |
28 | throw new Error("XHR does not function for file: protocol"); | 30 | throw new Error("XHR does not function for file: protocol"); |
29 | } | 31 | } |
30 | 32 | ||
@@ -44,8 +46,8 @@ Require.read = function (url) { | |||
44 | } | 46 | } |
45 | 47 | ||
46 | try { | 48 | try { |
47 | request.open("GET", url, true); | 49 | request.open(GET, url, true); |
48 | request.overrideMimeType("application/javascript"); | 50 | request.overrideMimeType(APPLICATION_JAVASCRIPT_MIMETYPE); |
49 | request.onreadystatechange = function () { | 51 | request.onreadystatechange = function () { |
50 | if (request.readyState === 4) { | 52 | if (request.readyState === 4) { |
51 | onload(); | 53 | onload(); |
@@ -77,6 +79,12 @@ if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) { | |||
77 | globalEval = new Function("evalString", "return eval(evalString)"); | 79 | globalEval = new Function("evalString", "return eval(evalString)"); |
78 | } | 80 | } |
79 | 81 | ||
82 | var __FILE__String = "__FILE__", | ||
83 | DoubleUnderscoreString = "__" | ||
84 | globalEvalConstantA = "(function ", | ||
85 | globalEvalConstantB = "(require, exports, module) {", | ||
86 | globalEvalConstantC = "//*/\n})\n//@ sourceURL="; | ||
87 | |||
80 | Require.Compiler = function (config) { | 88 | Require.Compiler = function (config) { |
81 | return function(module) { | 89 | return function(module) { |
82 | if (module.factory || module.text === void 0) | 90 | if (module.factory || module.text === void 0) |
@@ -91,10 +99,10 @@ Require.Compiler = function (config) { | |||
91 | // TODO: investigate why this isn't working in Firebug. | 99 | // TODO: investigate why this isn't working in Firebug. |
92 | // 3. set displayName property on the factory function (Safari, Chrome) | 100 | // 3. set displayName property on the factory function (Safari, Chrome) |
93 | 101 | ||
94 | var displayName = "__FILE__"+module.location.replace(/\.\w+$|\W/g, "__"); | 102 | var displayName = __FILE__String+module.location.replace(/\.\w+$|\W/g, DoubleUnderscoreString); |
95 | 103 | ||
96 | try { | 104 | try { |
97 | module.factory = globalEval("(function "+displayName+"(require, exports, module) {"+module.text+"//*/\n})"+"\n//@ sourceURL="+module.location); | 105 | module.factory = globalEval(globalEvalConstantA+displayName+globalEvalConstantB+module.text+globalEvalConstantC+module.location); |
98 | } catch (exception) { | 106 | } catch (exception) { |
99 | throw new SyntaxError("in " + module.location + ": " + exception.message); | 107 | throw new SyntaxError("in " + module.location + ": " + exception.message); |
100 | } | 108 | } |