Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions plugin.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
CKEDITOR.plugins.add( 'codeTag', {
icons: 'code',
init: function( editor ) {
editor.addCommand( 'wrapCode', {
exec: function( editor ) {
editor.insertHtml( '<code>' + editor.getSelection().getSelectedText() + '</code>' );
}
});
editor.ui.addButton( 'Code', {
label: 'Wrap code',
command: 'wrapCode',
toolbar: 'insert'
});

var style = new CKEDITOR.style( { element: 'code' } );

// Listen to contextual style activation.
editor.attachStyleStateChange( style, function (state) {
!editor.readOnly && editor.getCommand( 'wrapCode').setState(state);
} );

// Create the command.
editor.addCommand( 'wrapCode', new CKEDITOR.styleCommand( style ) );

// Register the button, if the button plugin is enabled.
if ( editor.ui.addButton ) {
editor.ui.addButton( 'Code', {
label: 'Code',
command: 'wrapCode',
toolbar: 'insert'
} );
}
}
});
});