我想为CK Editor 4.3制作一个插件,它可以防止所选文本被任何用户删除。我在span标记中包含了所选文本,并将其contentEditable属性设置为false,如果所选文本位于不可编辑的span标记上,则禁用所有键,它适用于IE 8,但不适用于IE 10.代码如下所示< / p>
CKEDITOR.plugins.add('disableelement',
{
init: function(editor)
{
editor.addCommand('insertDisableelement',
{
exec : function( editor )
{
var mySelection = editor.getSelection();
var selectedText = null;
if (CKEDITOR.env.ie)
{
selectedText = mySelection.getNative().createRange().text + " ";
}
else
{
selectedText = mySelection.getNative();
}
var e = new CKEDITOR.dom.element('span');
e.setStyle('background-color', '#81F7F3');
e.setAttributes({
contentEditable :'false'
});
e.setText(selectedText);
editor.insertElement(e);
editor.insertHtml("");
}
}); // end of addCommand
editor.ui.addButton('Disableelement',
{
label: 'Disable element',
command: 'insertDisableelement',
icon: this.path + 'images/disable1.png'
});
CKEDITOR.on('instanceReady', function(editorEvent)
{
editorEvent.editor.on('key', function(keyEvent)
{
var node = keyEvent.editor.getSelection().getStartElement();
if (node.getAttribute('contentEditable') == 'false')
{
alert("key event=" + keyEvent);
keyEvent.cancel();
}
});
}); // end of instanceReady
} // end of init
}); // end of plugins.add
请帮助我实现这一目标。
答案 0 :(得分:0)
为什么不将它放在小部件中而不是将其作为可编辑字段?