-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathvideo.js
More file actions
132 lines (111 loc) · 2.79 KB
/
video.js
File metadata and controls
132 lines (111 loc) · 2.79 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* global CLD_VIDEO_PLAYER */
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';
import { PanelBody, ToggleControl } from '@wordpress/components';
const Video = {
_init() {
if ( typeof CLD_VIDEO_PLAYER === 'undefined' ) {
return;
}
// Gutenberg Video Settings
wp.hooks.addFilter(
'blocks.registerBlockType',
'Cloudinary/Media/Video',
function ( settings, name ) {
if ( name === 'core/video' ) {
if ( 'off' !== CLD_VIDEO_PLAYER.video_autoplay_mode ) {
settings.attributes.autoplay.default = true;
}
if ( 'on' === CLD_VIDEO_PLAYER.video_loop ) {
settings.attributes.loop.default = true;
}
if ( 'off' === CLD_VIDEO_PLAYER.video_controls ) {
settings.attributes.controls.default = false;
}
}
return settings;
}
);
},
};
export default Video;
// Init.
Video._init();
const cldAddToggle = function ( settings, name ) {
if ( 'core/image' === name || 'core/video' === name ) {
if ( ! settings.attributes ) {
settings.attributes = {};
}
settings.attributes.overwrite_transformations = {
type: 'boolean',
};
settings.attributes.transformations = {
type: 'boolean',
};
}
return settings;
};
wp.hooks.addFilter(
'blocks.registerBlockType',
'cloudinary/addAttributes',
cldAddToggle
);
/* eslint-disable camelcase */
const TransformationsToggle = ( props ) => {
const {
attributes: { overwrite_transformations },
setAttributes,
} = props;
return (
<PanelBody title={ __( 'Transformations', 'cloudinary' ) }>
<ToggleControl
label={ __( 'Overwrite Global Transformations', 'cloudinary' ) }
checked={ overwrite_transformations }
onChange={ ( value ) => {
setAttributes( { overwrite_transformations: value } );
} }
__nextHasNoMarginBottom={ true }
/>
</PanelBody>
);
};
/* eslint-enable camelcase */
let ImageInspectorControls = ( props ) => {
const { setAttributes, media } = props;
const { InspectorControls } = wp.editor;
if ( media && media.transformations ) {
setAttributes( { transformations: true } );
}
return (
<InspectorControls>
<TransformationsToggle { ...props } />
</InspectorControls>
);
};
ImageInspectorControls = withSelect( ( select, ownProps ) => ( {
...ownProps,
media: ownProps.attributes.id
? select( 'core' ).getMedia( ownProps.attributes.id )
: null,
} ) )( ImageInspectorControls );
const cldFilterBlocksEdit = ( BlockEdit ) => {
return ( props ) => {
const { name } = props;
const shouldDisplayInspector =
'core/image' === name || 'core/video' === name;
return (
<>
{ shouldDisplayInspector ? (
<ImageInspectorControls { ...props } />
) : null }
<BlockEdit { ...props } />
</>
);
};
};
wp.hooks.addFilter(
'editor.BlockEdit',
'cloudinary/filterEdit',
cldFilterBlocksEdit,
20
);