From 2e2cba82a3b218877b5814c11f846e7500e91f06 Mon Sep 17 00:00:00 2001 From: 0ip Date: Mon, 28 Nov 2011 17:02:37 +0100 Subject: [PATCH] Basic support for different media types --- static/js/domline.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/static/js/domline.js b/static/js/domline.js index 7732805fd..c3da98e7e 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -152,12 +152,43 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { if (href) { - if(!~href.indexOf("http")) // if the url doesn't include http or https etc prefix it. + + // if the url doesn't include http or https prefix it + if(!~href.indexOf("http")) { href = "http://"+href; } - extraOpenTags = extraOpenTags + ''; - extraCloseTags = '' + extraCloseTags; + + // check extension and decide, whether it's media (image,audio,video) or a simple link + var href_ext = href.slice(-4); + var mtype = null; + + // images + if (href_ext==".jpg" || href_ext==".png" || href_ext==".gif" || href_ext==".svg") { mtype = 1; } + + // music + if (href_ext==".mp3" || href_ext==".wav" || href_ext==".oga") { mtype = 2; } + + // video + if (href_ext==".mp4" || href_ext==".ogv" || href_ext==".ogg" || href.slice(-5)==".webm" || href_ext==".mov") { mtype = 3; } + + switch (mtype) { + case 1: + extraOpenTags = extraOpenTags + '
'; + break; + case 2: + extraOpenTags = extraOpenTags + '
'; + break; + case 3: + extraOpenTags = extraOpenTags + '
'; + break; + // if nothing applies, consider it as a normal link + default: + extraOpenTags = extraOpenTags + ''; + extraCloseTags = '' + extraCloseTags; + break; + } + } if (simpleTags) {