Documents: Delay error handler

Add a delay to the image error handler attachment code to avoid
triggering a false image error event. This is cause when the error
handler is attached before the image is assigned a src attribute.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-11-30 04:31:59 -04:00
parent ab045c499c
commit 8bf484051e

View File

@@ -63,6 +63,7 @@ class MayanImage {
}
load () {
var self = this;
var container = this.element.parent().parent().parent();
var dataURL = this.element.attr('data-url');
@@ -70,17 +71,19 @@ class MayanImage {
container.html(MayanImage.options.templateInvalidDocument);
} else {
this.element.attr('src', dataURL);
this.element.on('error', function() {
// Check the .complete property to see if it is a real error
// or it was a cached image
if (this.complete === false) {
// It is a cached image, set the src attribute to trigger
// it's display.
this.src = this.src;
} else {
container.html(MayanImage.options.templateInvalidDocument);
}
});
setTimeout(function () {
self.element.on('error', function () {
// Check the .complete property to see if it is a real error
// or it was a cached image
if (this.complete === false) {
// It is a cached image, set the src attribute to trigger
// it's display.
this.src = dataURL;
} else {
container.html(MayanImage.options.templateInvalidDocument);
}
});
}, 1);
}
};
}