Deactivate shortcut keys for Dijit Editor Dojo
I am trying to use the dijit.Editor widget. I do not have the need for all the plugins, such as bold, italic, lists, etc.开发者_开发问答 By not including them in the plugins list, they do not appear in the toolbar. But the shortcut key mapping is still present.
I tried to subclass dijit.Editor and override the setupDefaultShortcuts method, but this does not seem to solve the problem.
Is there a way to override the shortcut key mappings?
What you stated in the question works for me... Don't even have to extend, just clobber the function by passing a new empty one in.
dojo.require('dijit.Editor');
dojo.ready(function() {
var ed = new dijit.Editor({
setupDefaultShortcuts: function(){},
}).placeAt(dojo.body());
ed.startup();
});
If you do want to extend, it's just as easy:
dojo.require('dijit.Editor');
dojo.ready(function() {
dojo.declare('MiniEditor', dijit.Editor, {
constructor: function() {
//executes after inherited constructor, overriding plugins
this.plugins = [];
},
setupDefaultShortcuts: function(){}
});
var ed = new MiniEditor({}).placeAt(dojo.body());
ed.startup();
});
I'm no means a dojo expert, so a better will likely come along, but one way that I found to accomplish this is by altering the member variable _keyHandlers
within the editor class.
var editor = new dijit.Editor({plugins:plugins},
dojo.byId('myEditor'));
delete editor._keyHandlers['b'];
The first line would create the new editor with the altered plugins list. The second line deletes the key handler for b
which would be bold. You could do the same for any other keys you want to remove. If you want to remove them all I'm guessing you could just set _keyHandlers
equal to a new array.
I'm not sure why overriding setupDefaultShortcuts didn't work. Did you override it in right class? It's a method in dijit._editor.RichText
not dijit.Editor
.
Hope this helps.
精彩评论