Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Created October 6, 2012 03:53
Show Gist options
  • Save georgeOsdDev/3843721 to your computer and use it in GitHub Desktop.
Save georgeOsdDev/3843721 to your computer and use it in GitHub Desktop.
get coderwall badge
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="coderwallbadges" class="badge" data-source="georgeosddev"></div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script src="main.js"></script>
</body>
</html>
Badge = Backbone.Model.extend({});
Badges = Backbone.Collection.extend({
model: Badge,
url: function(username) {
return "http://coderwall.com/:USERNAME.json?callback=?".replace(":USERNAME", username);
},
fetch: function(username) {
var self = this;
$.getJSON(self.url(username),function(data){
self.reset(data["data"]["badges"]);
});
}
});
BadgeView = Backbone.View.extend({
el: '#coderwallbadges',
initialize: function() {
var self = this;
_.bindAll(this, "render");
self.collection = new Badges();
this.collection.on("reset", this.render);
self.collection.fetch(self.$el.attr("data-source"));
},
render: function() {
var self = this;
this.collection.each(function(badge){
var badgeImg = new Image();
badgeImg.src = badge.get("badge");
self.$el.append(badgeImg);
});
}
});
new BadgeView();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment