From: Alexander Ebert Date: Wed, 10 May 2023 15:11:30 +0000 (+0200) Subject: Add support for images floating to the left X-Git-Tag: 6.0.0_Alpha_1~114 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f1fa95dbd249df94baad999f077e48f318437b09;p=GitHub%2FWoltLab%2FWCF.git Add support for images floating to the left See WoltLab/editor#51 --- diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts index 7b576552a4..61919b4522 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Normalizer.ts @@ -126,22 +126,28 @@ function reduceSpacerParagraphs(paragraphs: HTMLParagraphElement[]): void { function convertFloatingImages(div: HTMLElement): void { div.querySelectorAll("img").forEach((img) => { if (img.classList.contains("messageFloatObjectRight")) { - const paragraph = img.closest("p"); - if (paragraph === null) { - return; - } + imageToFigure(img, "image-style-side"); + } else if (img.classList.contains("messageFloatObjectLeft")) { + imageToFigure(img, "image-style-side-left"); + } + }); +} - const figure = document.createElement("figure"); - figure.classList.add("image", "image-style-side"); - figure.append(img); +function imageToFigure(img: HTMLImageElement, alignmentClass: string): void { + const paragraph = img.closest("p"); + if (paragraph === null) { + return; + } - paragraph.insertAdjacentElement("beforebegin", figure); + const figure = document.createElement("figure"); + figure.classList.add("image", alignmentClass); + figure.append(img); - if (paragraph.innerHTML === "") { - paragraph.remove(); - } - } - }); + paragraph.insertAdjacentElement("beforebegin", figure); + + if (paragraph.innerHTML === "") { + paragraph.remove(); + } } export function normalizeLegacyMessage(element: HTMLElement): void { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Normalizer.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Normalizer.js index 1278f76178..c6ba360086 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Normalizer.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Normalizer.js @@ -110,20 +110,26 @@ define(["require", "exports", "tslib", "../../Dom/Util"], function (require, exp function convertFloatingImages(div) { div.querySelectorAll("img").forEach((img) => { if (img.classList.contains("messageFloatObjectRight")) { - const paragraph = img.closest("p"); - if (paragraph === null) { - return; - } - const figure = document.createElement("figure"); - figure.classList.add("image", "image-style-side"); - figure.append(img); - paragraph.insertAdjacentElement("beforebegin", figure); - if (paragraph.innerHTML === "") { - paragraph.remove(); - } + imageToFigure(img, "image-style-side"); + } + else if (img.classList.contains("messageFloatObjectLeft")) { + imageToFigure(img, "image-style-side-left"); } }); } + function imageToFigure(img, alignmentClass) { + const paragraph = img.closest("p"); + if (paragraph === null) { + return; + } + const figure = document.createElement("figure"); + figure.classList.add("image", alignmentClass); + figure.append(img); + paragraph.insertAdjacentElement("beforebegin", figure); + if (paragraph.innerHTML === "") { + paragraph.remove(); + } + } function normalizeLegacyMessage(element) { if (!(element instanceof HTMLTextAreaElement)) { throw new TypeError("Expected the element to be a