From 07fa2ae598be72e658946c40f6a1f135f4eaa18f Mon Sep 17 00:00:00 2001 From: 0ip Date: Thu, 1 Dec 2011 15:00:12 +0100 Subject: [PATCH] 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) {