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

Google Calendar block: Fix full width support #14835

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions extensions/blocks/google-calendar/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<iframe src="${ url }" style="border:0" scrolling="no" frameborder="0" width="100%" height=${ height }></iframe>`;
const html = `<iframe src="${ url }" style="border:0" scrolling="no" frameborder="0" height="${ iframeHeight }"></iframe>`;

const permissionsLink = (
<ExternalLink href="https://en.support.wordpress.com/google-calendar/">
Expand Down
1 change: 1 addition & 0 deletions extensions/blocks/google-calendar/editor.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Editor styles for Google Calendar
*/
@import './view.scss';

.wp-block-jetpack-google-calendar {
&-embed-form-sidebar {
Expand Down
9 changes: 4 additions & 5 deletions extensions/blocks/google-calendar/google-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<div class="%1$s"><amp-iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" width="%3$d" height="%4$d" sandbox="allow-scripts allow-same-origin" layout="responsive"></amp-iframe></div>',
'<div class="%1$s"><amp-iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" height="%3$d" sandbox="allow-scripts allow-same-origin" layout="responsive"></amp-iframe></div>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change appears to have broken Google Calendar on AMP pages, since there is no width defined, and the layout was not changed from responsive to fixed-height. Opened PR to fix in #17251.

esc_attr( $classes ),
esc_url( $url ),
absint( $width ),
absint( $height )
);
} else {
return sprintf(
'<div class="%1$s"><iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" width="%3$d" height="%4$d"></iframe></div>',
'<div class="%1$s"><iframe src="%2$s" frameborder="0" style="border:0" scrolling="no" height="%3$d"></iframe></div>',
esc_attr( $classes ),
esc_url( $url ),
absint( $width ),
absint( $height )
);
}
Expand Down
8 changes: 2 additions & 6 deletions extensions/blocks/google-calendar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export const settings = {
url: {
type: 'string',
},
width: {
type: 'integer',
default: 800,
},
height: {
type: 'integer',
default: 600,
Expand Down Expand Up @@ -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 } );
},
},
],
Expand Down
4 changes: 4 additions & 0 deletions extensions/blocks/google-calendar/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Internal dependencies
*/
import './view.scss';
9 changes: 9 additions & 0 deletions extensions/blocks/google-calendar/view.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Shared Editor and Front End styles for Google Calendar
*/
.wp-block-jetpack-google-calendar {
min-width: 420px;
iframe {
width: 100%;
}
}