微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery – 限制TinyMCE编辑器中的键盘快捷键

试图找到在jQuery版本的TinyMCE编辑器中禁用单个键盘快捷键的位置.目前,允许的快捷方式列表是:

> ctrl z撤消
> ctrl y重做
> ctrl b Bold
> ctrl我的斜体
> ctrl u下划线
> ctrl 1-6 h1-h6
> ctrl 7 p
> ctrl 8 div
> ctrl 9地址

目前正在禁用所有快捷键,但是撤消,重做和粗体.由于它是不需要的格式化,其余的在我们的实现中是不统一的.

我似乎找不到启用这些快捷方式的代码.你能指出哪里找到这个代码.

解决方法

在Firefox中禁用测试

这应该帮助你开始.您可能需要为ctrl u和ctrl i添加空的快捷方式才能在其他浏览器中禁用它,但是此代码已经过测试以禁用Firefox中的操作.只是运行在初始化的tinyMCE已经运行(我测试我的在Firebug):

for(var i in tinyMCE.editors){
  var editor = tinyMCE.editors[i];
  for(var s in editor.shortcuts){
    var shortcut = editor.shortcuts[s];
    // Remove all shortcuts except Bold (66),Redo (89),Undo (90)
    if(!(s == "ctrl,66" || s == "ctrl,89" || s == "ctrl,90")){
       // This completely removes the shortcuts
       delete editor.shortcuts[s];

       // You Could use this instead,which just disables it,but still keeps
       // browser functionality (like CMD+U = show source in FF Mac) from interrupting the flow
       // shortcut.func = function(){  };
    }
  }
}

背景

它似乎是围绕jscripts / tiny_mce / classes / Editor.js的2294行定义的(从完整的开发下载).

而且,它们存储在Editor.shortcuts变量中的数组中.他们的键是使用特殊的字符设置键码,如下所示:ctrl,90.

但是从我可以看出,似乎很多浏览器实现了自己的ctrl b,ctrl i和ctrl u版本,只有Gecko浏览器没有:

// Add default shortcuts for gecko
if (isGecko) {
    t.addShortcut('ctrl+b',t.getLang('bold_desc'),'Bold');
    t.addShortcut('ctrl+i',t.getLang('italic_desc'),'Italic');
    t.addShortcut('ctrl+u',t.getLang('underline_desc'),'Underline');
}

但是如果你环顾四周,你可以看看它们是如何启用的.

另外,查看Editor.addShortcut方法.您可能可以覆盖认行为.

原文地址:https://www.jb51.cc/jquery/176186.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐