summaryrefslogtreecommitdiff
path: root/static/js/pichat.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/pichat.js')
-rwxr-xr-xstatic/js/pichat.js103
1 files changed, 75 insertions, 28 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js
index 92d24a1..8917e7c 100755
--- a/static/js/pichat.js
+++ b/static/js/pichat.js
@@ -1,8 +1,11 @@
var cache = {}
-var pendingMessages = {}
+var PendingMessages = {}
var MaxImagePosts = 40
+// Utils
+
+
function escapeHtml(txt) {
if (!txt) { return ""; }
else { return $("<span>").text(txt).html(); }
@@ -30,6 +33,8 @@ function linkReplace(url){
}
}
+// Message Handling
+
var ImageMsgCount = 0
function removeOldMessages(){
// don't count posts that are all text
@@ -61,7 +66,6 @@ function buildMessageDiv(msg, isLoading) {
}
function buildUserDiv(user) {
- console.warn(user);
if (user.avatar) {
return '<div class="username">'
+ '<a href="/u/' + escapeHtml(user.nick) + '" target="_blank">'
@@ -74,6 +78,8 @@ function buildUserDiv(user) {
}
}
+// Growl
+
function buildGrowlDataAndPopDatShit(msg) {
var nick = escapeHtml(msg.nick);
nick = '<a href="/u/' + nick + ' " style="color:pink">' + nick + '</a>:'
@@ -96,11 +102,13 @@ function handleMsgError(resp) {
}
}
+// Messages
+
function submitMessage() {
var content = $.trim($('#msgInput').val());
$('#msgInput').val('');
if (content == '') { return; }
- pendingMessages[content] = true;
+ PendingMessages[content] = true;
var msg = { 'nick': Nick, 'content': content };
var div = addNewMessage(msg, true);
@@ -166,7 +174,6 @@ function updateUI(msgs, users) {
}
if (users !== null) {
var flattened = flattenUserJson(users);
- console.log(flattened);
if (!('userlist' in cache) || flattened != cache.userlist) {
$("#userList").html($.map(users, buildUserDiv).join(''));
}
@@ -175,14 +182,34 @@ function updateUI(msgs, users) {
}
function isDuplicateMessage(m) {
- if (m.nick == Nick && m.content in pendingMessages) {
- delete pendingMessages[m.content];
+ if (m.nick == Nick && m.content in PendingMessages) {
+ delete PendingMessages[m.content];
return true;
} else {
return false;
}
}
+var CurrentTopic = null;
+
+function isSameTopic(curTopic, newTopic) {
+ if (!!curTopic != !!newTopic) { return false; }
+ else if (!curTopic) { return false; } // => !newTopic also
+ else {
+ return curTopic.topic == newTopic.topic &&
+ curTopic.deadline == newTopic.deadline &&
+ curTopic.maker == newTopic.maker;
+ }
+}
+
+function updateTopic(newTopic) {
+ if (isSameTopic(CurrentTopic, newTopic)) { return; }
+ alert('new topic');
+ CurrentTopic = newTopic;
+ $('#topic').text(topic.topic);
+
+}
+
function refresh() {
var onSuccess = function(json) {
try {
@@ -194,6 +221,9 @@ function refresh() {
if (typeof UnseenMsgCounter !== 'undefined' && !HasFocus) {
UnseenMsgCounter += messages.length;
}
+ if (json.topic) {
+ updateTopic(json.topic);
+ }
} catch(e) {
if (IsAdmin && window.console) {
console.error(e);
@@ -240,22 +270,16 @@ function initChat() {
setTimeout(refresh, 1000);
}
-function initProfile() {
- jQuery(".linkify").each(function() {
- var text = jQuery(this).text();
- jQuery(this).html(linkify(text));
- });
-
-
- $('.logged-dump .content').each(function() {
- var t = $(this);
- t.html(buildMsgContent(t.text()));
- });
+function makePlainText() {
+ var j = $(this);
+ j.text(j.text());
+}
+function activateProfileEditable() {
var onSubmit = function(attr, newVal, oldVal) {
newVal = $.trim(newVal);
if (newVal == oldVal) { return oldVal };
-
+
$.ajax({
type: "POST",
timeout: 5000,
@@ -273,22 +297,45 @@ function initProfile() {
return escapeHtml(newVal);
};
- var avatarOpts = { 'default_text': 'Enter here!',
+ var avatarOpts = { 'default_text': 'Paste URL here!',
'callback': onSubmit,
'field_type': 'text',
'callbackShowErrors': false };
- $('#avatar.editable').editInPlace(avatarOpts);
+ if ($('#avatar.editable').length > 0) {
+ $('#avatar.editable').editInPlace(avatarOpts);
+ setupUploadAvatar('upload');
+ }
var textareaOpts = { 'default_text': 'Enter here!',
'callback': onSubmit,
'field_type': 'textarea',
'callbackShowErrors': false };
- $('#contact.editable, #bio.editable').editInPlace(textareaOpts);
+ $('#contact.editable, #bio.editable')
+ .editInPlace(textareaOpts)
+ .each(makePlainText);
+}
- if ($('#upload').length > 0) {
- setupUploadAvatar('upload');
- }
+function enableProfileEdit() {
+ $('#contact, #bio, #avatar').addClass('editable');
+ $('#avatar-editing').show();
+ var resetPage = function() { location.reload() };
+ $('#edit-toggle a').text('--> Done editing <--').click(resetPage);
+ activateProfileEditable();
+}
+function initProfile() {
+ $(".linkify").each(function() {
+ var text = jQuery(this).text();
+ jQuery(this).html(linkify(text));
+ });
+
+ $('#edit-toggle').click(enableProfileEdit);
+ activateProfileEditable();
+
+ $('.logged-dump .content').each(function() {
+ var t = $(this);
+ t.html(buildMsgContent(t.text()));
+ });
};
function initLog() {
@@ -303,8 +350,8 @@ function favoriteImage() {};
function setupUpload(elementId, roomKey) {
var onSubmit = function(file, ext) {
- if (!(ext && /^(jpg|png|jpeg|gif)$/i.test(ext))) {
- alert('Error: invalid file extension ' + ext);
+ if (!(ext && /^(jpg|png|jpeg|gif|bmp)$/i.test(ext))) {
+ alert('SORRY, NOT AN IMAGE DUDE... ');
return false;
}
};
@@ -331,9 +378,9 @@ function setupUploadAvatar(elementId) {
var onComplete = function(file, resp) {
$('#spinner').hide();
if (resp == 'INVALID_REQUEST') {
- location.href = location.href;
+ location.reload();
} else if (resp == 'NOT_LOGGED_IN') {
- location.href = location.href;
+ location.reload();
} else if (resp == 'INVALID_IMAGE') {
alert("Sorry, dump.fm can't deal with your image. Pick another :(");
return;