From 503544061aaae8ff9977fbd6e9148d3eb5558b4f Mon Sep 17 00:00:00 2001
From: pabois <pierreandre.boissinot@noesya.coop>
Date: Thu, 24 Feb 2022 14:13:10 +0100
Subject: [PATCH] close #215

---
 .../javascripts/admin/plugins/summernote.js   | 91 +++++++++++--------
 .../website/index_pages/edit.html.erb         |  7 +-
 2 files changed, 58 insertions(+), 40 deletions(-)

diff --git a/app/assets/javascripts/admin/plugins/summernote.js b/app/assets/javascripts/admin/plugins/summernote.js
index 51a326329..038b6160e 100644
--- a/app/assets/javascripts/admin/plugins/summernote.js
+++ b/app/assets/javascripts/admin/plugins/summernote.js
@@ -2,50 +2,63 @@
 $(function () {
     'use strict';
 
+    var configs = [];
+    configs['mini'] = {
+        toolbar: [
+            ['font', ['bold', 'italic']],
+            ['insert', ['link']],
+            ['view', ['codeview']]
+        ]
+    };
+
+    configs['default'] = {
+        popover: {
+            image: [
+                ['remove', ['removeMedia']]
+            ]
+        },
+        toolbar: [
+            ['style', ['style']],
+            ['font', ['bold', 'italic']],
+            ['para', ['ul', 'ol']],
+            ['table', ['table']],
+            ['insert', ['link', 'picture', 'video']],
+            ['view', ['codeview']]
+        ],
+        styleTags: [
+            'p',
+            'blockquote',
+            'pre',
+            'h2',
+            'h3',
+            'h4'
+        ],
+        followingToolbar: true,
+        callbacks: {
+            onImageUpload: function (files) {
+                var attachmentUpload = new SummernoteAttachmentUpload(this, files[0]);
+                attachmentUpload.start();
+            },
+            onMediaDelete: function (_, $editable) {
+                $.summernote.rails.cleanEmptyAttachments($editable);
+            },
+            onKeyup: function (e) {
+                var $editable = $(e.currentTarget);
+                if (e.keyCode === 8) {
+                    $.summernote.rails.cleanEmptyAttachments($editable);
+                }
+            }
+        }
+    };
+
     $.extend($.summernote.lang['en-US'].image, {
         dragImageHere: 'Drag file here',
         dropImage: 'Drop file'
     });
 
     $('[data-provider="summernote"]').each(function () {
-        $(this).summernote({
-            popover: {
-                image: [
-                    ['remove', ['removeMedia']]
-                ]
-            },
-            toolbar: [
-                ['style', ['style']],
-                ['font', ['bold', 'italic']],
-                ['para', ['ul', 'ol']],
-                ['table', ['table']],
-                ['insert', ['link', 'picture', 'video']],
-                ['view', ['codeview']]
-            ],
-            styleTags: [
-                'p',
-                'blockquote',
-                'pre',
-                'h2',
-                'h3',
-                'h4'
-            ],
-            followingToolbar: true,
-            callbacks: {
-                onImageUpload: function (files) {
-                    var attachmentUpload = new SummernoteAttachmentUpload(this, files[0]);
-                    attachmentUpload.start();
-                },
-                onMediaDelete: function (_, $editable) {
-                    $.summernote.rails.cleanEmptyAttachments($editable);
-                },
-                onKeyup: function (e) {
-                    var $editable = $(e.currentTarget);
-                    if (e.keyCode === 8) {
-                        $.summernote.rails.cleanEmptyAttachments($editable);
-                    }
-                }
-            }
-        });
+        var config = $(this).attr('data-summernote-config');
+        config = config || 'default';
+        $(this).summernote(configs[config]);
     });
 });
diff --git a/app/views/admin/communication/website/index_pages/edit.html.erb b/app/views/admin/communication/website/index_pages/edit.html.erb
index 61394a3f3..4eaf6be10 100644
--- a/app/views/admin/communication/website/index_pages/edit.html.erb
+++ b/app/views/admin/communication/website/index_pages/edit.html.erb
@@ -22,7 +22,12 @@
                         input_html: { name: 'communication_website_index_page[breadcrumb_title]' },
                         hint: t('simple_form.hints.communication_website_index_page.breadcrumb_title')  %>
             <%= f.input :description, input_html: { name: 'communication_website_index_page[description]' } %>
-            <%= f.input :header_text, as: :summernote, input_html: { name: 'communication_website_index_page[header_text]' } %>
+            <%= f.input :header_text,
+                        as: :summernote,
+                        input_html: {
+                          name: 'communication_website_index_page[header_text]',
+                          data: { 'summernote-config' => 'mini' }
+                        } %>
             <%= f.input :text, as: :summernote, input_html: { name: 'communication_website_index_page[text]' } %>
           </div>
         </div>
-- 
GitLab