CKeditor拥有对话框的插件

时间:2015-02-10 08:56:52

标签: javascript ckeditor

我已经编写了自己的插件,可以生成一个简单的链接。 奇怪的是我无法编辑“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'));
    }
}

创建和编辑属性非常有效。

你不知道是什么问题?

谢谢。

1 个答案:

答案 0 :(得分:3)

由于各种内部原因,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>

每次更改data-时都会更新href属性,事情应该正确。