From 8bde0199101758397cee30e9e23c53f0a2f1141d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 21 Jul 2014 15:59:34 +0200 Subject: [PATCH] FEATURE: grab oneboxed image dimensions to prevent 'jiggles' while loading --- lib/cooked_post_processor.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 675dd69028e..f8bed1bc38d 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -55,7 +55,6 @@ class CookedPostProcessor return if images.blank? images.each do |img| - src, width, height = img["src"], img["width"], img["height"] limit_size!(img) convert_to_link!(img) end @@ -69,11 +68,15 @@ class CookedPostProcessor # minus, data images @doc.css("img[src^='data']") - # minus, image inside oneboxes - @doc.css(".onebox-result img, .onebox img") - + oneboxed_images - # minux, images inside quotes @doc.css(".quote img") end + def oneboxed_images + @doc.css(".onebox-result img, .onebox img") + end + def limit_size!(img) # retrieve the size from # 1) the width/height attributes @@ -131,7 +134,6 @@ class CookedPostProcessor if upload = Upload.get_from_url(src) upload.create_thumbnail!(width, height) - # TODO: optimize_image!(img) end add_lightbox!(img, original_width, original_height, upload) @@ -207,9 +209,11 @@ class CookedPostProcessor invalidate_oneboxes: !!@opts[:invalidate_oneboxes], } - result = Oneboxer.apply(@doc) do |url, element| - Oneboxer.onebox(url, args) - end + # apply oneboxes + Oneboxer.apply(@doc) { |url| Oneboxer.onebox(url, args) } + + # make sure we grab dimensions for oneboxed images + oneboxed_images.each { |img| puts "image: #{img["src"]}"; limit_size!(img) } end def optimize_urls @@ -224,7 +228,6 @@ class CookedPostProcessor end end - def pull_hotlinked_images(bypass_bump = false) # is the job enabled? return unless SiteSetting.download_remote_images_to_local?