jQuery 等待 TinyMCE 加载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7408559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wait for TinyMCE to load
提问by Pit Digger
I have these two lines of code one after another.
我有这两行代码一行一行。
tinymce.execCommand('mceAddControl',true,'email_body');
tinyMCE.activeEditor.setContent(data.tplCustom.htmltemplate);
Second line tries to set content even before the tinymce is done . I think cause of that I am getting " tinyMCE.activeEditor is null" error.
第二行甚至在 tinymce 完成之前尝试设置内容。我认为我收到“tinyMCE.activeEditor is null”错误的原因。
Is there any way to wait until its loaded ? Thanks
有没有办法等到它加载?谢谢
回答by Red Taz
Version 4 of TinyMCE uses a slightly different event binding method.
TinyMCE 的第 4 版使用稍微不同的事件绑定方法。
Version 3
版本 3
// v3.x
tinymce.init({
setup : function(ed) {
ed.onInit.add(function(ed) {
console.debug('Editor is done: ' + ed.id);
});
}
});
Version 4
版本 4
// v4.x
tinymce.init({
setup: function (ed) {
ed.on('init', function(args) {
console.debug(args.target.id);
});
}
});
Reference: http://www.tinymce.com/wiki.php/API3:event.tinymce.Editor.onInithttp://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x
参考:http ://www.tinymce.com/wiki.php/API3: event.tinymce.Editor.onInit http://www.tinymce.com/wiki.php/Tutorial:Migration_guide_from_3.x
回答by Camille Descombes
If you cannot access to the tinymce.init({...})
declaration (like in WordPressfor example), you can also use addeditor
event :
如果您无法访问tinymce.init({...})
声明(例如在WordPress中),您还可以使用addeditor
event :
/// Fires when an editor is added to the EditorManager collection.
tinymce.on('addeditor', function( event ) {
var editor = event.editor;
var $textarea = $('#' + editor.id);
console.log($textarea.val());
}, true );