Restrict keyboard shortcuts in TinyMCE editor

后端 未结 5 1378
名媛妹妹
名媛妹妹 2021-02-08 16:20

Trying to find where to disable individual keyboard shortcuts in the jQuery version of TinyMCE editor. Currently the list of allowable shortcuts is:

  • ctrl+z
5条回答
  •  余生分开走
    2021-02-08 16:48

    Example code to switch back and forth from allowing I B and U in both IE and FF.

    var ctrlKey = false;
    
    function removeShortcuts(){
      var e = tinyMCE.activeEditor;
      for (var s in e.shortcuts){
        if(s=="ctrl,,,73" || s=="ctrl,,,85" || s="ctrl,,,66"){
          e.shortcuts[s].func = function(){};
        }
      }
      e.onKeyUp.add(onKeyUp);
      e.onKeyDown.add(onKeyDown);
    }
    
    function resetShortcuts(){
      var e = tinyMCE.activeEditor;
      if (isGecko) {
        e.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold');
        e.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic');
        e.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline');
      }
      e.onKeyUp.remove(onKeyUp);
      e.onKeyDown.remove(onKeyDown);
    }
    
    
    function onKeyUp(editor, event){
      if(event.keyCode == 17){
        ctrlKey = false;
      }
    }
    
    function onKeyDown(editor, event){
      if(event.keyCode == 17){
        ctrlKey = true;
      }
      if(ctrlKey && (event.keyCode == 73 || event.keyCode == 85 || event.keyCode == 66){
        tinymce.dom.Event.cancel(event);
      }
    }
    

提交回复
热议问题