2016-03-03 117 views
0

我正在使用TinyMCE v4.3.6。由于缺省快捷键“alt gr + f”,我不能在我的编辑器中编写字符“[”。如何禁用快捷键“alt gr + f”?TinyMCE v4.3.6 - 快捷方式

请看看下面我的初始化代码和注释:

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' 
}); 

回答

0

发现以下链接变通方法: 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; 
});