Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with WP 6.2+ JS #342

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 46 additions & 21 deletions assets/js/src/block.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* global wp, bctiny, bcBlock */
(function (blocks, element, components, editor) {
(function (blocks, element, components) {
const { __, sprintf } = wp.i18n;

const { BlockControls } = wp.blockEditor;
const { Button, Dashicon, ToolbarGroup, ToolbarButton } = components;

var el = element.createElement,
registerBlockType = blocks.registerBlockType,
Placeholder = components.Placeholder,
BlockControls = editor.BlockControls,
IconButton = components.IconButton,
userPermission = !!bcBlock.userPermission,
InspectorControls = wp.blockEditor.InspectorControls,
TextControl = components.TextControl;
Expand Down Expand Up @@ -248,23 +249,47 @@
jQuery(document).on('change', '#' + target, onSelectVideo);

// Set up our controls
var controls = el(
BlockControls,
{ key: 'controls' },
el(
'div',
{ className: 'components-toolbar' },
el(IconButton, {
className:
'brightcove-add-media components-icon-button components-toolbar__control',
label: videoId.playlist_id
? __('Change Playlist', 'brightcove')
: __('Change Video', 'brightcove'),
icon: 'edit',
'data-target': '#' + target,
}),
),
);
if (typeof ToolbarGroup === 'function') {
var controls = el(
BlockControls,
{},
el(
ToolbarGroup,
{},
el(ToolbarButton, {
className:
'brightcove-add-media components-icon-button components-toolbar__control',
label: videoId.playlist_id
? __('Change Playlist', 'brightcove')
: __('Change Video', 'brightcove'),
icon: 'edit',
'data-target': '#' + target,
}),
),
);
} else {
var controls = el(
BlockControls,
{ key: 'controls' },
el(
'div',
{ className: 'components-toolbar' },
el(
Button,
{
className:
'brightcove-add-media components-icon-button components-toolbar__control',
label: videoId.playlist_id
? __('Change Playlist', 'brightcove')
: __('Change Video', 'brightcove'),

'data-target': '#' + target,
},
el(Dashicon, { icon: 'edit' }),
),
),
);
}

// If no video has been selected yet, show the selection view
if (
Expand Down Expand Up @@ -654,4 +679,4 @@
return null;
},
});
})(window.wp.blocks, window.wp.element, window.wp.components, window.wp.editor);
})(window.wp.blocks, window.wp.element, window.wp.components);