ckeditor5
ckeditor5 copied to clipboard
Getting parent model
Hi,
I want to create a plugin - placeholder for images with certain attributes. Here is what I have so far:
export default class InsertImagePathCommand extends Command {
execute(pathParam, fullPath, dimentions) {
this.editor.model.change(writer => {
const img = new Image();
img.src = fullPath;
img.onload = () => {
let dimentions= '';
if (img.width === img.height) {
dimentions= 'square';
} else if (img.height > img.width) {
dimentions = 'vertical';
}
this.editor.model.insertContent(writer.createElement('imagePathPreview', {path: pathParam, dimentions}));
}
});
}
refresh() {
const model = this.editor.model;
const selection = model.document.selection;
const allowedIn = model.schema.findAllowedParent(selection.getFirstPosition(), 'imagePathPreview');
this.isEnabled = allowedIn !== null;
}
}
It is working, but now I want to set proper dimentions param dependent on a parent element. I'm guessing that I have to read it in model. But how to get parent element and its attributes? It doesn't work as HTML node co can You guide me?
Thanks!