mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FEATURE: grab oneboxed image dimensions to prevent 'jiggles' while loading
This commit is contained in:
parent
9c2a7f0fd1
commit
8bde019910
1 changed files with 10 additions and 7 deletions
|
@ -55,7 +55,6 @@ class CookedPostProcessor
|
||||||
return if images.blank?
|
return if images.blank?
|
||||||
|
|
||||||
images.each do |img|
|
images.each do |img|
|
||||||
src, width, height = img["src"], img["width"], img["height"]
|
|
||||||
limit_size!(img)
|
limit_size!(img)
|
||||||
convert_to_link!(img)
|
convert_to_link!(img)
|
||||||
end
|
end
|
||||||
|
@ -69,11 +68,15 @@ class CookedPostProcessor
|
||||||
# minus, data images
|
# minus, data images
|
||||||
@doc.css("img[src^='data']") -
|
@doc.css("img[src^='data']") -
|
||||||
# minus, image inside oneboxes
|
# minus, image inside oneboxes
|
||||||
@doc.css(".onebox-result img, .onebox img") -
|
oneboxed_images -
|
||||||
# minux, images inside quotes
|
# minux, images inside quotes
|
||||||
@doc.css(".quote img")
|
@doc.css(".quote img")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def oneboxed_images
|
||||||
|
@doc.css(".onebox-result img, .onebox img")
|
||||||
|
end
|
||||||
|
|
||||||
def limit_size!(img)
|
def limit_size!(img)
|
||||||
# retrieve the size from
|
# retrieve the size from
|
||||||
# 1) the width/height attributes
|
# 1) the width/height attributes
|
||||||
|
@ -131,7 +134,6 @@ class CookedPostProcessor
|
||||||
|
|
||||||
if upload = Upload.get_from_url(src)
|
if upload = Upload.get_from_url(src)
|
||||||
upload.create_thumbnail!(width, height)
|
upload.create_thumbnail!(width, height)
|
||||||
# TODO: optimize_image!(img)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_lightbox!(img, original_width, original_height, upload)
|
add_lightbox!(img, original_width, original_height, upload)
|
||||||
|
@ -207,9 +209,11 @@ class CookedPostProcessor
|
||||||
invalidate_oneboxes: !!@opts[:invalidate_oneboxes],
|
invalidate_oneboxes: !!@opts[:invalidate_oneboxes],
|
||||||
}
|
}
|
||||||
|
|
||||||
result = Oneboxer.apply(@doc) do |url, element|
|
# apply oneboxes
|
||||||
Oneboxer.onebox(url, args)
|
Oneboxer.apply(@doc) { |url| Oneboxer.onebox(url, args) }
|
||||||
end
|
|
||||||
|
# make sure we grab dimensions for oneboxed images
|
||||||
|
oneboxed_images.each { |img| puts "image: #{img["src"]}"; limit_size!(img) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def optimize_urls
|
def optimize_urls
|
||||||
|
@ -224,7 +228,6 @@ class CookedPostProcessor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def pull_hotlinked_images(bypass_bump = false)
|
def pull_hotlinked_images(bypass_bump = false)
|
||||||
# is the job enabled?
|
# is the job enabled?
|
||||||
return unless SiteSetting.download_remote_images_to_local?
|
return unless SiteSetting.download_remote_images_to_local?
|
||||||
|
|
Loading…
Reference in a new issue