diff options
| author | sostler <sbostler@gmail.com> | 2010-02-24 08:12:31 -0500 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-02-24 08:12:31 -0500 |
| commit | 3e469cfa4dc440fc8fba92b629837306eb4b21b5 (patch) | |
| tree | 416c543fd8fe1082a7f9e1d66e2796bf68b69ae8 /static/js/pichat.js | |
| parent | 3a44ede0d5c1aff3cdd6102ece91df1403f6d14a (diff) | |
| parent | 49ef1a688025d9183452fe5f1dccf7802d64dc62 (diff) | |
Merge branch 'master' of ssh://sostler@dump.fm/pichat/repo
Diffstat (limited to 'static/js/pichat.js')
| -rwxr-xr-x | static/js/pichat.js | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/static/js/pichat.js b/static/js/pichat.js index 3137ac4..92d24a1 100755 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -61,6 +61,7 @@ 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">' @@ -149,6 +150,14 @@ function setUserList(users) { $("#userList").html($.map(users, buildUserDiv).join('')); } +function flattenUserJson(users) { + var s = ""; + $.map(users.sort(), function(user) { + s += user.nick + user.avatar; + }); + return s; +} + function updateUI(msgs, users) { if (window['growlize'] && msgs && msgs.length > 0) { $.map(msgs, buildGrowlDataAndPopDatShit) @@ -156,7 +165,8 @@ function updateUI(msgs, users) { addNewMessages(msgs); } if (users !== null) { - var flattened = users.sort().join(",") + var flattened = flattenUserJson(users); + console.log(flattened); if (!('userlist' in cache) || flattened != cache.userlist) { $("#userList").html($.map(users, buildUserDiv).join('')); } @@ -231,7 +241,6 @@ function initChat() { } function initProfile() { - jQuery(".linkify").each(function() { var text = jQuery(this).text(); jQuery(this).html(linkify(text)); @@ -241,7 +250,7 @@ function initProfile() { $('.logged-dump .content').each(function() { var t = $(this); t.html(buildMsgContent(t.text())); - }); + }); var onSubmit = function(attr, newVal, oldVal) { newVal = $.trim(newVal); @@ -276,6 +285,10 @@ function initProfile() { 'callbackShowErrors': false }; $('#contact.editable, #bio.editable').editInPlace(textareaOpts); + if ($('#upload').length > 0) { + setupUploadAvatar('upload'); + } + }; function initLog() { @@ -283,7 +296,6 @@ function initLog() { var t = $(this); t.html(buildMsgContent(t.text())); }); - } // TODO @@ -302,7 +314,7 @@ function setupUpload(elementId, roomKey) { } } new AjaxUpload(elementId, { - action: '/upload', + action: '/upload/message', autoSubmit: true, name: 'image', data: { room: roomKey }, @@ -311,6 +323,35 @@ function setupUpload(elementId, roomKey) { }); } +function setupUploadAvatar(elementId) { + // NOTE: AjaxUpload responses aren't converted from JSON. + var onSubmit = function(file, error) { + $('#spinner').show(); + }; + var onComplete = function(file, resp) { + $('#spinner').hide(); + if (resp == 'INVALID_REQUEST') { + location.href = location.href; + } else if (resp == 'NOT_LOGGED_IN') { + location.href = location.href; + } else if (resp == 'INVALID_IMAGE') { + alert("Sorry, dump.fm can't deal with your image. Pick another :("); + return; + } + var s = '<img id="avatarPic" src="' + resp + '" width="150" />'; + $('#avatarPic').replaceWith(s).show(); + $('#avatar').text(resp); + }; + new AjaxUpload(elementId, { + action: '/upload/avatar', + autoSubmit: true, + name: 'image', + onSubmit: onSubmit, + onComplete: onComplete + }); +} + + // scrolling stuff // this code keeps the div scrolled to the bottom, but will also let the user scroll up, without jumping down |
