Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gist Shortcode: Remove jQuery Dependency #16700

Merged
merged 6 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions modules/shortcodes/gist.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,22 @@ class_exists( 'Jetpack_AMP_Support' )

// URL points to the entire gist, including the file name if there was one.
$id = ( ! empty( $file ) ? $id . '?file=' . $file : $id );
$return = false;

wp_enqueue_script(
'jetpack-gist-embed',
Assets::get_file_url_for_environment( '_inc/build/shortcodes/js/gist.min.js', 'modules/shortcodes/js/gist.js' ),
array( 'jquery' ),
JETPACK__VERSION,
true
);
$request = wp_remote_get( "https://gist.github.com/" . esc_attr( $id ) );
Aurorum marked this conversation as resolved.
Show resolved Hide resolved
$request_code = wp_remote_retrieve_response_code( $request );

// inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables.
$return = sprintf(
'<style>.gist table { margin-bottom: 0; }</style><div class="gist-oembed" data-gist="%1$s" data-ts="%2$d"></div>',
esc_attr( $id ),
absint( $tab_size )
);
if ( 200 === $request_code ) {
$request_body = wp_remote_retrieve_body($request);
$request_data = json_decode($request_body);

wp_enqueue_style( 'jetpack-gist-styling', $request_data->stylesheet );
Aurorum marked this conversation as resolved.
Show resolved Hide resolved

$gist = substr_replace( $request_data->div, sprintf( 'style="tab-size: %1$s"', absint( $tab_size ) ), 5, 0);

// inline style to prevent the bottom margin to the embed that themes like TwentyTen, et al., add to tables.
$return = sprintf( '<style>.gist table { margin-bottom: 0; }</style>%1$s', $gist );
}

if (
// No need to check for a nonce here, that's already handled by Core further up.
Expand Down
32 changes: 0 additions & 32 deletions modules/shortcodes/js/gist.js

This file was deleted.