This repository has been archived on 2022-08-01. You can view files and clone it, but cannot push or open issues or pull requests.
Oldphaloskepsis/plugins/jetpack/modules/shortcodes/js/gist.js

29 lines
699 B
JavaScript
Raw Normal View History

2017-01-12 23:10:07 +00:00
;(function( $, undefined ) {
var gistStylesheetLoaded = false,
gistEmbed = function() {
$( '.gist-oembed' ).each( function( i, el ) {
var url = 'https://gist.github.com/' + $( el ).data( 'gist' );
$.ajax( {
url: url,
dataType: 'jsonp'
} ).done( function( response ) {
$( el ).replaceWith( response.div );
if ( ! gistStylesheetLoaded ) {
var stylesheet = '<link rel="stylesheet" href="' +
response.stylesheet +
'" type="text/css" />';
$( 'head' ).append( stylesheet );
gistStylesheetLoaded = true;
}
} );
} );
};
$( document ).ready( gistEmbed );
$( 'body' ).on( 'post-load', gistEmbed );
})( jQuery );