1

Maybe you guys can help me. I am trying to create a custom plugin for TinyMce that basically wraps my selection like so:

<div class="myClass" > content </div>

Sort of like how the bold button works. I don't know a lot of javascript and the current plugins are really confusiong so im wondering if anyone can tell me how to do it. I have already created my custom plugin and made it show up on TinyMce, so that part is done, I just need the method.

Thanks!

4

2 回答 2

1

包装选择不是一个大问题 - 如果您的 html 根元素是<p>. 否则它将无法正常工作。

这是必要的代码:

var ed = tinymce.get('my_editor_id');
var content = ed.selection.getContent();
tinymce.execCommand('insertHTML', false, '<div class="myClass">'+content+'</div>');

请注意,仅选择段落的一部分时可能会遇到问题。

于 2012-08-06T08:15:15.630 回答
1

这是我的做法:

        this.editor = ed;

        ed.addCommand('mceblizzardquote', function () {

            var se = ed.selection.getContent();

            if (se.trim() == "") {
                alert("Nothing Selected.");
                return;
            }

            var s1 = '<div class="myClass" >';
            s1 += se + '</div>';

            ed.selection.setContent(s1);
        });
于 2012-08-06T17:57:24.703 回答