# ckeditor4.1 插件
# ckeditor4.1_math/plugins/blank/plugin.js
/**
* 针对试题编辑,在填空题中插入一个空格,或者删除用户通过鼠标选择的内容。
*
* @auther leichu 2018-07-09
*/
CKEDITOR.plugins.add('blank', {
init: function (editor) {
var flag4b = ' ';
var customCommand4Insert = 'iblank';
editor.addCommand(customCommand4Insert, {
// 插入填空题中的一个空,只显示下划线。
exec: function (editor) {
editor.insertHtml('<u class="_blank_" style="cursor: pointer">' + flag4b + '</u>');
}
});
var customCommand4Delete = 'dblank';
editor.addCommand(customCommand4Delete, {
exec: function () {
window.document.execCommand("delete");
}
});
editor.ui.addButton('iBlankBtn', { //按钮名称:iBlankBtn,编辑器菜单上用到
label: '插入空格', //插件名称
command: customCommand4Insert, //插件命令
icon: this.path + 'images/i.png' //编辑器菜单的图标
});
editor.ui.addButton('dBlankBtn', { //按钮名称:dBlankBtn,编辑器菜单上用到
label: '删除所选', //插件名称
command: customCommand4Delete, //插件命令
icon: this.path + 'images/r.png' //编辑器菜单的图标
});
if (editor.contextMenu) {
var menuGroupName = 'blankGroup';
editor.addMenuGroup(menuGroupName, 10);
editor.addMenuItem('iBlankItem', {
label: '插入空格',
command: customCommand4Insert, //通过命令的方式绑定
group: menuGroupName
});
editor.addMenuItem('dBlankItem', {
label: '删除所选',
command: customCommand4Delete, //通过命令的方式绑定
group: menuGroupName
});
}
//为上下文菜单添加监听器, 如果不添加这句, 我们创建的上下文菜单将无法显示在右键菜单里面.
editor.contextMenu.addListener(function (element) {
return {
'iBlankItem': CKEDITOR.TRISTATE_OFF,
'dBlankItem': CKEDITOR.TRISTATE_OFF
};
});
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
← 弹性布局 JS动态加载外部文件 →