summaryrefslogtreecommitdiff
path: root/static/js/pichat.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/pichat.js')
-rwxr-xr-xstatic/js/pichat.js97
1 files changed, 73 insertions, 24 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js
index 985715d..dbc110b 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(); }
@@ -29,6 +32,8 @@ function linkReplace(url){
}
}
+// Message Handling
+
var ImageMsgCount = 0
function removeOldMessages(){
// don't count posts that are all text
@@ -72,6 +77,8 @@ function buildUserDiv(user) {
}
}
+// Growl
+
function buildGrowlDataAndPopDatShit(msg) {
var nick = escapeHtml(msg.nick);
nick = '<a href="/u/' + nick + ' " style="color:pink">' + nick + '</a>:'
@@ -94,11 +101,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);
@@ -172,14 +181,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 {
@@ -191,6 +220,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);
@@ -237,22 +269,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,
@@ -270,22 +296,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() {
@@ -328,9 +377,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;