-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
54 lines (44 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Internal dependencies
*/
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
const { attr, children } = query;
registerBlock( 'core/embed', {
title: wp.i18n.__( 'Embed' ),
icon: 'video-alt3',
category: 'common',
attributes: {
url: attr( 'iframe', 'src' ),
title: attr( 'iframe', 'title' ),
caption: children( '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>{ caption }</figcaption>
</figure>
);
}
} );