mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 11:04:26 +08:00
Update LazyYT for new onebox version
Much simpler code!
This commit is contained in:
parent
79f7a922ef
commit
277b7dc831
@ -16,32 +16,13 @@ class Onebox::Engine::YoutubeOnebox
|
|||||||
|
|
||||||
def to_html
|
def to_html
|
||||||
if video_id
|
if video_id
|
||||||
# Avoid making HTTP requests if we are able to get the video ID from the
|
# Put in the LazyYT div instead of the iframe
|
||||||
# URL.
|
"<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-width=\"480\" data-height=\"270\" data-parameters=\"#{embed_params}\"></div>"
|
||||||
html = "<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-width=\"480\" data-height=\"270\" data-parameters=\"start=0\"></div>"
|
|
||||||
else
|
else
|
||||||
# Fall back to making HTTP requests.
|
super
|
||||||
html = raw[:html] || ""
|
|
||||||
end
|
end
|
||||||
|
|
||||||
rewrite_agnostic(append_params(html))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_params(html)
|
|
||||||
result = html.dup
|
|
||||||
result.gsub! /(src="[^"]+)/, '\1&wmode=opaque'
|
|
||||||
if url =~ /t=(\d+h)?(\d+m)?(\d+s?)?/
|
|
||||||
h = Regexp.last_match[1].to_i
|
|
||||||
m = Regexp.last_match[2].to_i
|
|
||||||
s = Regexp.last_match[3].to_i
|
|
||||||
|
|
||||||
total = (h * 60 * 60) + (m * 60) + s
|
|
||||||
start_time = "\"start=#{total}\""
|
|
||||||
|
|
||||||
result.gsub!('"start=0"', start_time)
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user