diff options
Diffstat (limited to 'plugins/jetpack/modules/shortcodes/gist.php')
-rw-r--r-- | plugins/jetpack/modules/shortcodes/gist.php | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/plugins/jetpack/modules/shortcodes/gist.php b/plugins/jetpack/modules/shortcodes/gist.php index 9a8f63db..ed01a78f 100644 --- a/plugins/jetpack/modules/shortcodes/gist.php +++ b/plugins/jetpack/modules/shortcodes/gist.php @@ -4,12 +4,14 @@ * GitHub's Gist site supports oEmbed but their oembed provider only * returns raw HTML (no styling) and the first little bit of the code. * - * Their Javascript-based embed method is a lot better, so that's what we're using. + * Their JavaScript-based embed method is a lot better, so that's what we're using. */ wp_embed_register_handler( 'github-gist', '#https?://gist\.github\.com/([a-zA-Z0-9]+)#', 'github_gist_embed_handler' ); add_shortcode( 'gist', 'github_gist_shortcode' ); function github_gist_embed_handler( $matches, $attr, $url, $rawattr ) { + wp_enqueue_script( 'jetpack-gist-embed', plugins_url( 'js/gist.js', __FILE__ ), array( 'jquery' ), false, true ); + // Let the shortcode callback do all the work return github_gist_shortcode( $attr, $url ); } @@ -28,10 +30,29 @@ function github_gist_shortcode( $atts, $content = '' ) { if ( ! $id ) return '<!-- Invalid Gist ID -->'; - $embed_url = "https://gist.github.com/{$id}.js"; + if ( ! empty( $atts['file'] ) ) { + $file = '?file=' . urlencode( $atts['file'] ); + } else { + $file = ''; + } + + $embed_url = "{$id}.json" . $file; - if ( ! empty( $atts['file'] ) ) - $embed_url = add_query_arg( 'file', urlencode( $atts['file'] ), $embed_url ); // inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables - return '<style>.gist table { margin-bottom: 0; }</style>' . '<script src="' . esc_url( $embed_url ) . '"></script>'; + $return = '<style>.gist table { margin-bottom: 0; }</style>' . + '<div class="gist-oembed" data-gist="' . esc_attr( $embed_url ) . '"></div>'; + + if ( isset( $_POST[ 'type' ]) && 'embed' === $_POST[ 'type' ] && + isset( $_POST[ 'action' ] ) && 'parse-embed' === $_POST['action'] ) { + + return github_gist_simple_embed( $id, $file ); + } + + return $return; +} + +function github_gist_simple_embed( $id, $file ) { + $embed_url = $id . '.js' . $file; + + return '<script type="text/javascript" src="//gist.github.com/' . $embed_url . '"></script>'; }
\ No newline at end of file |