mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FEATURE: Enable pausing images from Giphy and Tenor (#13185)
This commit is contained in:
parent
9b4a873c60
commit
726500bc59
|
@ -7,6 +7,7 @@ class CookedPostProcessor
|
|||
LIGHTBOX_WRAPPER_CSS_CLASS = "lightbox-wrapper"
|
||||
LOADING_SIZE = 10
|
||||
LOADING_COLORS = 32
|
||||
GIF_SOURCES_REGEXP = /(giphy|tenor)\.com\//
|
||||
|
||||
attr_reader :cooking_options, :doc
|
||||
|
||||
|
@ -320,7 +321,7 @@ class CookedPostProcessor
|
|||
|
||||
upload = Upload.get_from_url(src)
|
||||
|
||||
if upload.present? && upload.animated?
|
||||
if (upload.present? && upload.animated?) || src.match?(GIF_SOURCES_REGEXP)
|
||||
img.add_class("animated")
|
||||
end
|
||||
|
||||
|
|
|
@ -990,6 +990,31 @@ describe CookedPostProcessor do
|
|||
expect(doc.css('img.animated').size).to eq(1)
|
||||
end
|
||||
|
||||
context "giphy/tenor images" do
|
||||
before do
|
||||
CookedPostProcessor.any_instance.stubs(:get_size).with("https://media2.giphy.com/media/7Oifk90VrCdNe/giphy.webp").returns([311, 280])
|
||||
CookedPostProcessor.any_instance.stubs(:get_size).with("https://media1.tenor.com/images/20c7ddd5e84c7427954f430439c5209d/tenor.gif").returns([833, 104])
|
||||
end
|
||||
|
||||
it "marks giphy images as animated" do
|
||||
post = Fabricate(:post, raw: "![tennis-gif|311x280](https://media2.giphy.com/media/7Oifk90VrCdNe/giphy.webp)")
|
||||
cpp = CookedPostProcessor.new(post, disable_loading_image: true)
|
||||
cpp.post_process
|
||||
|
||||
doc = Nokogiri::HTML5::fragment(cpp.html)
|
||||
expect(doc.css('img.animated').size).to eq(1)
|
||||
end
|
||||
|
||||
it "marks giphy images as animated" do
|
||||
post = Fabricate(:post, raw: "![cat](https://media1.tenor.com/images/20c7ddd5e84c7427954f430439c5209d/tenor.gif)")
|
||||
cpp = CookedPostProcessor.new(post, disable_loading_image: true)
|
||||
cpp.post_process
|
||||
|
||||
doc = Nokogiri::HTML5::fragment(cpp.html)
|
||||
expect(doc.css('img.animated').size).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "optimizes images in quotes" do
|
||||
post = Fabricate(:post, raw: <<~MD)
|
||||
[quote]
|
||||
|
|
Loading…
Reference in New Issue
Block a user