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

Support 'preload' attribute for Audio Block #7590

Merged
merged 5 commits into from
Jul 11, 2018
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
16 changes: 14 additions & 2 deletions core-blocks/audio/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
import {
IconButton,
PanelBody,
SelectControl,
Toolbar,
ToggleControl,
withNotices,
Expand Down Expand Up @@ -41,7 +42,7 @@ class AudioEdit extends Component {
}

render() {
const { autoplay, caption, loop, src } = this.props.attributes;
const { autoplay, caption, loop, preload, src } = this.props.attributes;
const { setAttributes, isSelected, className, noticeOperations, noticeUI } = this.props;
const { editing } = this.state;
const switchToEditing = () => {
Expand Down Expand Up @@ -102,7 +103,7 @@ class AudioEdit extends Component {
</Toolbar>
</BlockControls>
<InspectorControls>
<PanelBody title={ __( 'Playback Controls' ) }>
<PanelBody>
<ToggleControl
label={ __( 'Autoplay' ) }
onChange={ this.toggleAttribute( 'autoplay' ) }
Expand All @@ -113,6 +114,17 @@ class AudioEdit extends Component {
onChange={ this.toggleAttribute( 'loop' ) }
checked={ loop }
/>
<SelectControl
label={ __( 'Preload' ) }
value={ undefined !== preload ? preload : 'none' }
// `undefined` is required for the preload attribute to be unset.
onChange={ ( value ) => setAttributes( { preload: ( 'none' !== value ) ? value : undefined } ) }
options={ [
{ value: 'auto', label: __( 'Auto' ) },
{ value: 'metadata', label: __( 'Metadata' ) },
{ value: 'none', label: __( 'None' ) },
] }
/>
</PanelBody>
</InspectorControls>
<figure className={ className }>
Expand Down
10 changes: 8 additions & 2 deletions core-blocks/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export const settings = {
selector: 'audio',
attribute: 'loop',
},
preload: {
type: 'string',
source: 'attribute',
selector: 'audio',
attribute: 'preload',
},
},

supports: {
Expand All @@ -57,10 +63,10 @@ export const settings = {
edit,

save( { attributes } ) {
const { autoplay, caption, loop, src } = attributes;
const { autoplay, caption, loop, preload, src } = attributes;
return (
<figure>
<audio controls="controls" src={ src } autoPlay={ autoplay } loop={ loop } />
<audio controls="controls" src={ src } autoPlay={ autoplay } loop={ loop } preload={ preload } />
Copy link
Member

@tofumatt tofumatt Jul 5, 2018

Choose a reason for hiding this comment

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

This will need a deprecated save function, right? (https://github.com/WordPress/gutenberg/blob/master/docs/block-api/deprecated-blocks.md)

Or will this load fine because it's just adding the binary attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

The latter, to my knowledge. The markup doesn't change structure; this is only a progressive enhancement.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, cool. 👍 (Sorry I'm still a bit new to block validation!)

{ caption && caption.length > 0 && <RichText.Content tagName="figcaption" value={ caption } /> }
</figure>
);
Expand Down