Last active
January 9, 2019 15:39
-
-
Save technote-space/a9d1ab7154b6e5d372e0aa8b0cd77faa to your computer and use it in GitHub Desktop.
Gutenberg複数追加例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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