How to insert custom html tag using YUI Editor

2019-05-31 03:18发布

I've got YUI set up and working. I've created a custom button and it shows up fine. What I would like that button to do is wrap selected text with my own custom 'span' tags, just like clicking the 'bold' button wraps selected text with 'strong' / 'bold' tags.

Does anyone have any examples they could point to to make this work?

1条回答
聊天终结者
2楼-- · 2019-05-31 03:47

Discovered the solution for myself, so I'm posting so others may see as well. :)

First, a BIG thanks to MK_Dev for inspiration from his similar question asked back in April. Here is the all the code that's needed for my problem (above):

this.toolbar.on('mycustombuttonClick', function() {
        var sSelection = this._getSelection();
        var sNewElt = '<span class="testhere">' + sSelection + '</span>';
        this.execCommand('inserthtml', sNewElt);
        return false;
    }, this, true);

Note that this assumes that the button that's inserting the html is on the toolbar.

查看更多
登录 后发表回答