CKEditor中有用的方法和事件
调用或初始化CKeditor
检查CKEditor是否可用
销毁或删除CKeditor实例
粘贴事件
获得焦点或失去焦点事件
最大化或最小化事件
定义对话框事件
图片对话框
表格对话框
获取当前对话框,对话框标签页以及标签页组件
设置对话框中输入的值
获取对话框中输入的值
强制应用js脚本或css样式表文件
工具栏按钮按下事件
双击事件(例子中包含屏蔽双击超链接弹出对话框的代码)
代码:
<textarea name="htmlcontent" id="myckeditor" > hi.! I am Ckeditor </textarea>
CKEDITOR.replace('myckeditor');
代码:
var isCkeditor = typeof CKEDITOR.instances[myckeditor] != 'undefined';
代码:
if(typeof CKEDITOR.instances[myckeditor] != 'undefined') {
setTimeout(function () {
CKEDITOR.instances[myckeditor].updateElement();
CKEDITOR.instances[myckeditor].destroy();
}, );
}
代码:
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.on('paste', function(evt) {
if (evt.data.type == 'html') {
// when paste as plain text or direct paste in ckeditor body.
}
if (evt.data.type == 'text') {
// when paste as text or paste from word.
}
});
});
代码:
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.on('focus', function(evt) {
console.log(“Editor focused”)
});
ev.editor.on('blur', function(evt) {
console.log(“Editor blur”)
});
});
代码:
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.on('maximize', function(evt) {
console.log('maximized');
});
ev.editor.on('minimize', function(evt) {
console.log('minimized');
});
});
代码:
CKEDITOR.on('dialogDefinition', function (ev) {
});
代码:
CKEDITOR.on('dialogDefinition', function(ev) {
if (ev.data.name == 'image') {}
});
代码:
CKEDITOR.on('dialogDefinition', function(ev) {
if (ev.data.name == 'table') {}
});
代码:
CKEDITOR.on('dialogDefinition', function(ev) {
if (ev.data.name == 'image') {
var infoTab = ev.data.definition.getContents('info'); //get contents of infotab in image dialog
var browseBtn = infoTab.get('browse'); //get specific element in info tab
//here do some action (onclick, focus) of element
}
});
代码:
var CurrentDialog = CKEDITOR.dialog.getCurrent();
CurrentDialog.selectPage('info');
var urlInput = CurrentDialog.getContentElement('info', 'txtUrl');
urlInput.setValue('pic/flowers.jpg');
代码:
urlInput.getValue();
代码:
var head = CKEDITOR.instances.Content.document.getHead();
var myscript = CKEDITOR.document.createElement('link', {
attributes: {
type: 'text/css',
rel: 'stylesheet',
'href': 'mytemp.css'
}
});
head.append(myscript);
代码:
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.on('afterCommandExec', function(event){
if (event.data.name == 'unlink')
alert("unlink button pressed!");
});
};
代码:
CKEDITOR.on('instanceReady', function(ev) {
ev.editor.on('doubleclick', function(evt){
var element = evt.data.element;
if (element.is('a')){
evt.stop(); // don't do the other listeners
// optionally put your code
}
});
};