diff options
author | Pushkar Joshi | 2012-03-12 15:26:10 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-03-12 15:26:10 -0700 |
commit | 46b2e561fa6ca054cad58e4c372a598bbb7ee2c9 (patch) | |
tree | 38d1c8666098a10078834c1eaac3d455135bee12 /node_modules/montage/require/browser.js | |
parent | 7b4b068cadc0af8ec7e930e1c2b429e945f96984 (diff) | |
parent | 69d90467865a1384725b2301901be2180c5a841f (diff) | |
download | ninja-46b2e561fa6ca054cad58e4c372a598bbb7ee2c9.tar.gz |
Merge branch 'master' into brushtool
Diffstat (limited to 'node_modules/montage/require/browser.js')
-rwxr-xr-x | node_modules/montage/require/browser.js | 90 |
1 files changed, 88 insertions, 2 deletions
diff --git a/node_modules/montage/require/browser.js b/node_modules/montage/require/browser.js index 3fdd58d4..f4a11d97 100755 --- a/node_modules/montage/require/browser.js +++ b/node_modules/montage/require/browser.js | |||
@@ -47,7 +47,9 @@ Require.read = function (url) { | |||
47 | 47 | ||
48 | try { | 48 | try { |
49 | request.open(GET, url, true); | 49 | request.open(GET, url, true); |
50 | request.overrideMimeType(APPLICATION_JAVASCRIPT_MIMETYPE); | 50 | if (request.overrideMimeType) { |
51 | request.overrideMimeType(APPLICATION_JAVASCRIPT_MIMETYPE); | ||
52 | } | ||
51 | request.onreadystatechange = function () { | 53 | request.onreadystatechange = function () { |
52 | if (request.readyState === 4) { | 54 | if (request.readyState === 4) { |
53 | onload(); | 55 | onload(); |
@@ -76,7 +78,7 @@ var globalEval = /*this.execScript ||*/eval; | |||
76 | // For Firebug evaled code isn't debuggable otherwise | 78 | // For Firebug evaled code isn't debuggable otherwise |
77 | // http://code.google.com/p/fbug/issues/detail?id=2198 | 79 | // http://code.google.com/p/fbug/issues/detail?id=2198 |
78 | if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) { | 80 | if (global.navigator && global.navigator.userAgent.indexOf("Firefox") >= 0) { |
79 | globalEval = new Function("evalString", "return eval(evalString)"); | 81 | globalEval = new Function("_", "return eval(_)"); |
80 | } | 82 | } |
81 | 83 | ||
82 | var __FILE__String = "__FILE__", | 84 | var __FILE__String = "__FILE__", |
@@ -89,6 +91,8 @@ Require.Compiler = function (config) { | |||
89 | return function(module) { | 91 | return function(module) { |
90 | if (module.factory || module.text === void 0) | 92 | if (module.factory || module.text === void 0) |
91 | return module; | 93 | return module; |
94 | if (config.define) | ||
95 | throw new Error("Can't use eval."); | ||
92 | 96 | ||
93 | // Here we use a couple tricks to make debugging better in various browsers: | 97 | // Here we use a couple tricks to make debugging better in various browsers: |
94 | // TODO: determine if these are all necessary / the best options | 98 | // TODO: determine if these are all necessary / the best options |
@@ -117,4 +121,86 @@ Require.Compiler = function (config) { | |||
117 | } | 121 | } |
118 | }; | 122 | }; |
119 | 123 | ||
124 | Require.XhrLoader = function (config) { | ||
125 | return function (url, module) { | ||
126 | return Require.read(url) | ||
127 | .then(function (text) { | ||
128 | module.type = "javascript"; | ||
129 | module.text = text; | ||
130 | module.location = url; | ||
131 | }); | ||
132 | }; | ||
133 | }; | ||
134 | |||
135 | var definitions = {}; | ||
136 | var getDefinition = function (hash, id) { | ||
137 | definitions[hash] = definitions[hash] || {}; | ||
138 | definitions[hash][id] = definitions[hash][id] || Promise.defer(); | ||
139 | return definitions[hash][id]; | ||
140 | }; | ||
141 | define = function (hash, id, module) { | ||
142 | getDefinition(hash, id).resolve(module); | ||
143 | }; | ||
144 | |||
145 | Require.ScriptLoader = function (config) { | ||
146 | var hash = config.packageDescription.hash; | ||
147 | return function (location, module) { | ||
148 | return Promise.call(function () { | ||
149 | |||
150 | // short-cut by predefinition | ||
151 | if (definitions[hash] && definitions[hash][module.id]) { | ||
152 | return definitions[hash][module.id].promise; | ||
153 | } | ||
154 | |||
155 | if (/\.js$/.test(location)) { | ||
156 | location = location.replace(/\.js/, ".load.js"); | ||
157 | } else { | ||
158 | location += ".load.js"; | ||
159 | } | ||
160 | |||
161 | var script = document.createElement("script"); | ||
162 | script.onload = function() { | ||
163 | script.parentNode.removeChild(script); | ||
164 | }; | ||
165 | script.onerror = function (error) { | ||
166 | script.parentNode.removeChild(script); | ||
167 | }; | ||
168 | script.src = location; | ||
169 | script.defer = true; | ||
170 | document.getElementsByTagName("head")[0].appendChild(script); | ||
171 | |||
172 | return getDefinition(hash, module.id).promise | ||
173 | }) | ||
174 | .then(function (definition) { | ||
175 | delete definitions[hash][module.id]; | ||
176 | for (var name in definition) { | ||
177 | module[name] = definition[name]; | ||
178 | } | ||
179 | module.location = location; | ||
180 | module.directory = URL.resolve(location, "."); | ||
181 | }); | ||
182 | }; | ||
183 | }; | ||
184 | |||
185 | Require.makeLoader = function (config) { | ||
186 | if (config.define) { | ||
187 | Loader = Require.ScriptLoader; | ||
188 | } else { | ||
189 | Loader = Require.XhrLoader; | ||
190 | } | ||
191 | return Require.MappingsLoader( | ||
192 | config, | ||
193 | Require.ExtensionsLoader( | ||
194 | config, | ||
195 | Require.PathsLoader( | ||
196 | config, | ||
197 | Require.MemoizedLoader( | ||
198 | config, | ||
199 | Loader(config) | ||
200 | ) | ||
201 | ) | ||
202 | ) | ||
203 | ); | ||
204 | }; | ||
205 | |||
120 | }); | 206 | }); |