From 8bf484051e41bcddec3b8b46e12ff5f4439e382b Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 30 Nov 2018 04:31:59 -0400 Subject: [PATCH] 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 --- .../static/appearance/js/mayan_image.js | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mayan/apps/appearance/static/appearance/js/mayan_image.js b/mayan/apps/appearance/static/appearance/js/mayan_image.js index 869faf547e..16b7544649 100644 --- a/mayan/apps/appearance/static/appearance/js/mayan_image.js +++ b/mayan/apps/appearance/static/appearance/js/mayan_image.js @@ -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); } }; }