.appendchild Executing Twice In Ckeditor
I'm using the simpleuploads plugin for CKeditor. Everything's working perfect except for one itsy bitsy problem. I'm trying wrap an uploaded image object in a div like so
Solution 1:
The code is fine, but that file is being included twice so the listener is executed twice. The problem can be avoided by stopping the finishedUpload event after is being executed the first time:
CKEDITOR.on('instanceReady', function(e) {
e.editor.on( 'simpleuploads.finishedUpload' , function(ev)
{
var element = ev.data.element;
if (element.getName() == 'img')
{
var img = element.$,
doc = img.ownerDocument,
div = doc.createElement('div');
img.setAttribute('class', 'addedImg');
img.removeAttribute('width');
img.removeAttribute('height');
div.setAttribute('class', 'image-container');
img.parentNode.replaceChild(div, img);
div.appendChild(img);
ev.stop(); // Stop the event in case the listener is inserted twice
}
});
});
Post a Comment for ".appendchild Executing Twice In Ckeditor"