博客园中TinyMCE编辑器的快捷键

今天本来想找些TinyMCE编辑器的快捷键的使用的,结果搜索到了禁用的文章,问题不大,最起码解决了咱们的问题,下面直接给出文章和出处供参考吧!

 

=======================================================================================

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 Undo
  • ctrl+y Redo
  • ctrl+b Bold
  • ctrl+i Italic
  • ctrl+u Underline
  • ctrl+1-6 h1-h6
  • ctrl+7 p
  • ctrl+8 div
  • ctrl+9 address

Currently looking to disable all shortcuts but Undo, Redo and bold. The rest are unnessary in our implementation due to it's unwanted formatting.

I can't seem to find the code that enables these shortcuts. Can you point out where to find this code.

解决方案

Disable Tested in Firefox

This should help get you started. You might need to actually add empty shortcuts for ctrl+u and ctrl+i to disable it in other browsers, but this code has been tested to disable the actions in Firefox. Just run after the initialization of tinyMCE has run (I tested mine in 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(){  };
    }
  }
}

Background

It appears to be defined around line 2294 of jscripts/tiny_mce/classes/Editor.js (From the full development download).

Also, they are stored in an array in the Editor.shortcuts variable. They keys are setup with special chars then the keycode, like this: ctrl,,,90.

But from what I can tell, it seems that many browser implement their own versions of ctrl+b, ctrl+i, and ctrl+u and that only Gecko browsers do not:

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

But if you look around there, you can see how they enable it.

Additionally, look into the Editor.addShortcut method. You might be able to override the default behavior.

 

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

  • ctrl + z 撤消
  • ctrl + y 重做
  • ctrl + b 粗体
  • ctrl + i 斜体
  • 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 方法.您也许可以覆盖默认行为.

本文地址:限制TinyMCE编辑器中的键盘快捷键

 

出处:https://www.it1352.com/1486800.html

posted on 2021-05-28 16:35  jack_Meng  阅读(545)  评论(0编辑  收藏  举报

导航