summaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authortimb <timb@mb.local>2010-01-19 12:51:06 -0800
committertimb <timb@mb.local>2010-01-19 12:51:06 -0800
commit860fff28431e405174eb11a41dbb044674b80a9a (patch)
tree6ffc06631e0a2f7b5771ad7be98ae6d06d7b9c2d /static/js
parentba5bfc7892f8bfb6448d741291de1b0e51d8885b (diff)
imageify multiple image urls in a line
Diffstat (limited to 'static/js')
-rwxr-xr-xstatic/js/pichat.js28
1 files changed, 11 insertions, 17 deletions
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 $("<span>").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,"<a href='$1'>$1</a>");
+ 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 "<a target='_blank' href='" + match + "'><img src='" + match + "'></a>"
+ } else {
+ return "<a target='_blank' href='" + match + "'>" + match + "</a>"
+ }
}
function buildMsgContent(content) {
- if (isImage(content)) {
- return '<a href="' + content + '" target="_blank">'
- + '<img src="'+ content + '" /></a>';
- } else {
- return linkify(escapeHtml(content));
- }
+ return linkify(content)
}
function buildMessageDiv(msg) {