2017-04-25 95 views
0

我查看了许多线程,但无法找到解决我问题的答案。所以,我定义了一个CKEditor的情况下,像这样:无法捕捉到CKEditor更改事件

var editor = $('#test-editor'); 

editor.ckeditor(function() {}, { 
    customConfig: '../../assets/js/custom/ckeditor_config.js', 
    allowedContent: true 
}); 

但是我不知道我怎么能赶上change事件。这是我试过的:

var t = editor.ckeditor(function() { 
    this.on('change', function() { 
    console.log("test 1"); 
    }); 
}, { 
    customConfig: '../../assets/js/custom/ckeditor_config.js', 
    allowedContent: true 
}); 

editor.on('change', function() { 
    console.log("test 2"); 
}); 

t.on('change', function() { 
    console.log("test 3"); 
}); 

所有这三次尝试都以失败告终。我应该补充一点,我不想循环浏览一个页面上的所有编辑器,我只想解决一个编辑器在#test-editor处渲染的特定编辑器。我怎样才能做到这一点?

+0

BTW,我看到我的编辑变量包含一个承诺对象。但我从来没有与他们交涉,我不知道我怎么能用这个事实来赶上事件, – Jacobian

回答

1

jQuery ckeditor()方法返回一个jQuery对象,该对象仅在其event handling中公开CKEditor的5个事件。为了使用其他事件,您需要通过访问jQuery对象的editor属性来使用CKEditor.editor对象。

所以,你需要使用这样的事情:

var myeditor = $('#test-editor').ckeditor({ 
    customConfig: '../../assets/js/custom/ckeditor_config.js', 
    allowedContent: true 
}); 
myeditor.editor.on('change', function(evt) { 
    console.log('change detected'); 
}); 
+0

谢谢!顺便说一下,你可能还知道关于CKEditor的更多信息。对我来说,它看起来像格式,字体和大小组合框占据了太多的地方在工具栏上。你知道吗,如果有可能把它们改成图标或一些自定义的字母? – Jacobian

+0

我曾经为了乐趣而改变了他们的标签,但是宽度保持不变(可能是因为他们的物品的宽度)。 – Wizard