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-9296: Custom CSS classes not working for "embedimage" #197

Open
wants to merge 1 commit into
base: 4.6
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -32,20 +32,24 @@ class IbexaCustomAttributesCommand extends Command {
cleanClasses(modelElement, classes) {
Object.keys(classes).forEach((elementName) => {
const configName = findConfigName(modelElement.name);
const selectedCustomClasses = modelElement.getAttribute('custom-classes') ?? '';
const selectedCustomClasses = modelElement.getAttribute('custom-classes')?.split(' ') ?? [];
const elementCustomClassesConfig = classes[configName];
const filteredSelectedCustomClasses = selectedCustomClasses.filter(
(className) => !elementCustomClassesConfig || className !== elementCustomClassesConfig.predefinedClass,
);

const hasOwnCustomClasses =
elementCustomClassesConfig &&
selectedCustomClasses
.split(' ')
.every((selectedCustomClass) => elementCustomClassesConfig.choices.includes(selectedCustomClass));

if (elementName === configName || hasOwnCustomClasses) {
return;
}
filteredSelectedCustomClasses.every((selectedCustomClass) =>
elementCustomClassesConfig.choices.includes(selectedCustomClass),
);

this.editor.model.change((writer) => {
writer.removeAttribute('custom-classes', modelElement);
if (elementName !== configName && !hasOwnCustomClasses) {
writer.removeAttribute('custom-classes', modelElement);
} else if (selectedCustomClasses.length !== filteredSelectedCustomClasses.length) {
writer.setAttribute('custom-classes', filteredSelectedCustomClasses.join(' '), modelElement);
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ const getCustomClassesElementConfig = (elementName) => {

return config[configName];
};
const addPredefinedClassToConfig = (elementName, className) => {
const configName = findConfigName(elementName);
const config = window.ibexa.richText.alloyEditor.classes[configName];

if (config) {
config.predefinedClass = className;
}
};

export {
getCustomAttributesConfig,
getCustomClassesConfig,
getCustomAttributesElementConfig,
getCustomClassesElementConfig,
findConfigName,
addPredefinedClassToConfig,
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Widget from '@ckeditor/ckeditor5-widget/src/widget';
import IbexaEmbedImageCommand from './embed-image-command';

import { findContent } from '../../services/content-service';
import { addPredefinedClassToConfig } from '../../custom-attributes/helpers/config-helper';

const CONTAINER_CLASS = 'ibexa-embed-type-image';

class IbexaEmbedImageEditing extends Plugin {
static get requires() {
Expand All @@ -17,6 +20,8 @@ class IbexaEmbedImageEditing extends Plugin {
this.loadImagePreview = this.loadImagePreview.bind(this);
this.loadImageVariation = this.loadImageVariation.bind(this);
this.getSetting = this.getSetting.bind(this);

addPredefinedClassToConfig('embedImage', CONTAINER_CLASS);
}

loadImagePreview(modelElement) {
Expand Down Expand Up @@ -89,7 +94,7 @@ class IbexaEmbedImageEditing extends Plugin {
const container = downcastWriter.createContainerElement('div', {
'data-ezelement': 'ezembed',
'data-ezview': 'embed',
class: 'ibexa-embed-type-image',
class: CONTAINER_CLASS,
});

this.loadImagePreview(modelElement);
Expand Down Expand Up @@ -136,7 +141,7 @@ class IbexaEmbedImageEditing extends Plugin {
'data-href': `ezcontent://${modelElement.getAttribute('contentId')}`,
'data-ezelement': 'ezembed',
'data-ezview': 'embed',
class: 'ibexa-embed-type-image',
class: CONTAINER_CLASS,
});
const config = downcastWriter.createUIElement('span', { 'data-ezelement': 'ezconfig' }, function (domDocument) {
const domElement = this.toDomElement(domDocument);
Expand Down Expand Up @@ -177,7 +182,7 @@ class IbexaEmbedImageEditing extends Plugin {
attributes: {
'data-ezelement': 'ezembed',
},
classes: 'ibexa-embed-type-image',
classes: CONTAINER_CLASS,
},
model: (viewElement, { writer: upcastWriter }) => {
const href = viewElement.getAttribute('data-href');
Expand Down
Loading