Skip to content

Commit

Permalink
Improved the jQuery user extension by having it only request user inf…
Browse files Browse the repository at this point in the history
…ormation from the API when really necessary.
  • Loading branch information
blixt committed Mar 24, 2010
1 parent e5925ea commit bbff26d
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions app/js/pages.intro.js
Expand Up @@ -25,20 +25,29 @@ $.fn.frame = function (id) {
};

$.fn.user = function (id) {
var user = User.get(id), img, span;
this.addClass('user').hash('user/' + id).empty();

this.addClass('user').hash('user/' + id)
.empty()
.append(img = $('<img/>').attr({alt: '', src: '/media/loading3.gif',
width: 20, height: 20}))
.append(span = $('<span/>').text('[User#' + id + ']'));

user.listen('load', function () {
var
user = User.get(id),
img = $('<img/>').attr({alt: '', width: 20, height: 20}).appendTo(this),
span = $('<span/>').appendTo(this),
onload = function () {
img.attr('src', user.get_gravatarUrl(20));
span.text(user.get_displayName());
});
};

user.load();
// Update the user info whenever a load event is raised.
user.listen('load', onload);

if (user.isLoaded()) {
// Simulate a load event to load the user data into the link.
onload();
} else {
img.attr('src', '/media/loading3.gif');
span.text('[User#' + id + ']');

user.load();
}
};

var
Expand Down

0 comments on commit bbff26d

Please sign in to comment.