From: http://www.voofie.com/content/2/ckeditor-plugin-development/ 根据comment有修改
CKeditor API: http://docs.cksource.com/ckeditor_api/index.html
CKEditor 是目前市场上比较灵活的在线WYSIWYG编辑器之一. 它灵活的设计, 开放的API和详细的文档使得用户扩展功能非常容易. 本文尝试勾勒出 CKEditor插件开发的基础,包含了增加按钮,对话框和执行命令.
1
2
3
4
5
6
7
|
CKEDITOR.plugins.add(
'footnote'
,
{
init:
function
(editor)
{
//plugin code goes here
}
});
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
CKEDITOR.plugins.add(
'footnote'
,
{
init:
function
(editor)
{
var
pluginName =
'footnote'
;
CKEDITOR.dialog.add(pluginName,
this
.path +
'dialogs/footnote.js'
);
editor.addCommand(pluginName,
new
CKEDITOR.dialogCommand(pluginName));
editor.ui.addButton(
'Footnote'
,
{
label:
'Footnote or Citation'
,
command: pluginName
});
}
});
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
CKEDITOR.plugins.add(
'myplugin'
,
{
init:
function
(editor)
{
//plugin code goes here
editor.ui.addButton(
'myplugin'
,
{
label:
'myplugin'
,
command: FCKCommand_myplugin,
icon: CKEDITOR.plugins.getPath(
'myplugin'
) +
'myplugin.png'
});
}
});
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
(
function
(){
var
exampleDialog =
function
(editor){
return
{
title :
/* title in string*/
,
minWidth :
/*number of pixels*/
,
minHeight :
/*number of pixels*/
,
buttons:
/*array of button definitions*/
,
onOk:
/*function*/
,
onLoad:
/*function*/
,
onShow:
/*function*/
,
onHide:
/*function*/
,
onCancel:
/*function*/
,
resizable:
/* none,width,height or both */
,
contents:
/*content definition, basically the UI of the dialog*/
}
}
CKEDITOR.dialog.add(
'insertHTML'
,
function
(editor) {
return
exampleDialog(editor);
});
})();
|
1
2
3
4
5
6
7
8
|
buttons:[{
type:
'button'
,
id:
'someButtonID'
,
/* note: this is not the CSS ID attribute! */
label:
'Button'
,
onClick:
function
(){
//action on clicking the button
}
},CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton],
|
1
2
3
4
5
6
7
8
9
10
11
|
contents: [{
id:
'page1'
,
/* not CSS ID attribute! */
label:
'Page1'
,
accessKey:
'P'
,
elements:[
/*elements */
]
}, {
id:
'page2'
,
label:
'Page2'
,
accessKey:
'Q'
,
elements:[
/*elements*/
]
}]
|
1
2
3
4
5
6
7
8
9
10
|
elements:[{
type :
'hbox'
,
widths : [
'100px'
,
'100px'
,
'100px'
],
children :
[{
type:
'html'
,
html:
'<div>Cell1'
,
},{
type:
'html'
,
html:'
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
if
(editor.addMenuItems)
{
editor.addMenuItems(
//have to add menu item first
{
insertCode:
//name of the menu item
{
label:
'Code'
,
command:
'insertCode'
,
group:
'insertCode'
//have to be added in config
}
});
}
if
(editor.contextMenu)
{
editor.contextMenu.addListener(
function
(element, selection)
//function to be run when context menu is displayed
{
if
(! element || !element.is(
'pre'
))
return
null
;
return
{ insertCode: CKEDITOR.TRISTATE_OFF };
});
}
|