Skip to content

Commit

Permalink
JSXTransformer respects async attribute
Browse files Browse the repository at this point in the history
Conflicts:
	vendor/browser-transforms.js
  • Loading branch information
syranide committed Aug 14, 2014
1 parent 5ca9e19 commit 079400c
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions vendor/browser-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function run(code, url, options) {
* @param {function} callback Function to call with the content of url
* @internal
*/
function load(url, callback) {
function load(url, successCallback, errorCallback) {
var xhr;
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP')
: new XMLHttpRequest();
Expand All @@ -212,8 +212,9 @@ function load(url, callback) {
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 0 || xhr.status === 200) {
callback(xhr.responseText, url);
successCallback(xhr.responseText);
} else {
errorCallback();
throw new Error("Could not load " + url);
}
}
Expand All @@ -230,21 +231,19 @@ function load(url, callback) {
* @internal
*/
function loadScripts(scripts) {
var result = scripts.map(function() {
return false;
});
var count = result.length;
var result = [];
var count = scripts.length;

function check() {
var script, i;

for (i = 0; i < count; i++) {
script = result[i];

if (script && !script.executed) {
run(script.content, script.url, script.options);
if (script.loaded && !script.executed) {
script.executed = true;
} else if (!script) {
run(script.content, script.url, script.options);
} else if (!script.loaded && !script.error && !script.async) {
break;
}
}
Expand All @@ -258,26 +257,42 @@ function loadScripts(scripts) {
};
}

// script.async is always true for non-javascript script tags
var async = script.hasAttribute('async');

if (script.src) {
load(script.src, function(content, url) {
result[i] = {
executed: false,
content: content,
url: url,
options: options
};
result[i] = {
async: async,
error: false,
executed: false,
content: null,
loaded: false,
url: script.src,
options: options
};

load(script.src, function(content) {
result[i].loaded = true;
result[i].content = content;
check();
}, function() {
result[i].error = true;
check();
});
} else {
result[i] = {
async: async,
error: false,
executed: false,
content: script.innerHTML,
loaded: true,
url: null,
options: options
};
check();
}
});

check();
}

/**
Expand Down

0 comments on commit 079400c

Please sign in to comment.