45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/animate_it/embed_helper.rb', line 45
def animate_it_embed(
composition_id,
poster:,
variants: [],
navigation: { preset: :pills },
load_when_visible: 0.25,
play_when_visible: 2.0 / 3,
pause_offscreen: true,
reduced_motion: :poster,
autoplay: true,
title: nil,
**attributes,
&block
)
composition = public_animate_it_composition!(composition_id)
navigation = navigation == false ? false : (navigation || {}).to_h.deep_symbolize_keys
resolved_variants = resolve_animate_it_variants(composition, poster, variants)
validate_animate_it_variant_chapters!(resolved_variants)
manifest = animate_it_embed_manifest(
title: title || composition.id,
variants: resolved_variants,
load_when_visible:,
play_when_visible:,
pause_offscreen:,
reduced_motion:,
autoplay:
)
builder = EmbedBuilder.new(self, composition, navigation: navigation || {})
navigation_html = if navigation
block ? capture(builder, &block) : builder.chapter_navigation(class: "animate-it-embed__navigation")
end
classes = ["animate-it-embed", attributes.delete(:class)].compact.join(" ")
data = (attributes.delete(:data) || {}).merge(animate_it_embed: true)
safe_join(
[
stylesheet_link_tag(animate_it_embed_asset_path("embed.css"), data: { animate_it_embed_asset: "style" }),
javascript_include_tag(
animate_it_embed_asset_path("embed.js"), defer: true, data: { animate_it_embed_asset: "script" }
),
tag.public_send("animate-it-embed", **attributes, class: classes, data:) do
safe_join([
navigation_html,
animate_it_embed_viewport(resolved_variants, title || composition.id),
tag.script(ERB::Util.json_escape(JSON.generate(manifest)).html_safe,
type: "application/json", data: { animate_it_embed_manifest: true })
].compact)
end
]
)
end
|