From 5dd9b7da3b0491635770a7dd1a08d22ca5e5d82b Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 30 Apr 2016 17:16:11 -0700 Subject: [PATCH] Embed .ogg as video first and switch to audio if there is no video. Also support embedding .oga links. --- src/Linkification/Embedding.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Linkification/Embedding.coffee b/src/Linkification/Embedding.coffee index 3f98555c5..d231d7e61 100644 --- a/src/Linkification/Embedding.coffee +++ b/src/Linkification/Embedding.coffee @@ -166,7 +166,7 @@ Embedding = ordered_types: [ key: 'audio' - regExp: /\.(?:mp3|ogg|wav)(?:\?|$)/i + regExp: /\.(?:mp3|oga|wav)(?:\?|$)/i style: '' el: (a) -> $.el 'audio', @@ -378,14 +378,21 @@ Embedding = dummy: true , key: 'video' - regExp: /\.(?:ogv|webm|mp4)(?:\?|$)/i + regExp: /\.(?:og[gv]|webm|mp4)(?:\?|$)/i style: 'max-width: 80vw; max-height: 80vh;' el: (a) -> - $.el 'video', + el = $.el 'video', + hidden: true controls: true preload: 'auto' src: a.dataset.href loop: /^https?:\/\/i\.4cdn\.org\//.test a.dataset.href + $.on el, 'loadedmetadata', -> + if el.videoHeight is 0 and el.parentNode + $.replace el, Embedding.types.audio.el(a) + else + el.hidden = false + el ] return Embedding