@samitouri / QOS-React-2 / commits / 079400c2a6

JSXTransformer respects async attribute

Conflicts: vendor/browser-transforms.js

Andreas Svensson committed Jul 13, 2014 at 23:33 UTC 079400c2a6f5da71c8b0b2546014b5cea264247d
1 file changed +32 -17
vendor/browser-transforms.js
+32 -17
@@ -198,7 +198,7 @@ function run(code, url, options) {
198 * @param {function} callback Function to call with the content of url
199 * @internal
200 */
201 -function load(url, callback) {
201 +function load(url, successCallback, errorCallback) {
202 var xhr;
203 xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
204 : new XMLHttpRequest();
@@ -212,8 +212,9 @@ function load(url, callback) {
212 xhr.onreadystatechange = function() {
213 if (xhr.readyState === 4) {
214 if (xhr.status === 0 || xhr.status === 200) {
215 - callback(xhr.responseText, url);
215 + successCallback(xhr.responseText);
216 } else {
217 + errorCallback();
218 throw new Error("Could not load " + url);
219 }
220 }
@@ -230,10 +231,8 @@ function load(url, callback) {
231 * @internal
232 */
233 function loadScripts(scripts) {
233 - var result = scripts.map(function() {
234 - return false;
235 - });
236 - var count = result.length;
234 + var result = [];
235 + var count = scripts.length;
236
237 function check() {
238 var script, i;
@@ -241,10 +240,10 @@ function loadScripts(scripts) {
240 for (i = 0; i < count; i++) {
241 script = result[i];
242
244 - if (script && !script.executed) {
245 - run(script.content, script.url, script.options);
243 + if (script.loaded && !script.executed) {
244 script.executed = true;
247 - } else if (!script) {
245 + run(script.content, script.url, script.options);
246 + } else if (!script.loaded && !script.error && !script.async) {
247 break;
248 }
249 }
@@ -258,26 +257,42 @@ function loadScripts(scripts) {
257 };
258 }
259
260 + // script.async is always true for non-javascript script tags
261 + var async = script.hasAttribute('async');
262 +
263 if (script.src) {
262 - load(script.src, function(content, url) {
263 - result[i] = {
264 - executed: false,
265 - content: content,
266 - url: url,
267 - options: options
268 - };
264 + result[i] = {
265 + async: async,
266 + error: false,
267 + executed: false,
268 + content: null,
269 + loaded: false,
270 + url: script.src,
271 + options: options
272 + };
273 +
274 + load(script.src, function(content) {
275 + result[i].loaded = true;
276 + result[i].content = content;
277 + check();
278 + }, function() {
279 + result[i].error = true;
280 check();
281 });
282 } else {
283 result[i] = {
284 + async: async,
285 + error: false,
286 executed: false,
287 content: script.innerHTML,
288 + loaded: true,
289 url: null,
290 options: options
291 };
278 - check();
292 }
293 });
294 +
295 + check();
296 }
297
298 /**