Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7740: Fixed links in embed image #149

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class IbexaEmbedImageEditing extends Plugin {

this.loadImagePreview = this.loadImagePreview.bind(this);
this.loadImageVariation = this.loadImageVariation.bind(this);
this.getSetting = this.getSetting.bind(this);
}

loadImagePreview(modelElement) {
Expand Down Expand Up @@ -57,6 +58,16 @@ class IbexaEmbedImageEditing extends Plugin {
.catch(window.ibexa.helpers.notification.showErrorNotification);
}

getSetting(viewElement, settingName) {
const children = viewElement.getChildren();

for (const child of children) {
if (child.getAttribute('data-ezelement') === settingName) {
return child;
}
}
}

defineSchema() {
const { schema } = this.editor.model;

Expand Down Expand Up @@ -171,8 +182,8 @@ class IbexaEmbedImageEditing extends Plugin {
model: (viewElement, { writer: upcastWriter }) => {
const href = viewElement.getAttribute('data-href');
const contentId = href.replace('ezcontent://', '');
const size = viewElement.getChild(0).getChild(0).getChild(0).data;
const link = viewElement.getChild(1);
const size = this.getSetting(viewElement, 'ezconfig').getChild(0).getChild(0).data;
const link = this.getSetting(viewElement, 'ezlink');
const modelElement = upcastWriter.createElement('embedImage', { contentId, size });

if (link?.is('element', 'a')) {
Expand Down
Loading