From 29f3621f453797f2c98c71dd9c6ee0abe34bc1cf Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 20 May 2021 15:19:44 -0400 Subject: [PATCH] FIX: Disable lightboxing of animated images (#13099) --- lib/cooked_post_processor.rb | 12 ++++++------ spec/components/cooked_post_processor_spec.rb | 7 +++++-- spec/services/search_indexer_spec.rb | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index ed57f8b067a..368d1d24e63 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -353,13 +353,13 @@ class CookedPostProcessor unless @disable_loading_image upload.create_thumbnail!(LOADING_SIZE, LOADING_SIZE, format: 'png', colors: LOADING_COLORS) end - end - if img.ancestors('.onebox, .onebox-body, .quote').blank? && !img.classes.include?("onebox") - add_lightbox!(img, original_width, original_height, upload, cropped: crop) - end + return if upload.animated? + + if img.ancestors('.onebox, .onebox-body, .quote').blank? && !img.classes.include?("onebox") + add_lightbox!(img, original_width, original_height, upload, cropped: crop) + end - if upload.present? optimize_image!(img, upload, cropped: crop) end end @@ -390,7 +390,7 @@ class CookedPostProcessor w, h = img["width"].to_i, img["height"].to_i # 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 img["src"] = thumbnail.url diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 7cffe18edff..e0ecf37ee58 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -973,7 +973,10 @@ describe CookedPostProcessor do expect(doc.css('img').first['srcset']).to_not eq(nil) 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) post = Fabricate(:post, raw: "![image|1024x768, 50%](#{upload.short_url})") @@ -981,7 +984,7 @@ describe CookedPostProcessor do cpp.post_process 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['srcset']).to eq(nil) expect(doc.css('img.animated').size).to eq(1) diff --git a/spec/services/search_indexer_spec.rb b/spec/services/search_indexer_spec.rb index 6774543c69b..4fe3f1d9975 100644 --- a/spec/services/search_indexer_spec.rb +++ b/spec/services/search_indexer_spec.rb @@ -241,7 +241,7 @@ describe SearchIndexer do post.rebake! post.reload - expect(post.cooked).to include( + expect(post.cooked).not_to include( CookedPostProcessor::LIGHTBOX_WRAPPER_CSS_CLASS )