button - Froala 添加自定义预编码按钮

标签 button tags customization wysiwyg froala

我正在尝试使用 Froala 创建一个代码按钮编辑器基本上可以通过按 CNTRL+K 执行与此处相同的操作。现在我想我有两个选择。

第一个是编辑 froala-editor.js 文件,因为 Froala 已经有一个“代码”按钮,该按钮仅添加 <pre>标签。如果我能以某种方式让它也添加 <code>标签,问题解决。不幸的是我没有让它发挥作用。

第二个选项是创建一个自定义按钮,到目前为止我有这段代码:

$('textarea[name="description"]').editable({
    //Settings here
    customButtons: {
        insertCode: {
            title: 'Insert code',
            icon: {
                type: 'font',
                value: 'fa fa-code'
            },
            callback: function() {
                this.saveSelection();

                if (!this.selectionInEditor()) {
                    this.$element.focus(); // Focus on editor if it's not.
                }

                var html = '<pre><code>' + this.text() + ' </code></pre>';

                this.restoreSelection();
                this.insertHTML(html);
                this.saveUndoStep();
            }
        }
    }
});

它以某种方式工作,但它有缺陷并且会产生奇怪的 html,如下所示:

<p><code></code>
  <pre><code>asdasdasdasd
</code></pre>
</p>

任何帮助完成选项一或选项二的帮助将不胜感激。

最佳答案

如果您升级到 Github 上提供的版本 1.2.3,您的代码应该可以工作 https://github.com/froala/wysiwyg-editor 。无需保存/恢复选择。


稍后编辑: 这是一个 jsFiddle http://jsfiddle.net/9pmmg1jk/ .

customButtons: {
  insertCode: {
    title: 'Insert code',
      icon: {
        type: 'font',
          value: 'fa fa-code'
      },
        callback: function() {
          if (!this.selectionInEditor()) {
            this.$element.focus(); // Focus on editor if it's not.
          }

          var html = '<code>' + (this.text() || '&#8203;') + '<span class="f-marker" data-type="false" data-id="0" data-fr-verified="true"></span><span class="f-marker" data-type="true" data-id="0" data-fr-verified="true"></span></code>';

          this.insertHTML(html);
          this.restoreSelectionByMarkers();
          this.saveUndoStep();
        }
  }
}

关于button - Froala 添加自定义预编码按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26392277/

相关文章:

Android:使用 RelativeLayout 将两个 Toggle Button 一个放在另一个下面的问题

html - WordPress - 将按钮添加到标题区域

IsEnabled = False 时的 WPF 按钮背景

php - 我怎样才能改进这段代码?

Android NFC 扫描时间

C# - 添加、编辑和删除文件标签

android - 如何自定义 Android AlertDialog 中的列表项

javascript - 页面无法重定向并清除 URL 参数

c# - 值不能为空。参数名称 : value, CreateIdentityAsync?

visual-studio - 在 Visual Studio 2008 中以编程方式强制大写?