CKEditor 4获取父元素的维度



我构建了一个小型的CKEditor插件,其中一个按钮插入一个span标记。span必须与p的高度相同,所以我需要css行高度值或p标记的高度。当前插件代码:

CKEDITOR.plugins.add('border',{
icons: 'border',
init: function(editor){
editor.addCommand('addBox',{
exec: function(editor) {
var box = editor.document.createElement('span');
box.setAttribute('style', 'border:1px solid #000;display:inline-block;width:40px;height:40px;vertical-align: text-top;');
box.setAttribute('class', 'borderbox');
editor.insertElement(box);
}
});
editor.ui.addButton('empty box',{
label: 'insert box',
command: 'addBox',
toolbar: 'links'
});
}
});

如何访问父级p?

找到的解决方案:editor.elementPath((.elements[0]返回第一个父元素。

最新更新