Hi,
I have a command that add a specific piece of HTML at the selected area.
CKEDITOR.instances.editable.addCommand('button_cmd', {
exec: function(editor) {
editor.insertHtml('<div class="btn">mybuttoncode</div>');
}
});
I would like to cancel the actio if the selection is already in a element with a 'btn' class.
I made this functions :
function isDescendant(parent, child) {
var node = child.parentNode;
while (node != null) {
if (node == parent) {
return true;
}
node = node.parentNode;
}
return false;
}
function isInAButton(node) {
var butts = document.getElementsByClassName('btn');
for(var i=0,j=butts.length; i<j; i++) {
var butt = butts[i];
if (isDescendant(butt,node)) {
return true;
}
}
return false;
}
But document.getElementsByClassName('btn') is always returning 0 elements, even if I already inserted btn's.
Why 'document' doesn't show me the real content of the editor ?
Thanks
