Make a configuration option to choose image styling applied by default
(Edited by @scofalik)
As far as I tested, there is no option to easily set which image style should be used as default. We have isDefault configuration option for styles but it does not really work as I expected it to work
I've tried this configuration and after the image was uploaded, side-style icon was highlighted but there was no class applied and I also couldn't change it to full-style.
styles: [
{
name: 'full',
className: 'image-style-full'
},
{
name: 'side',
isDefault: true,
className: 'image-style-side'
}
]
I have uploaded image successfully into editor using ImageUploadAdapter,
but all my images are center aligned and fully occupied,
I want all images to be left aligned by default.
Is there any special configuration, can you help me with this..
function imageUploadPlugin(editor) {
editor.plugins.get("FileRepository").createUploadAdapter = loader => {
return new ImageUploadAdapter(loader);
};
}
function loadEditor(editor){
if (editor) {
if (!toolbars) toolbars = getDefaultToolbarEditor();
const promise = ClassicEditor.create(editor, {
extraPlugins: [InsertDropDown, Underline, FontSize, imageUploadPlugin],
fontSize: {
options: [9, 10, 11, 12, 14, 19, 21]
},
image: {
toolbar: [
"imageStyle:alignLeft",
"imageStyle:full",
"imageStyle:alignRight"
],
styles: ["alignLeft", "full", "alignRight"]
},
toolbar: toolbars
});
promise.then(editor => {})
}
}
@Reinmar @AnnaTomanek @vokiel @jodator
Hi, I wanted to point you to https://ckeditor.com/docs/ckeditor5/latest/features/image.html#image-styles but, unfortunately, when I tried it I realized this works differently than I (and you) expected.
You could try to style (using CSS) images to be aligned left or right, and then set this styling as default with isDefault (you don't specify className for that style). Then, for the full image style you would have to specify a class, and in CSS that class would have to clear any floatings you have.
This shouldn't work like that, though, it might be nice to simply have a config option defaultStyle. I'll change the title of this issue.
@scofalik but looks like the class that added is reflected only within the editor, when I copy this content and paste in a different editor, All the styles to figure tag is not reflected in the new editor.
The styles applied is not added as inline styles to the dom, it's reflected as style from external style sheet, The styles of figure is not reflected when printed the html anywhere outside the editor, this is inconsitent.. Seems like a special bug only for figure..
The above solution would have the same problem..
@scofalik
Btw, can you explain how to you to use isDefault
I tried something like this, but this didn't work,
editor.commands._commands.get("imageStyle")._defaultStyle = "side";
editor.commands._commands.get("imageStyle")._defaultStyle = "alignLeft";
I'd use CSS for that. You can style images without any class to be left aligned and change the default button icon to a left aligned image, while e.g. style "centered" would apply a class image-style-centered and use the current default icon. You can read more about image style format in https://ckeditor.com/docs/ckeditor5/latest/api/module_image_image-ImageConfig.html#member-styles.
Since this seems totally doable and should work quite fine, I don't think we'll work on the ability to define the default style in any other way. One can imagine that to images which are unstyled (e.g. newly created ones) we'd automatically assign some style, but this leads to some tricky issues with what we should do with images which don't have any style. Were they styled to not have any style or were they left unstyled yet?
There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.
We've closed your issue due to inactivity over the last year. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).