如何在TinyMCE中覆盖Ctrl + V.

时间:2008-09-23 08:24:02

标签: tinymce override keypress

我需要将粘贴文本的HTML清理为TinyMCE,方法是将其传递给Web服务,然后将其恢复到textarea中。 因此,我需要覆盖TinyMCE中的Ctrl + V来捕获文本,执行后台请求,并在返回时继续使用TinyMCE的粘贴处理程序。 首先,TinyMCE的Ctrl + V处理程序在哪里,是否有一种非破坏性的方式来覆盖它? (而不是更改源代码)

2 个答案:

答案 0 :(得分:3)

您可以编写一个处理ctrl + v事件的插件,并将其传递或修改粘贴插件。以下代码位于plugins/paste/editor_plugin.js,它处理ctrl + v事件。

  handleEvent : function(e) {
          // Force paste dialog if non IE browser
          if (!tinyMCE.isRealIE && tinyMCE.getParam("paste_auto_cleanup_on_paste", false) && e.ctrlKey && e.keyCode == 86 && e.type == "keydown") {
             window.setTimeout('tinyMCE.selectedInstance.execCommand("mcePasteText",true)', 1);
             return tinyMCE.cancelEvent(e);
          }

          return true;
       },

以下是一些more information about creating plug-ins for tinyMCE

答案 1 :(得分:0)

Tiny Editor有一个名为“ paste”的插件。

使用它时,您可以在init部分定义两个函数

/**
 * This option enables you to modify the pasted content BEFORE it gets
 * inserted into the editor.
 */
paste_preprocess : function(plugin, args)
{
     //Replace empty styles
    args.content = args.content.replace(/<style><\/style>/gi, "");
}

/**
 * This option enables you to modify the pasted content before it gets inserted
 * into the editor ,but after it's been parsed into a DOM structure.
 *
 * @param plugin
 * @param args
 */
paste_postprocess : function(plugin, args) {
    var paste_content= args.node.innerHTML;
    console.log('Node:');
    console.log(args.node);

}
相关问题