mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 00:14:17 +08:00
FEATURE: ship lazyYT plugin by default
This commit is contained in:
29
plugins/lazyYT/plugin.rb
Normal file
29
plugins/lazyYT/plugin.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# name: lazyYT
|
||||
# about: Uses the lazyYT plugin to lazy load Youtube videos
|
||||
# version: 0.1
|
||||
# authors: Arpit Jalan
|
||||
|
||||
# javascript
|
||||
register_asset "javascripts/lazyYT.js"
|
||||
register_asset "javascripts/initializers/lazyYT.js.es6"
|
||||
|
||||
# stylesheet
|
||||
register_asset "stylesheets/lazyYT.css"
|
||||
|
||||
# freedom patch YouTube Onebox
|
||||
class Onebox::Engine::YoutubeOnebox
|
||||
include Onebox::Engine
|
||||
|
||||
def to_html
|
||||
if video_id
|
||||
# Avoid making HTTP requests if we are able to get the video ID from the
|
||||
# URL.
|
||||
html = "<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-width=\"480\" data-height=\"270\"></div>"
|
||||
else
|
||||
# Fall back to making HTTP requests.
|
||||
html = raw[:html] || ""
|
||||
end
|
||||
|
||||
rewrite_agnostic(append_params(html))
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user