Javascript 编辑后删除CKEditor实例
我正在使用JQuery将CKEditor实例(单击事件)动态添加到页面的某些元素中 问题1:如果元素已被单击,则它们已连接了CKEditor实例,这将在尝试创建新实例时导致错误 问题2:我没有这些元素的id,因此事先不知道CKeditor实例的名称。在这种情况下,它们将遵循渐进式计数器,如“editor1”、“editor2”等 因此,我无法按名称删除实例,删除每个单击事件上的所有实例似乎不是一个正确的解决方案Javascript 编辑后删除CKEditor实例,javascript,jquery,html,ckeditor,Javascript,Jquery,Html,Ckeditor,我正在使用JQuery将CKEditor实例(单击事件)动态添加到页面的某些元素中 问题1:如果元素已被单击,则它们已连接了CKEditor实例,这将在尝试创建新实例时导致错误 问题2:我没有这些元素的id,因此事先不知道CKeditor实例的名称。在这种情况下,它们将遵循渐进式计数器,如“editor1”、“editor2”等 因此,我无法按名称删除实例,删除每个单击事件上的所有实例似乎不是一个正确的解决方案 问题:我想在编辑完元素后立即删除CKEditor实例。如果单击的元素已经存在(不知道
问题:我想在编辑完元素后立即删除CKEditor实例。如果单击的元素已经存在(不知道实例名称),则在(重新)创建它之前删除该元素上的实例的任何其他建议。考虑以下HTML:
<div class="foo">Hello!</div>
<div class="foo">World!</div>
内联方式:
CKEDITOR.disableAutoInline = true;
function attachEditorToElement( element ) {
element.once( 'click', function() {
if ( element.getEditor() )
return;
element.setAttribute( 'contenteditable', true );
CKEDITOR.inline( element, {
plugins: 'floatingspace,toolbar,basicstyles',
on: {
instanceReady: function() {
// Focus the instance immediately.
this.focus();
},
blur: function() {
var el = this.element;
el.removeAttribute( 'contenteditable' );
this.destroy();
attachEditorToElement( el );
}
}
} );
} );
}
var divs = CKEDITOR.document.find( 'div.foo' );
// Create editor instances when div is clicked.
for ( var i = divs.count(); i--; )
attachEditorToElement( divs.getItem( i ) );
谢谢,我必须提到我使用的是内联编辑器,我想方法有点不同,不是吗?@Leonardo更新了答案。谢谢,好的,差不多了,但这不起作用。如果我单击任何
元素,将仅为单击的第一个元素创建内联编辑器。所有其他div(类foo
)都不会在CKEditor inline上创建实例,我正试图弄清楚为什么要查看您的代码
CKEDITOR.disableAutoInline = true;
function attachEditorToElement( element ) {
element.once( 'click', function() {
if ( element.getEditor() )
return;
element.setAttribute( 'contenteditable', true );
CKEDITOR.inline( element, {
plugins: 'floatingspace,toolbar,basicstyles',
on: {
instanceReady: function() {
// Focus the instance immediately.
this.focus();
},
blur: function() {
var el = this.element;
el.removeAttribute( 'contenteditable' );
this.destroy();
attachEditorToElement( el );
}
}
} );
} );
}
var divs = CKEDITOR.document.find( 'div.foo' );
// Create editor instances when div is clicked.
for ( var i = divs.count(); i--; )
attachEditorToElement( divs.getItem( i ) );