Instantly share code, notes, and snippets.

@technote-space technote-space/editor.js
Last active Jan 9, 2019

Embed
What would you like to do?
Gutenberg複数追加例
(function (richText, element, editor) {
richText.registerFormatType('my-plugin/my-plugin1', {
title: 'my-plugin',
tagName: 'span',
className: 'class1',
edit: function ({isActive, value, onChange}) {
return element.createElement(editor.RichTextToolbarButton, {
icon: 'admin-customizer',
title: 'title1',
onClick: function () {
onChange(richText.toggleFormat(value, {
type: 'my-plugin/my-plugin1'
}));
},
isActive: isActive,
});
},
});
richText.registerFormatType('my-plugin/my-plugin2', {
title: 'my-plugin',
tagName: 'span',
className: 'class2',
edit: function ({isActive, value, onChange}) {
return element.createElement(editor.RichTextToolbarButton, {
icon: 'admin-customizer',
title: 'title2',
onClick: function () {
onChange(richText.toggleFormat(value, {
type: 'my-plugin/my-plugin2'
}));
},
isActive: isActive,
});
},
});
}(
window.wp.richText,
window.wp.element,
window.wp.editor
));
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_style( 'my_plugin', plugins_url( 'assets/css/editor.css', __FILE__ ) );
wp_enqueue_script( 'my_plugin', plugins_url( 'assets/js/editor.js', __FILE__ ), [
'wp-element',
'wp-rich-text',
'wp-editor',
] );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment