-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from WordPress/add/embed-block
Add very basic embed block
- Loading branch information
Showing
3 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { registerBlock, query } from 'api'; | ||
import Editable from 'components/editable'; | ||
|
||
const { attr, html } = query; | ||
|
||
registerBlock( 'core/embed', { | ||
title: wp.i18n.__( 'Embed' ), | ||
|
||
icon: 'video-alt3', | ||
|
||
category: 'common', | ||
|
||
attributes: { | ||
url: attr( 'iframe', 'src' ), | ||
title: attr( 'iframe', 'title' ), | ||
caption: html( 'figcaption' ) | ||
}, | ||
|
||
edit( { attributes, isSelected, setAttributes } ) { | ||
const { url, title, caption } = attributes; | ||
|
||
return ( | ||
<figure> | ||
<iframe src={ url } title={ title } /> | ||
{ caption || isSelected ? ( | ||
<Editable | ||
tagName="figcaption" | ||
placeholder={ wp.i18n.__( 'Write caption…' ) } | ||
value={ caption } | ||
onChange={ ( value ) => setAttributes( { caption: value } ) } /> | ||
) : null } | ||
</figure> | ||
); | ||
}, | ||
|
||
save( { attributes } ) { | ||
const { url, title, caption } = attributes; | ||
const iframe = <iframe src={ url } title={ title } />; | ||
|
||
if ( ! caption ) { | ||
return iframe; | ||
} | ||
|
||
return ( | ||
<figure> | ||
{ iframe } | ||
<figcaption dangerouslySetInnerHTML={ { __html: caption } } /> | ||
</figure> | ||
); | ||
} | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import './embed'; | ||
import './freeform'; | ||
import './heading'; | ||
import './image'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters