From 6da27201680bf8495825e5874d14ab5cc61d9477 Mon Sep 17 00:00:00 2001 From: Faldrian Date: Thu, 4 Feb 2016 20:27:48 +0100 Subject: [PATCH] Check for collapsible content_view again after images are loaded --- app/assets/javascripts/app/views/content_view.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/assets/javascripts/app/views/content_view.js b/app/assets/javascripts/app/views/content_view.js index d462dd067..76fb62739 100644 --- a/app/assets/javascripts/app/views/content_view.js +++ b/app/assets/javascripts/app/views/content_view.js @@ -72,6 +72,21 @@ app.views.Content = app.views.Base.extend({ postRenderTemplate : function(){ _.defer(_.bind(this.collapseOversized, this)); + + // run collapseOversized again after all contained images are loaded + var self = this; + _.defer(function() { + self.$("img").each(function() { + this.addEventListener("load", function() { + // only fire if the top of the post is in viewport + var rect = self.el.getBoundingClientRect(); + if(rect.top > 0) { + self.collapseOversized.call(self); + } + }); + }); + }); + var photoAttachments = this.$(".photo_attachments"); if(photoAttachments.length > 0) { new app.views.Gallery({ el: photoAttachments });