From 2e2cba82a3b218877b5814c11f846e7500e91f06 Mon Sep 17 00:00:00 2001 From: 0ip Date: Mon, 28 Nov 2011 17:02:37 +0100 Subject: [PATCH 1/4] 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) { From 6fcc3a24f133dbf7bd6044fba84e42f16f3aa60c Mon Sep 17 00:00:00 2001 From: 0ip Date: Mon, 28 Nov 2011 17:07:33 +0100 Subject: [PATCH 2/4] Basic support for different media types [CSS] --- static/css/pad.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/static/css/pad.css b/static/css/pad.css index 9b676ab26..35cc1ab4b 100644 --- a/static/css/pad.css +++ b/static/css/pad.css @@ -1160,3 +1160,10 @@ width:33px !important; #qrcode{ margin-left:10px; } + +#innerdocbody img, #innerdocbody video, #innerdocbody audio { + padding: 2px; + margin-bottom: 4px; + box-shadow: 0 0 4px #aaa; + background: #fff; +} \ No newline at end of file From 4a6f8d0c9824d3c1b3ba47731575aeaebaffe1aa Mon Sep 17 00:00:00 2001 From: 0ip Date: Tue, 29 Nov 2011 21:06:23 +0100 Subject: [PATCH 3/4] Added YouTube + Vimeo support --- static/js/domline.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/static/js/domline.js b/static/js/domline.js index c3da98e7e..aabc5de18 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -171,6 +171,11 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) // video if (href_ext==".mp4" || href_ext==".ogv" || href_ext==".ogg" || href.slice(-5)==".webm" || href_ext==".mov") { mtype = 3; } + + // YouTube + if (href.match(/[http|https]\:\/\/www\.youtube\.com\/watch\?v=([A-z0-9-_]{11})/) != null) { mtype = 4; } + // Vimeo + if (href.match(/[http|https]\:\/\/vimeo\.com\/(\d{8})/) != null) { mtype = 5; } switch (mtype) { case 1: @@ -182,6 +187,16 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) case 3: extraOpenTags = extraOpenTags + '
'; break; + case 4: + 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 + '

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

'; + break; // if nothing applies, consider it as a normal link default: extraOpenTags = extraOpenTags + ''; From 07fa2ae598be72e658946c40f6a1f135f4eaa18f Mon Sep 17 00:00:00 2001 From: 0ip Date: Thu, 1 Dec 2011 15:00:12 +0100 Subject: [PATCH 4/4] Removed switch-construct --- static/js/domline.js | 53 +++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/static/js/domline.js b/static/js/domline.js index aabc5de18..da5a7e8d0 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -161,49 +161,42 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) // 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; } + 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") { mtype = 2; } + 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") { mtype = 3; } + 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) { mtype = 4; } + 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) { mtype = 5; } + 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 + '

'; + } - switch (mtype) { - case 1: - extraOpenTags = extraOpenTags + '
'; - break; - case 2: - extraOpenTags = extraOpenTags + '
'; - break; - case 3: - extraOpenTags = extraOpenTags + '
'; - break; - case 4: - 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 + '

'; - break; - case 5: - var vimeo_id = href.match(/[http|https]\:\/\/vimeo\.com\/(\d{8})/)[1]; - txt = 'https://vimeo.com/' + vimeo_id; - extraOpenTags = extraOpenTags + '

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