簡體   English   中英

TinyMCE,Rails 4和execcommand_callback

[英]TinyMCE, Rails 4 and execcommand_callback

我一直在嘗試讓TinyMCE在選擇File Menu :: New Document選項時使用自定義的execcommand_callback處理程序執行操作,但是即使在最基本的級別上也無法使其正常工作。 該項目位於Rails 4上,我使用的tinyMCE-rails gem來自:

https://github.com/spohlenz/tinymce-rails

並遵循以下示例:

http://www.tinymce.com/wiki.php/Configuration3x:execcommand_callback

我將以下內容放在tinymce.yml中

execcommand_callback: "myCustomExecCommandHandler"

產生的html:

<script>
//<![CDATA[

function myCustomExecCommandHandler(editor_id, elm, command, user_interface, value) {
    alert('hello');
}

//]]>
</script>

some html  ...

<form accept-charset="UTF-8" action="" id="homepage_form" method="post">
    <textarea class="tinymce" cols="10" id="editor" name="editor" rows="10"></textarea>
    <script>
      //<![CDATA[
      tinyMCE.init({"selector":"textarea.tinymce","document_base_url":"/",
          "theme_advanced_toolbar_location":"top","theme_advanced_toolbar_align":"left",
          "theme_advanced_statusbar_location":"bottom",
          "theme_advanced_buttons3_add":"tablecontrols,fullscreen,image,link",
          "plugins":"table,fullscreen,image,link",
          "execcommand_callback":"myCustomExecCommandHandler"});
      //]]>
     </script>

more form fields ...

</form>

在所有情況下,這都不起作用。 甚至不會發出警告或錯誤。 我究竟做錯了什么?

好的,我想我應該對對此問題感興趣的其他人總結一下,並感謝Nishant使我走上正確的道路。

將TinyMCE 4與tinymce-rails gem( https://github.com/spohlenz/tinymce-rails )結合使用非常簡單,所需的配置更少。 由於我希望能夠嵌入鏈接和圖像,因此我的tinymce.yml文件如下所示:

document_base_url: /
plugins:
 - image
 - link
setup: "myNewDocumentHandler"

我的自定義命令處理程序如下所示:

function myNewDocumentHandler(ed) {
  ed.on('BeforeExecCommand', function(e) {
    if (e.command === 'mceNewDocument') {
      alert('New Document Command Handled');
    }
  });

}

您可以在這里看到它的工作: http : //fiddle.tinymce.com/uRdaab/4

您的回調沒有問題。 它工作正常。

檢查http://fiddle.tinymce.com/pRdaab

當您刪除圖像並鏈接它時 ,插件行中的這里存在一些問題。 檢查我的小提琴,這里是代碼。 我不知道為什么,但是設法弄清楚。 image通常是advimage,但是不確定鏈接插件/功能。

<script type="text/javascript">

function myCustomExecCommandHandler(editor_id, elm, command, user_interface, value) {alert('hello');}

tinyMCE.init({"selector":"textarea",
          "document_base_url":"/",
          "theme_advanced_toolbar_location":"top",
          "theme_advanced_toolbar_align":"left",
          "theme_advanced_statusbar_location":"bottom",
          "theme_advanced_buttons3_add":"tablecontrols,fullscreen",
          "plugins":"table,fullscreen",  

          "execcommand_callback":"myCustomExecCommandHandler"});  
</script>

<form method="post" action="dump.php">
    <textarea>Foo</textarea>
</form>

因此,通常使用經典的TinyMCE init然后對其進行處理是有好處的。 最好先使TinyMCE正常工作,然后檢查添加回叫功能。 一次解決一個問題可以節省大量的故障排除時間。 我也想在我的編程技能中實現它!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM