Skip to content

Instantly share code, notes, and snippets.

@mstapp
Forked from thomasmb/ajax-gist-embed.js
Created March 10, 2014 02:33
Show Gist options
  • Save mstapp/9458545 to your computer and use it in GitHub Desktop.
Save mstapp/9458545 to your computer and use it in GitHub Desktop.
// … find all gist scripts inside the ajax container
var $gists = $ajax_container.find('script[src^="https://gist.github.com/"]');
// if gist embeds are found
if( $gists.length ){
// update each gist
$gists.each(function(){
// we need to store $this for the callback
var $this = $(this);
// load gist as json instead with a jsonp request
$.getJSON( $this.attr('src') + 'on?callback=?', function( data ) {
// replace script with gist html
$this.replaceWith( $( data.div ) );
// load the stylesheet, but only once…
add_stylesheet_once( 'https://gist.github.com/' + data.stylesheet )
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment