CKEditor内联选择包装

时间:2013-03-22 11:03:31

标签: javascript ckeditor

我正在寻找一种方法来为选择添加带有属性的内联span元素。 这很困难的部分是让它使用通过多个​​块级元素的选择。

我正在寻找StyleCombobox的源代码并找到了这一行。

var style = styles[ value ],
elementPath = editor.elementPath();
editor[ style.checkActive( elementPath ) ? 'removeStyle' : 'applyStyle' ]( style );

这种方式已经适用于多个块级元素。

唯一的一点是,我想将属性应用于围绕不同块级元素的多个选择而不是应用样式元素的跨度。

有谁知道如何做到这一点?

2 个答案:

答案 0 :(得分:1)

我用它作为解决方案。 确实可以设置属性和元素类型。 这在api中没有定义。我在CKEditor 3.0 api(旧版本)

中找到了这个
var style = new CKEDITOR.style({attributes: {name:"changed"}});
editor.applyStyle(style);

答案 1 :(得分:0)

您问题的最新解决方案。

获取所选文字:

editor.getSelection().getSelectedText();

放置标签和属性

editor.applyStyle(new CKEDITOR.style({
        element : 'span', 
        attributes : {'class':'YourClass','data-Otherattr':'otherattrvalue'}, 
        style : {'background-color':'gray'} 
    });
);