Cleditor - 小插件错误

发布于 2025-01-04 05:41:45 字数 1071 浏览 2 评论 0原文

我不是 Javascript 专家,所以我有点困惑为什么这个小按钮插件在 Cleditor 中执行它应该执行的操作,但 jquery 编辑器会弹出错误警告。

这是代码:

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
  }


})(jQuery);

这是一个简单的插件,当您单击按钮时,会将 [VIDEO] 插入文档中。

问题是,由于某种原因,在插入文本后,

在插件按钮下的一个黄色小窗口中会出现“执行 inserthtml 命令时出错”。

我确信由于缺乏 Javascript 经验,我错过了一些小事情。

提前致谢

I am not a Javascript specialist so I am a little confused as to why this little button plugin does what it is supposed to in Cleditor but a error warning is popped up by the jquery editor.

Here is the code:

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
  }


})(jQuery);

It is a simple plugin that inserts [VIDEO] into the document when you click the button.

The problem is that for some reason after it inserts the text this comes up

"Error Executing the inserthtml command" In a little yellow window under the plugin button.

I am sure it is something small that I am missing due to lack of experience with Javascript.

Thanks in advance

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

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

发布评论

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

评论(1

泅渡 2025-01-11 05:41:45

错误就在这里

editor.execCommand(data.command, html);

,它应该是:

editor.execCommand(data.command, html, null, data.button);

编辑:

非常烦人,在函数末尾只需添加:

return false;

这里是 jsfiddle

最终代码

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
       return false;
  }


})(jQuery);

Error is here you have

editor.execCommand(data.command, html);

and it should be:

editor.execCommand(data.command, html, null, data.button);

EDIT:

verry annoying, at the end of your function just add:

return false;

here is jsfiddle for that

and final code

(function($) {


  // Define the hello button
  $.cleditor.buttons.video = {
    name: "video",
    image: "video.gif",
    title: "Insert Video",
    command: "inserthtml",
    buttonClick: videoClick
  };


  // Add the button to the default controls before the bold button
  $.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
    .replace("bold", "video bold");


  // Handle the hello button click event
  function videoClick(e, data) {

        // Get the editor
        var editor = data.editor;

        // Insert some html into the document
        var html = "[VIDEO]";
        editor.execCommand(data.command, html, null, data.button);


        // Hide the popup and set focus back to the editor
       // editor.focus();
       return false;
  }


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