我该如何调用tinymce插件函数?如何调用TinyMCE插件函数?
tinymce.activeEditor.plugins.customplugin.customfunction(customvar);
不工作!
我该如何调用tinymce插件函数?如何调用TinyMCE插件函数?
tinymce.activeEditor.plugins.customplugin.customfunction(customvar);
不工作!
tinymce.activeEditor.plugins.customplugin.customfunction(customvar);
是调用此功能的正确方法。 请注意,tinymce.activeEditor
需要设置才能使用它。例如,当用户点击编辑器时, tinymce.activeEditor
被设置。 否则使用
tinymce.get('your_editor_id_here').plugins.customplugin.customfunction(customvar);
有可能是另一个原因您的函数调用不工作: 要调用需要的功能一样的功能getInfo
,在保存插件_save
和_nodeChange
(请参阅开发人员定义构建tinymce来检查插件目录中的插件)。
在这里保存插件缩短:
(function() {
tinymce.create('tinymce.plugins.Save', {
init : function(ed, url) {
...
},
getInfo : function() {
...
},
// Private methods
_nodeChange : function(ed, cm, n) {
...
},
// Private methods
...
_save : function() {
}
});
// Register plugin
tinymce.PluginManager.add('save', tinymce.plugins.Save);
})();
您可以使用下面的JavaScript调用调用该插件的getInfo
功能:
tinymce.get('your_editor_id_here').plugins.save.getInfo();
参考:https://github.com/tinymce/tinymce/blob/master/js/tinymce/plugins/save/plugin.js – Fred 2015-04-29 09:01:52
此链接现在不是最新版本,因为插件的更新版本现在在plugin.add()方法的参数中使用了一个匿名函数 – 2016-04-19 15:09:33
将要暴露给外界的功能在self
。
tinymce.PluginManager.add('myplugin', function(editor) {
var self = this;
var self.myFunction = myFunction(); // Put function into self!
function myFunction() {
console.log('Hello world!');
}
}
然后:
tinymce.get('your_editor_id_here').plugins.myplugin.myFunction();
+1清楚的问题 – Thariama 2012-08-10 08:31:56