From c16345101c1f96c216634b8f8b2502989e6a8fd9 Mon Sep 17 00:00:00 2001 From: Andy Peatling Date: Wed, 18 Mar 2020 04:33:07 -0700 Subject: [PATCH] Google Calendar block: Fix full width support (#14835) Make sure that the Google Calendar block widths match in the editor and front end, and that full and wide widths are supported correctly. Co-authored-by: Copons --- extensions/blocks/google-calendar/edit.js | 6 +++--- extensions/blocks/google-calendar/editor.scss | 1 + extensions/blocks/google-calendar/google-calendar.php | 9 ++++----- extensions/blocks/google-calendar/index.js | 8 ++------ extensions/blocks/google-calendar/view.js | 4 ++++ extensions/blocks/google-calendar/view.scss | 9 +++++++++ 6 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 extensions/blocks/google-calendar/view.js create mode 100644 extensions/blocks/google-calendar/view.scss diff --git a/extensions/blocks/google-calendar/edit.js b/extensions/blocks/google-calendar/edit.js index 291d967247040..4228102359f1b 100644 --- a/extensions/blocks/google-calendar/edit.js +++ b/extensions/blocks/google-calendar/edit.js @@ -118,12 +118,12 @@ class GoogleCalendarEdit extends Component { render() { const { attributes, className, name, noticeUI } = this.props; const defaultClassName = getBlockDefaultClassName( name ); - const { url } = attributes; + const { url, height } = attributes; const { editedEmbed, interactive, editingUrl } = this.state; - const height = this.props.isMobile ? '300' : '500'; + const iframeHeight = this.props.isMobile ? '300' : height; - const html = ``; + const html = ``; const permissionsLink = ( diff --git a/extensions/blocks/google-calendar/editor.scss b/extensions/blocks/google-calendar/editor.scss index 7f7186825039f..df0cfa2420593 100644 --- a/extensions/blocks/google-calendar/editor.scss +++ b/extensions/blocks/google-calendar/editor.scss @@ -1,6 +1,7 @@ /** * Editor styles for Google Calendar */ + @import './view.scss'; .wp-block-jetpack-google-calendar { &-embed-form-sidebar { diff --git a/extensions/blocks/google-calendar/google-calendar.php b/extensions/blocks/google-calendar/google-calendar.php index d5815a6e794e6..4564a63c877cb 100644 --- a/extensions/blocks/google-calendar/google-calendar.php +++ b/extensions/blocks/google-calendar/google-calendar.php @@ -35,31 +35,30 @@ function register_block() { * @return string */ function load_assets( $attr ) { - $width = isset( $attr['width'] ) ? $attr['width'] : '800'; $height = isset( $attr['height'] ) ? $attr['height'] : '600'; $url = isset( $attr['url'] ) ? \Jetpack_Gutenberg::validate_block_embed_url( $attr['url'], array( 'calendar.google.com' ) ) : ''; $classes = \Jetpack_Gutenberg::block_classes( 'google-calendar', $attr ); + \Jetpack_Gutenberg::load_assets_as_required( 'google-calendar' ); + if ( empty( $url ) ) { return; } if ( class_exists( 'Jetpack_AMP_Support' ) && \Jetpack_AMP_Support::is_amp_request() ) { return sprintf( - '
', + '
', esc_attr( $classes ), esc_url( $url ), - absint( $width ), absint( $height ) ); } else { return sprintf( - '
', + '
', esc_attr( $classes ), esc_url( $url ), - absint( $width ), absint( $height ) ); } diff --git a/extensions/blocks/google-calendar/index.js b/extensions/blocks/google-calendar/index.js index ba96855075b7a..83a606e18f09d 100644 --- a/extensions/blocks/google-calendar/index.js +++ b/extensions/blocks/google-calendar/index.js @@ -35,10 +35,6 @@ export const settings = { url: { type: 'string', }, - width: { - type: 'integer', - default: 800, - }, height: { type: 'integer', default: 600, @@ -76,8 +72,8 @@ export const settings = { type: 'raw', isMatch: node => node.nodeName === 'FIGURE' && IFRAME_REGEX.test( node.innerHTML ), transform: node => { - const { url, width, height } = extractAttributesFromIframe( node.innerHTML.trim() ); - return createBlock( 'jetpack/google-calendar', { url, width, height } ); + const { url, height } = extractAttributesFromIframe( node.innerHTML.trim() ); + return createBlock( 'jetpack/google-calendar', { url, height } ); }, }, ], diff --git a/extensions/blocks/google-calendar/view.js b/extensions/blocks/google-calendar/view.js new file mode 100644 index 0000000000000..741c50d6a0ff9 --- /dev/null +++ b/extensions/blocks/google-calendar/view.js @@ -0,0 +1,4 @@ +/** + * Internal dependencies + */ +import './view.scss'; diff --git a/extensions/blocks/google-calendar/view.scss b/extensions/blocks/google-calendar/view.scss new file mode 100644 index 0000000000000..8745502f0ca78 --- /dev/null +++ b/extensions/blocks/google-calendar/view.scss @@ -0,0 +1,9 @@ +/** + * Shared Editor and Front End styles for Google Calendar + */ +.wp-block-jetpack-google-calendar { + min-width: 420px; + iframe { + width: 100%; + } +}