Skip to content

Commit

Permalink
Update async.js
Browse files Browse the repository at this point in the history
  • Loading branch information
olaferlandsen committed May 17, 2016
1 parent 3c1dfad commit aea327a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Date: 2016-05-01T05:00Z
*/
function async () {
var type,file,options = {},index = 0;
var type,options = {},index = 0;
function _isFunction (object) {
return !!(object && object.constructor && object.call && object.apply);
}
Expand Down Expand Up @@ -62,7 +62,7 @@ function async () {
}

if (type === 'file') {
window._async.file.push(options)
window._async.file.push(options);
} else {
window._async.func.push(options);
}
Expand All @@ -72,7 +72,12 @@ function async () {
// map files
window._async.file.map(function (element) {

var xhr = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" );
var xhr;
if (window.XMLHttpRequest) {
xhr = new window.XMLHttpRequest();
} else {
xhr = new window.ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open('HEAD', element.file, false);
try {
xhr.send();
Expand All @@ -92,8 +97,7 @@ function async () {
script.src= element.file;
if (_propertyExists(element,'success')) {
script.onload = script.onreadystatechange = function() {
var state = this.readyState,
status = true;
var state = this.readyState;
if (state) {
if (state !== 'complete' && state !== 'loaded') {
if (_propertyExists(element,'error')) {
Expand All @@ -107,12 +111,12 @@ function async () {
}

document.getElementsByTagName('head')[0].appendChild(script);
})
});

// map callbacks
window._async.func.map(function (element) {
return element.success.apply(element.success, element.arguments);
})
});
}
};
window.async = async;

0 comments on commit aea327a

Please sign in to comment.