ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

Getting parent model

Open piernik opened this issue 1 year ago • 0 comments

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!

piernik avatar Feb 16 '24 14:02 piernik