From 5a02cd61db118d08fe76f880cf57606b083fcea7 Mon Sep 17 00:00:00 2001 From: 8chan Date: Tue, 10 Jun 2014 18:50:14 +0000 Subject: [PATCH] Fix issue when loading images in Chrome --- js/no-animated-gif.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/no-animated-gif.js b/js/no-animated-gif.js index cfdf757b..36d48954 100644 --- a/js/no-animated-gif.js +++ b/js/no-animated-gif.js @@ -13,7 +13,17 @@ function unanimate_gif(e) { $(e).parent().prepend(c); c.attr('width', $(e).width()); c.attr('height',$(e).height()); - c[0].getContext('2d').drawImage(e, 0, 0, $(e).width(), $(e).height()); + function draw_image() { + c[0].getContext('2d').drawImage(e, 0, 0, $(e).width(), $(e).height()) + }; + + // Fix drawing image before loaded. Note that Chrome needs to check .complete because load() is NOT called if loaded from cache. + if (!e.complete) { + e.onload = draw_image; + } else { + draw_image(); + } + $(e).hide(); }