TinyMCE v4.3.6 - 快捷方式

TinyMCE v4.3.6 - Shortcuts

本文关键字:快捷方式 v4 TinyMCE      更新时间:2023-09-26

我正在使用TinyMCE v4.3.6。由于默认快捷键"alt gr + f",我无法在编辑器中写入字符"["。如何禁用快捷方式"alt gr + f"?

请查看我的初始化代码和下面的评论:

tinymce.init({
    selector: 'textarea.my-textarea-content',
    theme: 'modern',
    schema: 'html5-strict',
    menubar: false,
    // editor size
    width        : 770,
    height        : 500,
    min_height    : 500,
    autoresize_min_height: 500,
    convert_urls: false,
    relative_urls: true,
    inline: false,
    setup: function(ed) {
    ed.on('init', function(event) {
        var hidTinyData = $('.my-tinymce-data');
        // fullscreen custom shortcut
        ed.addShortcut('CTRL+SHIFT+F9', 'Fullscreen', 'mceFullScreen', this);
        // trying to override default behaviour for "alt gr + f"
        // but it is not working as expected
        ed.addShortcut('ctrl+alt+f', '', '', function () {});
        ed.addShortcut('meta+alt+f', '', '', function () {});
        ed.remove('meta+f');
        ed.setContent(hidTinyData.val());
        ed.execCommand('mceRepaint');
    });
},
plugins: ['advlist autolink lists link charmap hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code contextmenu
fullscreen ', 'nonbreaking table textcolor paste autoresize'],
contextmenu: 'inserttable tableprops deletetable cell row column | hr',
toolbar1: 'newdocument | searchreplace | fontselect fontsizeselect
formatselect table | bullist numlist | outdent indent removeformat | fullscreen ',
toolbar2: 'undo redo | bold italic underline strikethrough subscript
superscript | forecolor backcolor | alignleft aligncenter alignright
alignjustify | blockquote hr | visualchars visualblocks | code'
});

在以下链接中找到解决方法:https://stackoverflow.com/a/19836730/2614103

我更新的代码:

tinymce.init({
selector: 'textarea.my-textarea-content',
theme: 'modern',
schema: 'html5-strict',
menubar: false,
// editor size
width        : 770,
height        : 500,
min_height    : 500,
autoresize_min_height: 500,
convert_urls: false,
relative_urls: true,
inline: false,
setup: function(ed) {
ed.on('init', function(event) {
    // add custom shortcut for fullscreen
    ed.addShortcut('CTRL+SHIFT+F9', 'Fullscreen', 'mceFullScreen', this);
    // content
    ed.setContent($('.my-tinymce-data').val());
        // repaint editor
        ed.execCommand('mceRepaint');
    });
    ed.on('keyup', function(e) {
        overrideKeyboardEvent(e, ed);
    });
    ed.on('keydown', function( e) {
        overrideKeyboardEvent(e, ed);
    });
},
plugins: ['advlist autolink lists link charmap hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code contextmenu
fullscreen ', 'nonbreaking table textcolor paste autoresize'],
contextmenu: 'inserttable tableprops deletetable cell row column | hr',
toolbar1: 'newdocument | searchreplace | fontselect fontsizeselect
formatselect table | bullist numlist | outdent indent removeformat | fullscreen ',
toolbar2: 'undo redo | bold italic underline strikethrough subscript
superscript | forecolor backcolor | alignleft aligncenter alignright
alignjustify | blockquote hr | visualchars visualblocks | code'
});
overrideKeyboardEvent: function(e, ed) {
    switch (e.type) {
        case 'keydown':
            if (e.keyCode == 9 && !e.altKey && !e.ctrlKey) {
                // toggle between Indent and Outdent 
                // command, depending on if SHIFT is pressed
                if (e.shiftKey) {
                    ed.execCommand('Outdent');
                } else {
                    ed.execCommand('Indent');
                }
                // cancel default action for keys Tab and Shift+Tab
                if (e.preventDefault) {
                    e.preventDefault();
                }
                return tinymce.dom.Event.cancel(e);
            } else if (e.keyCode == 27 && !e.altKey && !e.ctrlKey) {
                // check if fullscreen is on
                if ($('.mce-fullscreen').length) {
                    ed.execCommand('mceFullScreen');
                }
            } else if (e.keyCode == 70 && e.altKey && e.ctrlKey) {
                e.stopPropagation();
                e.preventDefault();
                // insert character '['
                ed.insertContent('[');
                return false;
            }
        break;
    }
    return true;
}
$(document).ready(function($) {
    document.onkeydown = overrideKeyboardEvent;
    document.onkeyup = overrideKeyboardEvent;
});