diff options
Diffstat (limited to 'static/js/pichat.js')
| -rw-r--r-- | static/js/pichat.js | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js index a33209b..884e01f 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -120,6 +120,7 @@ Log.initialize(); URLRegex = /((\b(http\:\/\/|https\:\/\/|ftp\:\/\/)|(www\.))+(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi; PicRegex = /\.(jpg|jpeg|png|gif|bmp|svg|fid)$/i; RecipRegex = /(^|\s)@\w+/g; +TopicRegex = /(^|\s)#\w+/g; function getImagesAsArray(text) { @@ -135,24 +136,44 @@ function getImagesAsArray(text) { return imgs } -function linkify(text, recips) { - LastMsgContainsImage = false; - var recipWrapper = function(text) { return recipientReplace(text, recips); }; - return text.replace(URLRegex, linkReplace).replace(RecipRegex, recipWrapper); +function topicReplace(text) { + text = $.trim(text).toLowerCase(); + var topicLabel = text.substring(1); + return ' <a target="_blank" href="http://dump.fm/t/' + topicLabel + '">' + text + '</a> '; } function recipientReplace(atText, recips) { + recips = recips || []; + + var space = ''; if (atText[0] == ' ') { atText = atText.slice(1); - var space = ' '; - } else { - var space = ''; + space = ' '; } - var nick = atText.slice(1); - if (!recips || recips.indexOf(nick.toLowerCase()) == -1) { + + var nick = atText.slice(1).toLowerCase(); + var matchedRecip; + for (var i = 0; i < recips.length; i++) { + if (recips[i].toLowerCase() == nick) { + matchedRecip = recips[i]; + break; + } + } + + if (matchedRecip) { + return space + '<a target="_blank" href="http://dump.fm/' + matchedRecip + '">@' + matchedRecip + '</a>'; + } else { return space + atText; - } else - return space + '<a target="_blank" href="/' + nick + '">' + atText + '</a>'; + } +} + +function linkify(text, recips) { + LastMsgContainsImage = false; + var recipWrapper = function(text) { return recipientReplace(text, recips); }; + return text + .replace(URLRegex, linkReplace) + .replace(RecipRegex, recipWrapper) + .replace(TopicRegex, topicReplace); } // use this in escapeHtml to turn everyone's text lIkE tHiS @@ -330,7 +351,7 @@ function setImgsEnable() { function buildMsgContent(content, recips) { if (content.substr(0,6) == "<safe>") - return content.substr(6,content.length - 13) + return content.substr(6,content.length - 13); else return linkify(escapeHtml(content), recips); } @@ -363,7 +384,7 @@ function buildUserDiv(user) { + escapeHtml(user.nick) + '</a></div>'; } else { return '<div class="username">' - + '<a href="/' + escapeHtml(user.nick) + '" target="_blank">' + + '<a href="http://dump.fm/' + escapeHtml(user.nick) + '" target="_blank">' + '<img src="/static/img/noinfo.png" width="50" height="50">' + escapeHtml(user.nick) + '</a></div>'; } @@ -373,7 +394,7 @@ function buildUserDiv(user) { function buildFav(f) { var h = '<div class="fav-note">' - + '<img src="/static/img/thumbs/chatheartover.gif">' + + '<img src="http://dump.fm/static/img/thumbs/chatheartover.gif">' + '<a href="http://dump.fm/' + f.from + '">' + f.from + '</a>' + ' <span>just faved you!</span>' + '</div>'; @@ -712,7 +733,7 @@ function enableProfileEdit() { activateProfileEditable(); } -function initProfile() { +function initProfile(recips) { Search.initInpage(); $(".linkify-text").each(function() { var text = jQuery(this).text(); @@ -720,7 +741,7 @@ function initProfile() { }); $(".linkify-full").each(function() { - $(this).html(buildMsgContent($(this).text(), Recips)); + $(this).html(buildMsgContent($(this).text(), recips)); }); $('#edit-toggle').click(enableProfileEdit); @@ -732,11 +753,11 @@ function initProfile() { }); }; -function initLog() { - Search.initInpage() +function initLog(recips) { + Search.initInpage(); $('.logged-dump .content').each(function() { var t = $(this); - t.html(buildMsgContent(t.text())); + t.html(buildMsgContent(t.text(), recips)); }); initLogThumb(".logged-dump .thumb", '.dump'); } @@ -797,7 +818,7 @@ function paletteToChat(img){ chatText += " " chatText += $(img).attr("src") + " " $("#msgInput").val(chatText) - $("#msgInput").focus().val($("#msgInput").val()) //http://stackoverflow.com/questions/1056359/ + $("#msgInput").focus().val($("#msgInput").val()) // http://stackoverflow.com/questions/1056359/ paletteHide() } |
