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:
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user