kevas
kevas

Reputation: 573

CKeditor own plugin with dialog

I have written own plugin which generates a simple link. The strange thing is that I can not editing "href" attribute. Other attributes can be edited.

This element does not work:

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

When I create a link, href attribute is written. When I editing a link "href" attribute is not changed. Strange!

When I change the code above and rewrite name of attribute for example to "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'));
    }
}

Creation and editing attribute works perfectly.

You do not know what's the problem?

Thank you.

Upvotes: 4

Views: 408

Answers (1)

oleq
oleq

Reputation: 15895

For various internal reasons, CKEditor uses data-cke-saved-href attribute to duplicate href during runtime. So what in the output would look like

<p>I&#39;m a <a href="http://foo.com">plain&nbsp;link</a>.</p>

<p>I&#39;m a <a href="mailto:[email protected]?subject=Subject&amp;body=Body">mailto link</a>.</p>

is actually something different in editor 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:[email protected]?subject=Subject&amp;body=Body" href="mailto:[email protected]?subject=Subject&amp;body=Body">mailto link</a>.</p>

Update the data- attribute each time you change href and things should go right.

Upvotes: 2

Related Questions