diff options
Diffstat (limited to 'static/js')
| -rwxr-xr-x | static/js/home.js | 7 | ||||
| -rwxr-xr-x | static/js/pichat.js | 50 |
2 files changed, 48 insertions, 9 deletions
diff --git a/static/js/home.js b/static/js/home.js index 107486c..60b5d07 100755 --- a/static/js/home.js +++ b/static/js/home.js @@ -5,7 +5,6 @@ function ifEnter(fn) { } function initLoginForm() { - var nick = "#nickInput", nickFiller = "username" var pass = "#passwordInput", passLabel = "#passwordInputLabel", passFiller = "password" var submit = "#signin-submit" @@ -145,17 +144,15 @@ function initBigHand(id){ } function login() { - //$('#passwordInput, #loginSubmit').blur(); var nick = $('#nickInput').val(); var password = $('#passwordInput').val(); var rememberme = $('#remembermeInput').attr('checked') ? 'yes' : ''; var hash = hex_sha1(nick + '$' + password + '$dumpfm'); var onSuccess = function(json) { + location.href = location.href; if (typeof pageTracker !== 'undefined') { - pageTracker._setCustomVar(1, "logged-in", nick, 1); - } - location.href = "/chat"; + pageTracker._setCustomVar(1, "logged-in", nick, }; var onError = function(resp, textStatus, errorThrown) { diff --git a/static/js/pichat.js b/static/js/pichat.js index 3137ac4..566bd10 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('')); } @@ -241,7 +251,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 +286,10 @@ function initProfile() { 'callbackShowErrors': false }; $('#contact.editable, #bio.editable').editInPlace(textareaOpts); + if ($('#upload').length > 0) { + setupUploadAvatar('upload'); + } + }; function initLog() { @@ -283,7 +297,6 @@ function initLog() { var t = $(this); t.html(buildMsgContent(t.text())); }); - } // TODO @@ -302,7 +315,7 @@ function setupUpload(elementId, roomKey) { } } new AjaxUpload(elementId, { - action: '/upload', + action: '/upload/message', autoSubmit: true, name: 'image', data: { room: roomKey }, @@ -311,6 +324,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 |
