Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ckeditor turn off enter key

I am trying to use ckeditor to edit single lines so I don't want users to be able to use the enter key. Does anyone know how to stop the enter key from being used?

I tried $("#text").keypress(function(event){ alert(event.keyCode); }); But it didn't register. Thanks for any help.

like image 600
jsonlehman Avatar asked Dec 28 '22 10:12

jsonlehman


1 Answers

Here's what I did. I created a dummy plugin called 'doNothing'. Just create a 'doNothing' directory under 'plugins', then paste the following code into a plugin.js file there.

(function()
{
    var doNothingCmd =
    {
        exec : function( editor )
        {
            return;
        }
    };
    var pluginName = 'doNothing';
    CKEDITOR.plugins.add( pluginName,
    {
        init : function( editor )
        {
            editor.addCommand( pluginName, doNothingCmd );
        }
    });
})();

Add the plugin to your config.js file with config.extraPlugins = 'doNothing';, then put in

config.keystrokes =
[
    [ 13 /*Enter*/, 'doNothing'],
    [ CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ],
    [ CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus' ],

    [ CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' ],

    [ CKEDITOR.CTRL + 90 /*Z*/, 'undo' ],
    [ CKEDITOR.CTRL + 89 /*Y*/, 'redo' ],
    [ CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo' ],

    [ CKEDITOR.CTRL + 76 /*L*/, 'link' ],

    [ CKEDITOR.CTRL + 66 /*B*/, 'bold' ],
    [ CKEDITOR.CTRL + 73 /*I*/, 'italic' ],
    [ CKEDITOR.CTRL + 85 /*U*/, 'underline' ],

    [ CKEDITOR.ALT + 109 /*-*/, 'toolbarCollapse' ]
];

Voila! Now the enter key does absolutely nothing. You should also be able assign 'doNothing' to any other key you want to disable, though I haven't tried others myself.

like image 55
kmw Avatar answered Jan 12 '23 14:01

kmw