2013-10-09 11:40:10 -04:00
|
|
|
require_dependency 'oneboxer/oembed_onebox'
|
|
|
|
|
|
|
|
module Oneboxer
|
|
|
|
class YoutubeOnebox < OembedOnebox
|
|
|
|
matcher /^https?:\/\/(?:www\.)?(?:youtube\.com|youtu\.be)\/.+$/
|
2013-12-06 06:01:30 -05:00
|
|
|
|
2013-10-09 11:40:10 -04:00
|
|
|
def oembed_endpoint
|
|
|
|
"http://www.youtube.com/oembed?url=#{BaseOnebox.uriencode(@url.sub('https://', 'http://'))}&format=json"
|
|
|
|
end
|
2013-10-09 14:43:59 -04:00
|
|
|
|
|
|
|
def onebox
|
2013-12-06 06:01:30 -05:00
|
|
|
(super || []).each do |entry|
|
2013-11-06 11:19:02 -05:00
|
|
|
# Youtube allows HTTP and HTTPS, so replace them with the protocol-agnostic variant
|
|
|
|
BaseOnebox.replace_agnostic entry
|
|
|
|
# Add wmode=opaque to the iframe src URL so that the flash player is rendered within the document flow instead of on top
|
|
|
|
BaseOnebox.append_embed_wmode entry
|
|
|
|
end
|
2013-10-09 14:43:59 -04:00
|
|
|
end
|
2013-10-09 11:40:10 -04:00
|
|
|
end
|
|
|
|
end
|