Skip to content

Instantly share code, notes, and snippets.

@sungmin-park
Created January 10, 2012 15:19
Show Gist options
  • Save sungmin-park/1589565 to your computer and use it in GitHub Desktop.
Save sungmin-park/1589565 to your computer and use it in GitHub Desktop.
jquery.github
(function($) {
$.github = function(method, id, callback) {
return $.ajax('https://api.github.com' + method + '/' + id, {
cache : true,
dataType : 'jsonp',
success : function(data) {
if(data.meta.status != 200) {
return console.error(data.meta);
}
return callback(data.data);
}
})
}
var gist_id_exp = new RegExp('https://gist.github.com/([0-9]+)');
$.fn.gist = function(callback) {
this.each(function() {
if(gist_id_exp.test(this.href)) {
$.github('/gists', RegExp.$1, callback);
}
});
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment