FIX: Disable lightboxing of animated images (#13099)

This commit is contained in:
Penar Musaraj
2021-05-20 15:19:44 -04:00
committed by GitHub
parent f165f98cf7
commit 29f3621f45
3 changed files with 12 additions and 9 deletions

View File

@ -353,13 +353,13 @@ class CookedPostProcessor
unless @disable_loading_image unless @disable_loading_image
upload.create_thumbnail!(LOADING_SIZE, LOADING_SIZE, format: 'png', colors: LOADING_COLORS) upload.create_thumbnail!(LOADING_SIZE, LOADING_SIZE, format: 'png', colors: LOADING_COLORS)
end end
end
return if upload.animated?
if img.ancestors('.onebox, .onebox-body, .quote').blank? && !img.classes.include?("onebox") if img.ancestors('.onebox, .onebox-body, .quote').blank? && !img.classes.include?("onebox")
add_lightbox!(img, original_width, original_height, upload, cropped: crop) add_lightbox!(img, original_width, original_height, upload, cropped: crop)
end end
if upload.present?
optimize_image!(img, upload, cropped: crop) optimize_image!(img, upload, cropped: crop)
end end
end end
@ -390,7 +390,7 @@ class CookedPostProcessor
w, h = img["width"].to_i, img["height"].to_i w, h = img["width"].to_i, img["height"].to_i
# note: optimize_urls cooks the src and data-small-upload further after this # note: optimize_urls cooks the src and data-small-upload further after this
thumbnail = !upload.animated && upload.thumbnail(w, h) thumbnail = upload.thumbnail(w, h)
if thumbnail && thumbnail.filesize.to_i < upload.filesize if thumbnail && thumbnail.filesize.to_i < upload.filesize
img["src"] = thumbnail.url img["src"] = thumbnail.url

View File

@ -973,7 +973,10 @@ describe CookedPostProcessor do
expect(doc.css('img').first['srcset']).to_not eq(nil) expect(doc.css('img').first['srcset']).to_not eq(nil)
end end
it "does not optimize animated images but adds a class so animated images can be identified" do it "processes animated images correctly" do
# skips optimization
# skips lightboxing
# adds "animated" class to element
upload.update!(animated: true) upload.update!(animated: true)
post = Fabricate(:post, raw: "![image|1024x768, 50%](#{upload.short_url})") post = Fabricate(:post, raw: "![image|1024x768, 50%](#{upload.short_url})")
@ -981,7 +984,7 @@ describe CookedPostProcessor do
cpp.post_process cpp.post_process
doc = Nokogiri::HTML5::fragment(cpp.html) doc = Nokogiri::HTML5::fragment(cpp.html)
expect(doc.css('.lightbox-wrapper').size).to eq(1) expect(doc.css('.lightbox-wrapper').size).to eq(0)
expect(doc.css('img').first['src']).to include(upload.url) expect(doc.css('img').first['src']).to include(upload.url)
expect(doc.css('img').first['srcset']).to eq(nil) expect(doc.css('img').first['srcset']).to eq(nil)
expect(doc.css('img.animated').size).to eq(1) expect(doc.css('img.animated').size).to eq(1)

View File

@ -241,7 +241,7 @@ describe SearchIndexer do
post.rebake! post.rebake!
post.reload post.reload
expect(post.cooked).to include( expect(post.cooked).not_to include(
CookedPostProcessor::LIGHTBOX_WRAPPER_CSS_CLASS CookedPostProcessor::LIGHTBOX_WRAPPER_CSS_CLASS
) )