Skip to content

Instantly share code, notes, and snippets.

@caffo
Created August 17, 2011 17:33
Show Gist options
  • Save caffo/1152091 to your computer and use it in GitHub Desktop.
Save caffo/1152091 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.gistify = function() {
return this.each(function() {
var link = $(this);
var href = $(this).attr('href');
var gist_id = /http:\/\/gist\.github\.com\/(\d+)/.exec(href);
if (gist_id) {
link.wrap('<div id="embedded-gist-'+gist_id[1]+'">');
jQuery.getJSON(href+'.json?callback=?', function(data) {
var stylesheet_needed = true;
$('head link[rel=stylesheet]').each(function() {
if (this.href == data.stylesheet) { stylesheet_needed = false; }
})
if (stylesheet_needed) {$('head').append('<link rel="stylesheet" href="' + data.stylesheet + '" />');}
$('div#embedded-gist-'+gist_id[1]).replaceWith(data.div);
});
}
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment