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 {
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 <textarea>.");
* @var array<array>
*/
public static $allowedClassNames = [
- 'figure' => ['image', 'image-style-side'],
+ 'figure' => ['image', 'image-style-side', 'image-style-side-left'],
'h2' => ['text-center', 'text-justify', 'text-right'],
'h3' => ['text-center', 'text-justify', 'text-right'],
'h4' => ['text-center', 'text-justify', 'text-right'],
min-width: 50px;
text-align: center;
+ &.image-style-side-left {
+ float: left;
+ margin: 0 20px 20px 0;
+ }
+
&.image-style-side {
float: right;
margin: 0 0 20px 20px;