Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakearchibald/7662e012462c7537a075 to your computer and use it in GitHub Desktop.
Save jakearchibald/7662e012462c7537a075 to your computer and use it in GitHub Desktop.
function thingLoaded() {
console.log('loaded');
}
function thingFailed() {
console.log('failed');
}
function thingOnLoad() {
this.removeEventListener('load', thingOnLoad);
this.removeEventListener('error', thingOnError);
thingLoaded();
}
function thingOnError() {
this.removeEventListener('load', thingOnLoad);
this.removeEventListener('error', thingOnError);
thingFailed();
}
if (thing.complete) {
if (thing.looksSuccessful) {
thingLoaded();
}
else {
thingFailed();
}
}
else {
thing.addEventListener('load', thingOnLoad);
thing.addEventListener('error', thingOnError);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment