summaryrefslogtreecommitdiff
path: root/static/js
diff options
context:
space:
mode:
authorScott Ostler <scottbot9000@gmail.com>2011-01-04 15:42:23 -0500
committerScott Ostler <scottbot9000@gmail.com>2011-01-04 15:42:23 -0500
commit92b092823c21af1339e0d42716dc856357f93e85 (patch)
tree809221e2a3b3c88306ba5e4b4996eb05297cec02 /static/js
parent7a031af911887a913857fdcebb252231119f4bf9 (diff)
Added topics, refactored recipient handling
Diffstat (limited to 'static/js')
-rw-r--r--static/js/pichat.js58
1 files changed, 40 insertions, 18 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js
index a33209b..72f7d0d 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,45 @@ 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 href="/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="/' + matchedRecip + '">@' + matchedRecip + '</a>';
+ } else {
return space + atText;
- } else
- return space + '<a target="_blank" href="/' + nick + '">' + atText + '</a>';
+ }
+}
+
+function linkify(text, recips) {
+ console.log(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 +352,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);
}
@@ -712,7 +734,7 @@ function enableProfileEdit() {
activateProfileEditable();
}
-function initProfile() {
+function initProfile(recips) {
Search.initInpage();
$(".linkify-text").each(function() {
var text = jQuery(this).text();
@@ -720,7 +742,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 +754,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 +819,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()
}