neo*_*art 5 javascript wordpress reactjs wordpress-gutenberg
我想扩展 WordPress (Gutenberg) 默认块 段落,让编辑者无需编写代码即可添加工具提示。
目标:
在职的:
丢失的:
任何帮助都是极好的!
WordPress 插件
<?php
/*
Plugin Name: KF Custom
*/
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_script(
'kf-custom-script',
plugins_url( 'kf-custom-script.js', __FILE__ ),
array('wp-blocks', 'wp-rich-text')
);
});
add_action( 'enqueue_block_assets', function () {
wp_enqueue_style( 'kf-custom-style', plugins_url( 'style.css', __FILE__ ) );
});
Run Code Online (Sandbox Code Playgroud)
kf-自定义脚本.js
(function(wp){
console.log(wp);
// Create Popover
const { Popover } = wp.components;
var MyCustomButton = function( props ) {
return wp.element.createElement(
wp.blockEditor.RichTextToolbarButton, {
icon: 'editor-code',
title: 'Tooltip',
onClick: function() {
console.log('Open Popup on this event');
props.onChange( wp.richText.toggleFormat(
props.value,
{ type: 'my-custom-format/kf-tooltip' }
) );
},
isActive: props.isActive,
}
);
}
var clickHandler = function( props ) {
console.log('Open Popup on this event');
return 'test';
}
wp.richText.registerFormatType(
'my-custom-format/kf-tooltip', {
title: 'Tooltip',
tagName: 'span',
className: 'kf-tooltip',
edit: MyCustomButton,
click: clickHandler
}
);
})(window.wp)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1357 次 |
最近记录: |