FEATURE: add `data-original-href` attribute to Vimeo iframes

FEATURE: add data-original-href attribute to Vimeo iframes

diff --git a/lib/onebox/engine/vimeo_onebox.rb b/lib/onebox/engine/vimeo_onebox.rb
index 591f16d..10c73b6 100644
--- a/lib/onebox/engine/vimeo_onebox.rb
+++ b/lib/onebox/engine/vimeo_onebox.rb
@@ -7,13 +7,32 @@ module Onebox
       matches_regexp(/^https?:\/\/(www\.)?vimeo\.com\/\d+(\/[^\/]+)?$/)
       always_https
 
+      WIDTH  ||= 640
+      HEIGHT ||= 360
+
       def placeholder_html
-        oembed = get_oembed
-        "<img src='#{oembed.thumbnail_url}' width='#{oembed.thumbnail_width}' height='#{oembed.thumbnail_height}' #{oembed.title_attr}>"
+        image_src = og_data.image_secure_url || og_data.image_url
+        "<img src='#{image_src}' width='#{WIDTH}' height='#{HEIGHT}' #{og_data.title_attr}>"
       end
 
       def to_html
-        get_oembed.html
+        video_src = og_data.video_secure_url || og_data.video_url
+        video_src = video_src.gsub('autoplay=1', '').chomp("?")
+        <<-HTML
+          <iframe width="#{WIDTH}"
+                  height="#{HEIGHT}"
+                  src="#{video_src}"
+                  data-original-href="#{link}"
+                  frameborder="0"
+                  allowfullscreen>
+          </iframe>
+        HTML
+      end
+
+      private
+
+      def og_data
+        @og_data = get_opengraph
       end
     end
   end
diff --git a/lib/onebox/sanitize_config.rb b/lib/onebox/sanitize_config.rb
index d8c00a2..1d7bffa 100644
--- a/lib/onebox/sanitize_config.rb
+++ b/lib/onebox/sanitize_config.rb
@@ -10,7 +10,7 @@ class Sanitize
         'a' => RELAXED[:attributes]['a'] + %w(target),
         'audio' => %w[controls],
         'embed' => %w[height src type width],
-        'iframe' => %w[allowfullscreen frameborder height scrolling src width],
+        'iframe' => %w[allowfullscreen frameborder height scrolling src width data-original-href],
         'source' => %w[src type],
         'video' => %w[controls height loop width autoplay muted poster],
         'path' => %w[d],

GitHub sha: a591ea61

This commit has been mentioned on Discourse Meta. There might be relevant details there: