Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from chrisbeach/master
Rewrite javascript Promise as callback for IE compatibility
- Loading branch information
Showing
2 changed files
with
19 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
var testImageUrl = function(url) { | ||
return new Promise(function (resolve, reject) { | ||
let timeout = 5000; | ||
let timer, img = new Image(); | ||
img.onerror = img.onabort = function () { | ||
clearTimeout(timer); | ||
resolve("error"); | ||
}; | ||
img.onload = function () { | ||
clearTimeout(timer); | ||
resolve("success"); | ||
}; | ||
timer = setTimeout(function () { | ||
resolve("error"); | ||
}, timeout); | ||
img.src = url; | ||
}); | ||
} | ||
var testImageUrl = function(url, callback) { | ||
let timeout = 5000; | ||
let timer, img = new Image(); | ||
img.onerror = img.onabort = function () { | ||
clearTimeout(timer); | ||
callback(false); | ||
}; | ||
img.onload = function () { | ||
clearTimeout(timer); | ||
callback(true); | ||
}; | ||
timer = setTimeout(function () { | ||
callback(false); | ||
}, timeout); | ||
img.src = url; | ||
}; | ||
|
||
export default testImageUrl |