Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit 9f53b3b

Browse files
committed
ux improvements to codetag plugin
1 parent 7475de6 commit 9f53b3b

File tree

1 file changed

+31
-13
lines changed
  • ckeditor/static/ckeditor/ckeditor/plugins/codeTag

1 file changed

+31
-13
lines changed
Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
CKEDITOR.plugins.add( 'codeTag', {
1+
CKEDITOR.plugins.add('codeTag', {
22
icons: 'code',
3-
init: function( editor ) {
4-
editor.addCommand( 'wrapCode', {
5-
exec: function( editor ) {
6-
editor.insertHtml( '<code>' + editor.getSelection().getSelectedText() + '</code>' );
7-
}
3+
init(editor) {
4+
var style = new CKEDITOR.style({ element: 'code' }),
5+
forms = ['code'];
6+
7+
// Put the style as the most important form.
8+
forms.unshift(style);
9+
10+
// Listen to contextual style activation.
11+
editor.attachStyleStateChange(style, function (state) {
12+
!editor.readOnly && editor.getCommand('wrapCode').setState(state);
813
});
9-
editor.ui.addButton( 'Code', {
10-
label: 'Wrap code',
11-
command: 'wrapCode',
12-
toolbar: 'insert'
13-
});
14-
}
15-
});
14+
15+
// Create the command that can be used to apply the style.
16+
editor.addCommand('wrapCode', new CKEDITOR.styleCommand(style, {
17+
contentForms: forms,
18+
}));
19+
20+
// Register the button, if the button plugin is loaded.
21+
if (editor.ui.addButton) {
22+
editor.ui.addButton('Code', {
23+
label: 'Code',
24+
command: 'wrapCode',
25+
toolbar: 'insert',
26+
});
27+
}
28+
29+
editor.setKeystroke([
30+
[CKEDITOR.CTRL + 75, 'wrapCode'],
31+
]);
32+
},
33+
});

0 commit comments

Comments
 (0)