CKeditor自己的带有对话框的插件

CKeditor own plugin with dialog

本文关键字:插件 对话框 自己的 CKeditor      更新时间:2023-09-26

我已经编写了自己的插件,它可以生成一个简单的链接。奇怪的是,我无法编辑"href"属性。可以编辑其他属性。

此元素不起作用:

{
    type: 'text',
    id: 'url',
    label: 'URL',
    commit: function(element) {
        element.setAttribute('href', this.getValue());
    },
    setup: function(element) {
        this.setValue(element.getAttribute('href'));
    }
}

创建链接时,会写入href属性。编辑链接时,"href"属性不会更改。奇怪的

当我更改上面的代码并将属性名称重写为"href-s"时,例如:

{
    type: 'text',
    id: 'url',
    label: 'URL',
    commit: function(element) {
        element.setAttribute('href-s', this.getValue());
    },
    setup: function(element) {
        this.setValue(element.getAttribute('href-s'));
    }
}

创建和编辑属性的工作非常完美。

你不知道出了什么问题?

谢谢。

由于各种内部原因,CKEditor在运行时使用data-cke-saved-href属性来复制href。那么输出中的会是什么样子
<p>I&#39;m a <a href="http://foo.com">plain&nbsp;link</a>.</p>
<p>I&#39;m a <a href="mailto:foo@bar.com?subject=Subject&amp;body=Body">mailto link</a>.</p>

实际上在编辑器DOM 中有所不同

<p>I'm a <a data-cke-saved-href="http://foo.com" href="http://foo.com">plain&nbsp;link</a>.</p>
<p>I'm a <a data-cke-saved-href="mailto:foo@bar.com?subject=Subject&amp;body=Body" href="mailto:foo@bar.com?subject=Subject&amp;body=Body">mailto link</a>.</p>

每次更改href时都要更新data-属性,一切都会正常进行。