From 4cad5f6e9698fed766fb1a19061e435550848cb6 Mon Sep 17 00:00:00 2001 From: Jessica McKellar Date: Mon, 5 Nov 2012 17:51:27 -0500 Subject: [PATCH] settings: Update name and gravatar without a reload. (imported from commit 961c9f64d7c39b4345ece036062854e8d474d2c0) --- templates/zephyr/index.html | 4 ++-- templates/zephyr/settings.html | 4 ++-- tools/jslint/check-all.js | 2 +- zephyr/static/js/ui.js | 44 ++++++++++++++++++++++++++++++++-- 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/templates/zephyr/index.html b/templates/zephyr/index.html index fa4860798f..0a6bfe1f3c 100644 --- a/templates/zephyr/index.html +++ b/templates/zephyr/index.html @@ -84,9 +84,9 @@ var people_list = [


diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index 5c35a295a5..89d70e9af4 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -42,7 +42,7 @@ var globals = // ui.js + ' register_onclick hide_email show_email' + ' report_error report_success report_message clicking mouse_moved' - + ' userinfo_currently_popped' + + ' userinfo_currently_popped update_gravatars' // zephyr.js + ' message_array message_dict get_updates_params' diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 667a4e1d21..8f86181e80 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -384,9 +384,12 @@ $(function () { success: function (resp, statusText, xhr, form) { var message = "Updated settings!"; var result = $.parseJSON(xhr.responseText); - if ((result.full_name !== undefined) || (result.short_name !== undefined)) { - message = "Updated settings! You will need to reload the page for your changes to take effect."; + + if (result.full_name !== undefined) { + $(".my_fullname").text(result.full_name); } + update_gravatars(); + settings_status.removeClass(status_classes) .addClass('alert-success') .text(message).stop(true).fadeTo(0,1); @@ -455,3 +458,40 @@ $(function () { } }); }); + +function update_gravatars() { + $.each($(".gravatar-profile"), function(index, profile) { + $(this).attr('src', $(this).attr('src') + '?' + $.now()); + }); +} + +function poll_for_gravatar_update(start_time, url) { + var updated = false; + + $.ajax({ + type: "HEAD", + url: url, + async: false, + cache: false, + success: function (resp, statusText, xhr) { + if (new Date(xhr.getResponseHeader('Last-Modified')) > start_time) { + update_gravatars(); + updated = true; + } + } + }); + + // Give users 5 minutes to update their picture on gravatar.com, + // during which we try to auto-update their image on our site. If + // they take longer than that, we'll update when they press the + // save button. + if (!updated && (($.now() - start_time) < 1000 * 60 * 5)) { + setTimeout(function() { + poll_for_gravatar_update(start_time, url); + }, 1500); + } +} + +function wait_for_gravatar() { + poll_for_gravatar_update($.now(), $(".gravatar-profile").attr("src")); +}