How to disable CKEditor context menu?

核能气质少年 提交于 2019-11-27 02:08:40

问题


Does anybody know how to disable CKEditor's context (right click) menu? I would expect a configuration option, but I can't find one. I am using v3.1. Thanks.


回答1:


You need to remove the contextmenu plugin. See here for 3.1.




回答2:


As of version 3.6.4, the other answers in this question don't work anymore. See bug #9284

The three plugins that need to be disabled (using the means discussed in this question), are contextmenu, liststyle and tabletools. So for example, using config files:

CKEDITOR.editorConfig = function(config) {
    /* Your config options */
    ...
    config.removePlugins = 'contextmenu,liststyle,tabletools';
};



回答3:


Ckeditor 4.7.1

CKEDITOR.editorConfig = function (config) {
  config.language = 'en';
  config.toolbar = "mini";
  config.removePlugins = 'elementspath,contextmenu,liststyle,tabletools,tableselection';
  config.disableNativeSpellChecker = false;
}

Ckeditor 4.8.0 ('elementspath' plugin no longer need to remove)

CKEDITOR.editorConfig = function (config) {
  config.language = 'en';
  config.toolbar = "mini";
  config.removePlugins = 'contextmenu,liststyle,tabletools,tableselection';
  config.disableNativeSpellChecker = false;
}



回答4:


There is still a practical solution, by overriding the prototype function that initializes contextmenu behavior:

CKEDITOR.dom.element.prototype.disableContextMenu = function () {
    this.on( 'contextmenu', function( event ) {
        // your contextmenu behavior
    });
};

NOTE: when CKEDITOR loads its JS resources dynamically you need to place it right before the replace call.




回答5:


I needed to disable all of the following to get this to work.

config.removePlugins = 'language,tableresize,liststyle,tabletools,scayt,menubutton,contextmenu';

Previously we did not need language or tableresize - but a newer version of ckeditor seems to require that.

I discovered this in looking at the output in F12 dev tools on chrome.




回答6:


For version 4.2, I put the following at the end of my config.js file

CKEDITOR.on('instanceReady', function(ev) {
   ev.editor.editable().addClass('cke_enable_context_menu')
});



回答7:


You can find out which plugins require contextmenu in your particular build of CKEditor using the following snippet in an F12 console window in your site (assumes you have jQuery also for $.each):

$.each(CKEDITOR.plugins, function(k, v){ 
    v.requires && console.log("Plugin '" + k + "' requires: " + v.requires) 
})

For example:

Plugin 'tabletools' requires table,dialog,contextmenu

Which you can then use to help you with your config.removePlugins - in my case:

config.removePlugins = 'tabletools,contextmenu'



回答8:


With CKEditor 3.6 I was able to disable context menu by removing the contextmenu plugin as suggested above. To do this, you have to configure the editor with the removePlugins option. For instance:

CKEDITOR.replace('my_editor', {
    removePlugins : 'contextmenu'
});

It can also be disabled globally from the config.js file:

CKEDITOR.editorConfig = function(config) {
    /* Your config options */
    ...
    config.removePlugins = 'contextmenu';
};



回答9:


Unfortunately since CKEditor 3.6/4.0 this does not work anymore.

See bug report: http://dev.ckeditor.com/ticket/9284




回答10:


In CKEditor 4.x, (I tested 4.2.2) you must do both:

CKEDITOR.replace('my_editor', { removePlugins : 'contextmenu' });

And

CKEDITOR.editorConfig = function(config) {
/* Your config options */
...
config.removePlugins = ''liststyle,tabletools,contextmenu'';
};

All three of those will automatically require contextmenu if you don't disable them.




回答11:


It's possible to completely disable the context menu adding this line to your config file (tipically fckconfig.js):

FCKConfig.ContextMenu = [];



回答12:


Hold down the ctrl button while right clicking to by-pass the context menu and access spell checker etc.



来源:https://stackoverflow.com/questions/2246631/how-to-disable-ckeditor-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!