我的目标是创建一个自定义控件以在对话框的主体打开宽度中使用editor.windowManager.open
。
我在github上找到了标准控件源类,但是找不到通过插件添加新控件的方法。
https://github.com/tinymce/tinymce/tree/master/js/tinymce/classes/ui
经过数小时的搜索,我找不到任何文档、教程或 stackoverflow 响应。然后我尝试在插件中包含控件声明,但我得到一个ReferenceError: define is not defined
.
tinymce.PluginManager.add('my_plugin',function(editor,url){
// My custom control declaration following standard control found in source file
define("tinymce/ui/MyControl", [ "tinymce/ui/Widget" ],
function(Widget) {
"use strict";
return Widget.extend({
/**
* Renders the control as a HTML string.
*/
renderHtml: function() {
return '<div class="my-control">'+ this.state.get('text') +'</div>';
}
});
});
// Toolbar button to open the dialog
editor.addButton('my_plugin',{
title: 'My Plugin button',
text: 'My Plugin button',
onclick: function(){
// Dialog declaration
editor.windowManager.open({
title: 'My dialog',
body: [
{ type: 'textbox', name: 'textbox', label: 'My textbox' },
{ type: 'mycontrol', name: 'mycontrol', label: 'My Control' },
],
onsubmit: function( e ){
editor.insertContent( e.data.textbox );
}
});
},
});
});
// Init tinyMCE
tinymce.init({
selector: '#mytextarea',
plugins: 'my_plugin',
toolbar: 'my_plugin'
});
可以添加自定义控件,如果可以,如何实现?
找到两个 jsfiddle,第一个带有标准控件,第二个带有我的尝试和浏览器控制台中的错误
谢谢你的帮助