From 01cf366d2b7e5291ef9635827aea94a936c461dd Mon Sep 17 00:00:00 2001
From: fspreck <f.spreckelsen@indiscale.com>
Date: Tue, 30 Nov 2021 09:38:41 +0100
Subject: [PATCH] DRAFT: Replace textarea by editor

---
 src/core/js/ext_editmode_wysiwyg_text.js | 29 ++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/core/js/ext_editmode_wysiwyg_text.js b/src/core/js/ext_editmode_wysiwyg_text.js
index 2ee27ab6..101c77bd 100644
--- a/src/core/js/ext_editmode_wysiwyg_text.js
+++ b/src/core/js/ext_editmode_wysiwyg_text.js
@@ -23,14 +23,39 @@
 /**
  * Replaces textareas in the edit mode by a wysiwyg editor
  */
-var ext_editmode_wysiwyg_text = function ($, logger) {
+var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor) {
+
+    var _insertEditor = function (fieldId) {
+        ClassicEditor
+            .create(document.querySelector('#' + fieldId), {
+                plugins: ClassicEditor.builtinPlugins,
+            })
+            .then(editor => {
+                console.log('Initialized editor for ' + fieldId);
+            })
+            .catch(error => {
+                console.error(error.stack);
+            });
+    }
+
+    var replaceTextAreas = function () {
+        const fields = $('textarea');
+        for (let field of fields) {
+            // TODO(fspreck): This will be replaced by a whitelist of properties
+            // in the future
+            if (field.id) {
+                _insertEditor(field.id);
+            }
+        }
+    }
 
     var init = function () {};
 
     return {
         init: init,
+        replaceTextAreas: replaceTextAreas,
     };
-}($, log.getLogger("ext_editmode_wysiwyg_text"));
+}($, log.getLogger("ext_editmode_wysiwyg_text"), ClassicEditor);
 
 $(document).ready(() => {
     if ("${BUILD_MODULE_EXT_EDITMODE_WYSIWYG_TEXT}" == "ENABLED") {
-- 
GitLab