summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/shortcodes/js/gist.js')
-rw-r--r--plugins/jetpack/modules/shortcodes/js/gist.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/plugins/jetpack/modules/shortcodes/js/gist.js b/plugins/jetpack/modules/shortcodes/js/gist.js
new file mode 100644
index 00000000..a97d7f91
--- /dev/null
+++ b/plugins/jetpack/modules/shortcodes/js/gist.js
@@ -0,0 +1,27 @@
+( 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 );