将 OnMouseover 事件添加到 TinyMCE 编辑器实例

发布于 2024-10-04 12:02:04 字数 634 浏览 0 评论 0原文

我想将 onMouseOver 和 onMouseOut 事件添加到 TinyMCE 中的编辑器实例(通过插件),但 TinyMCE 的 API 似乎不支持它们。具体来说,我希望当鼠标悬停在元素上以切换“只读”模式(以及可能的其他模式)时出现一个控件。我是否必须自己向 TinyMCE 添加代码才能执行此操作,或者是否通过某些非显而易见的途径支持它?如果我确实必须添加代码,是否有一些禁止支持这些事件的禁令构成了他们不将其包含在 API 中的推理基础?

为了澄清那些与下面的响应者有同样困惑的人的利益,我特别希望将一个事件附加到由 TinyMCE 库创建的 TinyMCE.Editor 实例(例如,传递给使用的回调的类)在 TinyMCE.init 的设置参数中)。我希望执行以下操作

tinyMCE.init({
  .
  .
  .
  setup : function(ed) { 
    TinyMCEReadOnlySetup(ed,true); 
    ed.onMouseOver.add(ShowButton(ed));
    ed.onMouseOut.add(HideButton(ed));
  },
  .
  .
  .
});

,但 ed (TinyMCE.Editor 的实例)不支持类似事件方式的 MouseOver.add 。

I would like to add onMouseOver and onMouseOut events to an editor instance within TinyMCE (through a plugin), but they seem not to be supported by TinyMCE's API. Specifically, I would like a control to appear when the element is moused over to toggle "read-only" mode (and possibly other things). Would I have to add code myself to TinyMCE to do this, or is it supported through some non-obvious route? If I do have to add code, is there some prohibition against supporting these events that forms the basis of their reasoning for not including it in the API?

To clarify for the benefit of those with the same confusion as responders below, I am specifically wishing to attach an event to the TinyMCE.Editor instance that is created by the TinyMCE library (the class that is, for instance, passed to the callback used in the setup parameter of TinyMCE.init). I wish to do the following

tinyMCE.init({
  .
  .
  .
  setup : function(ed) { 
    TinyMCEReadOnlySetup(ed,true); 
    ed.onMouseOver.add(ShowButton(ed));
    ed.onMouseOut.add(HideButton(ed));
  },
  .
  .
  .
});

, but ed (an instance of TinyMCE.Editor) does not support MouseOver.add in the fashion of similar events.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不甘平庸 2024-10-11 12:02:04

要在只读和编辑模式之间切换,您可以

ed.getDoc().designMode = "Off";

在自己的插件中使用。或者,您可以保存编辑器内容并在 onChange 被触发时恢复它。

编辑:

要设置您可以使用的鼠标悬停事件侦听器

$('#' + ed.id +'_parent').bind('mouseover',function (evt){
   setTimeout("console.log('mouseover')",50);return false;
});

您可以在插件的 onInit 部分中执行此操作。

To toggle between read-only and edit mode you may use

ed.getDoc().designMode = "Off";

in your own plugin. Alternatively, you can save the editor content and restore it if onChange is fired.

EDIT:

To set a mouseover event listener you may use

$('#' + ed.id +'_parent').bind('mouseover',function (evt){
   setTimeout("console.log('mouseover')",50);return false;
});

You could do this in the onInit part of your plugin.

风筝有风,海豚有海 2024-10-11 12:02:04

好吧,我可以通过创建一个插件来使其工作,然后在 init 属性中添加以下非常 hack-y 的代码:

ed.onInit.add(function(ed){
                   .
                   .
                   .

    document.getElementById(ed.id + '_parent').setAttribute('onmouseover',
      "tinyMCE.editor_ShowButton('" + ed.id + "');");
    document.getElementById(ed.id + '_parent').setAttribute('onmouseout',
      "tinyMCE.editor_HideButton('" + ed.id + "');");
    //ed.getBody().appendChild(newdiv);
 });

这不是最佳解决方案,但它可以完成工作。

Alright, I was able to get this to work by creating a plugin, then adding the following very hack-y code in the init attribute:

ed.onInit.add(function(ed){
                   .
                   .
                   .

    document.getElementById(ed.id + '_parent').setAttribute('onmouseover',
      "tinyMCE.editor_ShowButton('" + ed.id + "');");
    document.getElementById(ed.id + '_parent').setAttribute('onmouseout',
      "tinyMCE.editor_HideButton('" + ed.id + "');");
    //ed.getBody().appendChild(newdiv);
 });

It's not an optimal solution, but it gets the job done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文