Class: Onebox::Engine::TiktokOnebox

Inherits:
Object
  • Object
show all
Includes:
Onebox::Engine, StandardEmbed
Defined in:
lib/onebox/engine/tiktok_onebox.rb

Instance Attribute Summary

Attributes included from Onebox::Engine

#errors, #options, #timeout, #uri, #url

Instance Method Summary collapse

Methods included from StandardEmbed

add_oembed_provider, add_opengraph_provider, #always_https?, oembed_providers, opengraph_providers, #raw

Methods included from Onebox::Engine

all_iframe_origins, engines, included, #initialize, origins_to_regexes

Instance Method Details

#placeholder_htmlObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/onebox/engine/tiktok_onebox.rb', line 13

def placeholder_html
  <<-HTML
    <img
      src="#{oembed_data.thumbnail_url}"
      title="#{oembed_data.title}"
      style="
        max-width: #{oembed_data.thumbnail_width / 2}px;
        max-height: #{oembed_data.thumbnail_height / 2}px;"
    >
  HTML
end

#to_htmlObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/onebox/engine/tiktok_onebox.rb', line 25

def to_html
  video_height = oembed_data.thumbnail_height < 1024 ? 998 : oembed_data.thumbnail_height
  height = (323.0 / 576) * video_height

  <<-HTML
    <iframe
      class="tiktok-onebox"
      src="https://www.tiktok.com/embed/v2/#{oembed_data.embed_product_id}"
      sandbox="allow-popups allow-popups-to-escape-sandbox allow-scripts allow-top-navigation allow-same-origin"
      frameborder="0"
      seamless="seamless"
      scrolling="no"
      style="
        min-width: 323px;
        height: #{height}px;
        border: 4px solid #fff;
        border-top: 3px solid #fff;
        background-color: #fff;
        border-radius: 9px;
        "
    ></iframe>
  HTML
end