为窗口管理器添加自定义控件
TinyMCE add custom control for windowManager
我的目标是创建一个自定义控件,用于对话框的主体打开宽度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,第一个是标准控件,第二个是我的尝试和浏览器控制台的错误
谢谢你的帮助
我也一直在纠结这个问题很长时间了…
用
定义控件后tinymce.ui.MyControl = tinymce.ui.Widget.extend({...})
我必须将构造函数添加到'tinymce.ui.Factory ':
tinymce.ui.Factory.add( 'mycontrol', tinymce.ui.MyControl );
工作示例:
// Stolen from tinymce.ui.TextBox:
// https://github.com/tinymce/tinymce/blob/master/src/ui/src/main/js/TextBox.js
tinymce.ui.MyControl = tinymce.ui.Widget.extend({
/**
* Constructs a instance with the specified settings.
*
* @constructor
* @param {Object} settings Name/value object with settings.
* @setting {String} format
*/
init: function(settings) {
var self = this;
self._super(settings);
self.classes.add('mycontrol');
},
/**
* Repaints the control after a layout operation.
*
* @method repaint
*/
repaint: function() {
var self = this, style, rect, borderBox, borderW = 0, borderH = 0, lastRepaintRect;
style = self.getEl().style;
rect = self._layoutRect;
lastRepaintRect = self._lastRepaintRect || {};
// Detect old IE 7+8 add lineHeight to align caret vertically in the middle
var doc = document;
if (!self.settings.multiline && doc.all && (!doc.documentMode || doc.documentMode <= 8)) {
style.lineHeight = (rect.h - borderH) + 'px';
}
borderBox = self.borderBox;
borderW = borderBox.left + borderBox.right + 8;
borderH = borderBox.top + borderBox.bottom + (self.settings.multiline ? 8 : 0);
if (rect.x !== lastRepaintRect.x) {
style.left = rect.x + 'px';
lastRepaintRect.x = rect.x;
}
if (rect.y !== lastRepaintRect.y) {
style.top = rect.y + 'px';
lastRepaintRect.y = rect.y;
}
if (rect.w !== lastRepaintRect.w) {
style.width = (rect.w - borderW) + 'px';
lastRepaintRect.w = rect.w;
}
if (rect.h !== lastRepaintRect.h) {
style.height = (rect.h - borderH) + 'px';
lastRepaintRect.h = rect.h;
}
self._lastRepaintRect = lastRepaintRect;
self.fire('repaint', {}, false);
return self;
},
/**
* Renders the control as a HTML string.
*
* @method renderHtml
* @return {String} HTML representing the control.
*/
renderHtml: function() {
var self = this, id = self._id, settings = self.settings, value = self.encode(self.state.get('value'), false), extraAttrs = '';
if (self.disabled()) {
extraAttrs += ' disabled="disabled"';
}
return '<input type="range" id="' + id + '" class="' + self.classes + '" value="' + value + '" hidefocus="1"' + extraAttrs + ' />';
},
value: function(value) {
if (arguments.length) {
this.state.set('value', value);
return this;
}
// Make sure the real state is in sync
if (this.state.get('rendered')) {
this.state.set('value', this.getEl().value);
}
return this.state.get('value');
},
/**
* Called after the control has been rendered.
*
* @method postRender
*/
postRender: function() {
var self = this;
self._super();
self.$el.on('change', function(e) {
self.state.set('value', e.target.value);
self.fire('change', e);
});
},
bindStates: function() {
var self = this;
self.state.on('change:value', function(e) {
if (self.getEl().value != e.value) {
self.getEl().value = e.value;
}
});
self.state.on('change:disabled', function(e) {
self.getEl().disabled = e.value;
});
return self._super();
},
remove: function() {
this.$el.off();
this._super();
}
});
tinymce.ui.Factory.add( 'mycontrol', tinymce.ui.MyControl );
// `mycontrol` is now available.
我已经相应地更新了你的提琴
相关文章:
- 在angularjs中创建自定义控件的推荐方法
- 自定义控件中的双向绑定在SAPUI5中不起作用
- 如何使用ngModel将自定义控件的提供程序扩展器分离到Angular 2中的单独文件中
- Google Maps Javascript v3 自定义控件子类化标准控件
- 优化自定义控件的脚本
- 从谷歌地图自定义控件打开离子模态时遇到问题
- ASP.net自定义控件,下拉值必须在服务器端填充,所选值在返回时丢失
- UpdatePanel中自定义控件内的动态javascript
- 操作无法使用自定义控件上的呈现属性集,该控件包含操作按钮
- Lightswitch HTML 自定义控件仅显示一次
- 自定义控件呈现两次
- asp.net ajaxtoolkit 自定义控件扩展器
- 传单:如何在自定义控件中设置 panTo 方法
- 尝试锁定自定义控件,但在页面中有多个控件时出现问题
- 使用自定义控件构建开放层
- 传单:使用分组图层控件插件扩展自定义控件
- 网格视图自定义控件和 JavaScript 函数 c#
- 要在不同 VS 解决方案中的多个应用中使用的自定义控件
- 如何在自定义控件中添加.js文件引用
- 为窗口管理器添加自定义控件