Created
August 3, 2011 10:48
-
-
Save rich97/1122371 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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