Disabling tinyMCE ctrl+s shortcut to enable this shortcut for ajax content save

你离开我真会死。 提交于 2019-12-06 03:36:45

This is a tricky one. You will have to create a function like this in the main document.

function receiveShortCutEvent(eventObject){
    //console.log('receiveShortCutEvent', eventObject);
    $(document).trigger(eventObject);
    $(document).trigger({type: 'keydown', ctrlKey: eventObject.ctrlKey, altKey: eventObject.altKey, which: eventObject.keyCode, originalEvent:eventObject });
    return false; 
}

On the tinymce side you will need to call receiveShortCutEvent if ctrl+h gets typed. You may use the setup configuration paramter for this.

        ed.onKeyDown.add(function onkeydown(ed, evt) {
            // Shortcut:  ctrl+h 
            if (evt.keyCode == 72 && !evt.altKey && !evt.shiftKey && evt.ctrlKey && !evt.metaKey) {
                setTimeout(function(){
                    var e = { type : 'keydown'};
                    e.charCode = e.keyCode = e.which = 72;
                    e.shiftKey = e.altKey = e.metaKey = false;
                    e.ctrlKey = true;
                    window.parent && window.parent.receiveShortCutEvent && window.parent.receiveShortCutEvent(e);
                }, 1);
            }
});

I hope you get the idea.

Use init_instance_callback and define your custom shortcut.

Example:

tinymce.init({
    selector: "textarea",


    init_instance_callback: function (editor) {
        editor.addShortcut("ctrl+s", "Custom Ctrl+S", "custom_ctrl_s");
        editor.addCommand("custom_ctrl_s", function() {
            alert("234");
            /*
            your custom codes
            */
        });
    }


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