Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Flash Video onebox, set dimension via url using #WxH #2809

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/onebox/engine/flash_video_onebox.rb
Expand Up @@ -3,11 +3,31 @@ module Engine
class FlashVideoOnebox
include Engine

matches_regexp /^https?:\/\/.*\.(swf|flv)$/
matches_regexp /^https?:\/\/.*\.(swf|flv)(#(\d{1,4}x\d{1,4}))?$/

def to_html
# Lidlanca 2014
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't very useful. Author's information is kept in git, no need to duplicate it in the code.

# Support size from url http://matching.domain/file.swf#WxH
# Providing 0 in a dimension (W|H) to indicate 100%
m = @url.match /^(?<url>https?:\/\/.*\.(swf|flv))(#(?<width>\d{1,4})x(?<height>\d{1,4}))?$/
max_w = 1000
min_w = 100
max_h = 1000
min_h = 100

style = ""
if m["width"] && m["height"] #size provided
style = ["max-width:100%","max-height:100%"] #prevent overflow of parent container
url_width = [[m["width"].to_i,max_w].min(),min_w].max #make sure min_w < url_width < max_w
url_height = [[m["height"].to_i,max_h].min(),min_h].max #make sure min_h < url_height < max_h
style << (m["width"].to_i == 0 ? "width:100%" : "width:#{url_width}px")
style << (m["height"].to_i == 0 ? "height:100%" : "height:#{url_height}px")
style = style.join ";"
end
@url = m["url"]

if SiteSetting.enable_flash_video_onebox
"<object width='100%' height='100%'><param name='#{@url}' value='#{@url}'><embed src='#{@url}' width='100%' height='100%'></embed></object>"
"<object style=\"#{style}\" width='100%' height='100%'><param name='#{@url}' value='#{@url}'><embed src='#{@url}' style=\"#{style}\" width='100%' height='100%'></embed></object>"
else
"<a href='#{@url}'>#{@url}</a>"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/components/onebox/engine/flash_video_onebox_spec.rb
Expand Up @@ -13,7 +13,7 @@

it "generates a flash video" do
expect(@o.to_html).to match_html(
"<object width='100%' height='100%'><param name='http://player.56.com/v_OTMyNTk1MzE.swf' value='http://player.56.com/v_OTMyNTk1MzE.swf'><embed src='http://player.56.com/v_OTMyNTk1MzE.swf' width='100%' height='100%'></embed></object>"
"<object style=\"\" width='100%' height='100%'><param name='http://player.56.com/v_OTMyNTk1MzE.swf' value='http://player.56.com/v_OTMyNTk1MzE.swf'><embed src='http://player.56.com/v_OTMyNTk1MzE.swf' style=\"\" width='100%' height='100%'></embed></object>"
)
end
end
Expand Down