diff --git a/static/css/pad.css b/static/css/pad.css index 33fc49a91..e9c885192 100644 --- a/static/css/pad.css +++ b/static/css/pad.css @@ -1164,3 +1164,10 @@ label[for=readonlyinput] { #qrcode{ margin-left:10px; } + +#innerdocbody img, #innerdocbody video, #innerdocbody audio { + padding: 2px; + margin-bottom: 4px; + box-shadow: 0 0 4px #aaa; + background: #fff; +} diff --git a/static/js/domline.js b/static/js/domline.js index 7732805fd..da5a7e8d0 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -152,12 +152,51 @@ 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); + + // images + if (href_ext==".jpg" || href_ext==".png" || href_ext==".gif" || href_ext==".svg") { + extraOpenTags = extraOpenTags + '
'; + } + + // music + if (href_ext==".mp3" || href_ext==".wav" || href_ext==".oga") { + extraOpenTags = extraOpenTags + '
'; + } + + // video + if (href_ext==".mp4" || href_ext==".ogv" || href_ext==".ogg" || href.slice(-5)==".webm" || href_ext==".mov") { + extraOpenTags = extraOpenTags + '
'; + } + + // YouTube + if (href.match(/[http|https]\:\/\/www\.youtube\.com\/watch\?v=([A-z0-9-_]{11})/) != null) { + var youtube_id = href.match(/[http|https]\:\/\/www\.youtube\.com\/watch\?v=([A-z0-9-_]{11})/)[1]; + txt = 'https://www.youtube.com/watch?v=' + youtube_id; + extraOpenTags = extraOpenTags + '

'; + } + // Vimeo + if (href.match(/[http|https]\:\/\/vimeo\.com\/(\d{8})/) != null) { + var vimeo_id = href.match(/[http|https]\:\/\/vimeo\.com\/(\d{8})/)[1]; + txt = 'https://vimeo.com/' + vimeo_id; + extraOpenTags = extraOpenTags + '

'; + } + + // If nothing applies, consider it as a normal url + if (extraOpenTags.length == 0) { + extraOpenTags = extraOpenTags + ''; + extraCloseTags = '' + extraCloseTags; + } + + } if (simpleTags) {