Skip to content

Commit

Permalink
Merge pull request #424 from WordPress/add/embed-block
Browse files Browse the repository at this point in the history
Add very basic embed block
  • Loading branch information
ellatrix authored Apr 20, 2017
2 parents c970c16 + 14306c7 commit af45471
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
54 changes: 54 additions & 0 deletions blocks/library/embed/index.js
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>
);
}
} );
1 change: 1 addition & 0 deletions blocks/library/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './embed';
import './freeform';
import './heading';
import './image';
Expand Down
13 changes: 9 additions & 4 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"X-Generator: babel-plugin-wp-i18n\n"

#: blocks/library/embed/index.js:10
msgid "Embed"
msgstr ""

#: blocks/library/embed/index.js:31
#: blocks/library/image/index.js:31
msgid "Write caption…"
msgstr ""

#: blocks/library/freeform/index.js:9
msgid "Freeform"
msgstr ""
Expand All @@ -19,10 +28,6 @@ msgstr ""
msgid "Image"
msgstr ""

#: blocks/library/image/index.js:31
msgid "Write caption…"
msgstr ""

#: blocks/library/list/index.js:11
msgid "List"
msgstr ""
Expand Down

0 comments on commit af45471

Please sign in to comment.