Skip to content

Instantly share code, notes, and snippets.

@rich97
Created August 3, 2011 10:48
Show Gist options
  • Save rich97/1122371 to your computer and use it in GitHub Desktop.
Save rich97/1122371 to your computer and use it in GitHub Desktop.
// ...
function image(path, fn) {
$(new Image()).load(function() {
if (typeof fn === 'function') {
fn($(this));
}
})
.error(function () {
console.error('Unable to load image: ' + imgBasePath + path);
})
.attr('src', imgBasePath + path);
}
function load(p, info, fn) {
display = info || {
Username : p.username,
Lives : p.location,
Supports : p.team,
Level : p.level
};
image(p.avatar, function(img) {
var detail = $('<div></div>', {
class: 'player_details'
});
for (name in display) {
detail.append($('<div>').html(name + ': ' + display[name]));
}
if (typeof fn === 'function') {
fn(img, detail);
}
});
}
// ...
$.each(players, function(i, p) {
var id, elem;
id = (player.sessionid === p.sessionid) ? 'me' : null;
elem = $('<div />', {
class: 'player clearfix',
target: p.sessionid,
id: id
});
load(p, {Username: p.username, Level: p.level}, function(img, details) {
img.appendTo(elem);
details.appendTo(elem);
});
elements.progress.append(elem);
});
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment