Restrict keyboard shortcuts in TinyMCE editor

后端 未结 5 1377
名媛妹妹
名媛妹妹 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 17:10

    OK so I was able to get this to work. I was able to block firefox using Doug's code above to get IE to disable the key's I wanted I had to add this code after Doug's code block.

    var $iframe = $('iframe').contents().get(0);
    
    $($iframe).keydown(function(oEvent) {
        //italics (ctrl+i & Cmd+i [Safari doesn't allow you to test for Cmd])
        if (oEvent.keyCode == '73' && (oEvent.metaKey || oEvent.ctrlKey)){
            oEvent.preventDefault();
            return false;
        }
    
        //underline (ctrl+u & cmd+u [Safari doesn't allow you to test for cmd])
        if (oEvent.keyCode == '85' && (oEvent.metaKey || oEvent.ctrlKey)){
            oEvent.preventDefault();
            return false;
        }
    });
    

    So basically TinyMCE dynamically loads the editor as a iFrame so I disabled the Ctrl+u and Ctrl+i from the iFrame. I what till the iFrame is finished loading and then attach a keydown event and sniff for Ctrl+i and Ctrl+i (I also sniff Cmd+i and Cmd+u for the mac [although Safari won't let you test for cmd according to this link. Everything else is disabled that I need disabled.

提交回复
热议问题