This repository was archived by the owner on Nov 29, 2023. It is now read-only.
File tree 1 file changed +31
-13
lines changed
ckeditor/static/ckeditor/ckeditor/plugins/codeTag
1 file changed +31
-13
lines changed Original file line number Diff line number Diff line change 1
- CKEDITOR . plugins . add ( 'codeTag' , {
1
+ CKEDITOR . plugins . add ( 'codeTag' , {
2
2
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 ) ;
8
13
} ) ;
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments