From 860fff28431e405174eb11a41dbb044674b80a9a Mon Sep 17 00:00:00 2001 From: timb Date: Tue, 19 Jan 2010 12:51:06 -0800 Subject: imageify multiple image urls in a line --- static/js/pichat.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'static/js') diff --git a/static/js/pichat.js b/static/js/pichat.js index 559e775..69a347c 100755 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -3,29 +3,23 @@ function escapeHtml(txt) { else { return $("").text(txt).html(); } } -// http://stackoverflow.com/questions/37684/replace-url-with-html-links-javascript function linkify(text) { - var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi; - return text.replace(exp,"$1"); + var URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; + return text.replace(URLRegex, linkReplace); } - -// http://snippets.dzone.com/posts/show/6995 -var URLRegex = /^((http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/i -var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i; -function isImage(content) { - var match = URLRegex.exec(content); - sansParams = match && match[0].replace(/\?.*$/i, ""); - return sansParams && PicRegex.test(sansParams); +function linkReplace(match){ + var PicRegex = /\.(jpg|jpeg|png|gif|bmp)$/i; + var matchWithoutParams = match.replace(/\?.*$/i, "") + if (PicRegex.test(matchWithoutParams)){ + return "" + } else { + return "" + match + "" + } } function buildMsgContent(content) { - if (isImage(content)) { - return '' - + ''; - } else { - return linkify(escapeHtml(content)); - } + return linkify(content) } function buildMessageDiv(msg) { -- cgit v1.2.3-70-g09d2