From acdc1f292d3d7e52059dd3ce0832348d23c00c46 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 3 May 2023 20:34:53 +0200 Subject: [PATCH] Add support for font styles See WoltLab/editor#34 --- com.woltlab.wcf/templates/wysiwyg.tpl | 3 ++ .../Core/Component/Ckeditor/Configuration.ts | 38 +++++++++++++++++++ .../install/files/acp/templates/wysiwyg.tpl | 3 ++ .../Core/Component/Ckeditor/Configuration.js | 35 +++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/com.woltlab.wcf/templates/wysiwyg.tpl b/com.woltlab.wcf/templates/wysiwyg.tpl index df4ebee570..3ba7abadb7 100644 --- a/com.woltlab.wcf/templates/wysiwyg.tpl +++ b/com.woltlab.wcf/templates/wysiwyg.tpl @@ -31,6 +31,9 @@ autosave: element.dataset.autosave || "", code: true, codeBlock: true, + fontColor: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('color')}true{else}false{/if}, + fontFamily: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('font')}true{else}false{/if}, + fontSize: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('size')}true{else}false{/if}, heading: true, html: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('html')}true{else}false{/if}, image: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')}true{else}false{/if}, diff --git a/ts/WoltLabSuite/Core/Component/Ckeditor/Configuration.ts b/ts/WoltLabSuite/Core/Component/Ckeditor/Configuration.ts index fb5eebc37a..786b85dfa0 100644 --- a/ts/WoltLabSuite/Core/Component/Ckeditor/Configuration.ts +++ b/ts/WoltLabSuite/Core/Component/Ckeditor/Configuration.ts @@ -64,6 +64,24 @@ class ConfigurationBuilder { this.#removePlugins.push("Superscript"); } + if (this.#features.fontColor) { + items.push("fontColor"); + } else { + this.#removePlugins.push("FontColor"); + } + + if (this.#features.fontFamily) { + items.push("fontFamily"); + } else { + this.#removePlugins.push("FontFamily"); + } + + if (this.#features.fontSize) { + items.push("fontSize"); + } else { + this.#removePlugins.push("FontSize"); + } + if (this.#features.code) { items.push("code"); } else { @@ -257,6 +275,23 @@ class ConfigurationBuilder { }, language, removePlugins: this.#removePlugins, + fontFamily: { + options: [ + "default", + "Arial, Helvetica, sans-serif", + "Comic Sans MS, Marker Felt, cursive", + "Consolas, Courier New, Courier, monospace", + "Georgia, serif", + "Lucida Sans Unicode, Lucida Grande, sans-serif", + "Tahoma, Geneva, sans-serif", + "Times New Roman, Times, serif", + 'Trebuchet MS", Helvetica, sans-serif', + "Verdana, Geneva, sans-serif", + ], + }, + fontSize: { + options: [8, 10, 12, "default", 18, 24, 36], + }, toolbar: this.#getToolbar(), woltlabToolbarGroup: this.#toolbarGroups, } as any; @@ -269,6 +304,9 @@ export type Features = { autosave: string; code: boolean; codeBlock: boolean; + fontColor: boolean; + fontFamily: boolean; + fontSize: boolean; heading: boolean; html: boolean; image: boolean; diff --git a/wcfsetup/install/files/acp/templates/wysiwyg.tpl b/wcfsetup/install/files/acp/templates/wysiwyg.tpl index df4ebee570..3ba7abadb7 100644 --- a/wcfsetup/install/files/acp/templates/wysiwyg.tpl +++ b/wcfsetup/install/files/acp/templates/wysiwyg.tpl @@ -31,6 +31,9 @@ autosave: element.dataset.autosave || "", code: true, codeBlock: true, + fontColor: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('color')}true{else}false{/if}, + fontFamily: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('font')}true{else}false{/if}, + fontSize: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('size')}true{else}false{/if}, heading: true, html: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('html')}true{else}false{/if}, image: {if $__wcf->getBBCodeHandler()->isAvailableBBCode('img')}true{else}false{/if}, diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Configuration.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Configuration.js index bbf535d360..2b11a0ee77 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Configuration.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Component/Ckeditor/Configuration.js @@ -56,6 +56,24 @@ define(["require", "exports", "../../Language"], function (require, exports, Lan else { this.#removePlugins.push("Superscript"); } + if (this.#features.fontColor) { + items.push("fontColor"); + } + else { + this.#removePlugins.push("FontColor"); + } + if (this.#features.fontFamily) { + items.push("fontFamily"); + } + else { + this.#removePlugins.push("FontFamily"); + } + if (this.#features.fontSize) { + items.push("fontSize"); + } + else { + this.#removePlugins.push("FontSize"); + } if (this.#features.code) { items.push("code"); } @@ -223,6 +241,23 @@ define(["require", "exports", "../../Language"], function (require, exports, Lan }, language, removePlugins: this.#removePlugins, + fontFamily: { + options: [ + "default", + "Arial, Helvetica, sans-serif", + "Comic Sans MS, Marker Felt, cursive", + "Consolas, Courier New, Courier, monospace", + "Georgia, serif", + "Lucida Sans Unicode, Lucida Grande, sans-serif", + "Tahoma, Geneva, sans-serif", + "Times New Roman, Times, serif", + 'Trebuchet MS", Helvetica, sans-serif', + "Verdana, Geneva, sans-serif", + ], + }, + fontSize: { + options: [8, 10, 12, "default", 18, 24, 36], + }, toolbar: this.#getToolbar(), woltlabToolbarGroup: this.#toolbarGroups, }; -- 2.20.1