-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (66 loc) · 1.8 KB
/
index.js
File metadata and controls
77 lines (66 loc) · 1.8 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Internal dependencies
*/
import './style.scss';
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
// TODO: Revisit when we have a common components solution
import Dashicon from '../../../editor/components/dashicon';
import Button from '../../../editor/components/button';
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, setAttributes, focus, setFocus } ) {
const { url, title, caption } = attributes;
if ( ! url ) {
return (
<div className="blocks-embed is-placeholder">
<div className="blocks-embed__placeholder-label">
<Dashicon icon="cloud" />
{ wp.i18n.__( 'Embed URL' ) }
</div>
<input type="url" className="blocks-embed__placeholder-input" placeholder={ wp.i18n.__( 'Enter URL to embed here.' ) } />
<Button isLarge>
{ wp.i18n.__( 'Embed the link above.' ) }
</Button>
</div>
);
}
return (
<figure>
<div className="iframe-overlay">
<iframe src={ url } title={ title } />
</div>
{ caption || !! focus ? (
<Editable
tagName="figcaption"
placeholder={ wp.i18n.__( 'Write caption…' ) }
value={ caption }
focus={ focus }
onFocus={ setFocus }
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>
);
}
} );