mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 02:51:14 +08:00
DEV: Remove lazy-yt and replace with lazy-videos (#20722)
- Refactors the old plugin to remove jquery usage - Adds support for Vimeo videos (default on) and Tiktok (experimental and default off)
This commit is contained in:
28
plugins/discourse-lazy-videos/plugin.rb
Normal file
28
plugins/discourse-lazy-videos/plugin.rb
Normal file
@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# name: discourse-lazy-videos
|
||||
# about: Lazy loading for embedded videos
|
||||
# version: 0.1
|
||||
# authors: Jan Cernik
|
||||
# url: https://github.com/discourse/discourse-lazy-videos
|
||||
|
||||
hide_plugin if self.respond_to?(:hide_plugin)
|
||||
enabled_site_setting :lazy_videos_enabled
|
||||
|
||||
register_asset "stylesheets/lazy-videos.scss"
|
||||
|
||||
require_relative "lib/lazy-videos/lazy_youtube"
|
||||
require_relative "lib/lazy-videos/lazy_vimeo"
|
||||
require_relative "lib/lazy-videos/lazy_tiktok"
|
||||
|
||||
after_initialize do
|
||||
on(:reduce_cooked) do |fragment|
|
||||
fragment
|
||||
.css(".lazy-video-container")
|
||||
.each do |video|
|
||||
title = video["data-video-title"]
|
||||
href = video.at_css("a")["href"]
|
||||
video.replace("<p><a href=\"#{href}\">#{title}</a></p>")
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user