Reputation: 11
In Ckeditor i want to create custom shortcut key to change the font-type (font should change by pressing shortcut cut key ) Need your help
Upvotes: 0
Views: 608
Reputation: 11
for this it need a custom plugin ,i have create custom plugin like this add this code by creating a plugin name(keystorke)and add it into plugin folder
CKEDITOR.plugins.add( 'keystrokes', {
init: function( editor ) {
editor.addCommand( 'h1', {
exec: function( editor ) {
var format = { element: 'h1' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
var selectedText = editor.getSelection().getNative();
}
} );
editor.addCommand( 'h2', {
exec: function( editor ) {
var format = { element: 'h2' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.addCommand( 'h3', {
exec: function( editor ) {
var format = { element: 'h3' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.addCommand( 'h4', {
exec: function( editor ) {
var format = { element: 'h4' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.addCommand( 'h5', {
exec: function( editor ) {
var format = { element: 'h5' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.addCommand( 'h6', {
exec: function( editor ) {
var format = { element: 'h6' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.addCommand( 'p', {
exec: function( editor ) {
var format = { element: 'p' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.setKeystroke( CKEDITOR.ALT + 49 , 'h1' ); // ALT + 1
editor.setKeystroke( CKEDITOR.ALT + 50 , 'h2' ); // ALT + 2
editor.setKeystroke( CKEDITOR.ALT + 51 , 'h3' ); // ALT + 3
editor.setKeystroke( CKEDITOR.ALT + 52 , 'h4' ); // ALT + 4
editor.setKeystroke( CKEDITOR.ALT + 53 , 'h5' ); // ALT + 5
editor.setKeystroke( CKEDITOR.ALT + 54 , 'h6' ); // ALT + 6
editor.setKeystroke( CKEDITOR.ALT + 55 , 'p' ); // ALT + 7
}
});
2 now you need to add one line in config.js file like this config.extraPlugins = 'keystrokes';
3 now it will work forsure
Upvotes: 1