From 001ab076fbd60aba4aa52e2edc8acd8539475270 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Fri, 5 Aug 2022 10:00:20 +0200
Subject: [PATCH] Fix #503

---
 app/assets/javascripts/admin.js               |  1 -
 .../javascripts/admin/plugins/summernote.js   | 43 +++++++++++++++++--
 .../stylesheets/commons/_summernote.sass      |  3 +-
 3 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js
index d8615d56d..20f2a4a00 100644
--- a/app/assets/javascripts/admin.js
+++ b/app/assets/javascripts/admin.js
@@ -10,7 +10,6 @@
 //= require gdpr/cookie_consent
 //= require sortablejs/Sortable
 //= require summernote/summernote-bs5
-//= require summernote-rails
 //= require slug/slug
 //= require cocoon
 //= require_self
diff --git a/app/assets/javascripts/admin/plugins/summernote.js b/app/assets/javascripts/admin/plugins/summernote.js
index 58a7a777b..38f2cf166 100644
--- a/app/assets/javascripts/admin/plugins/summernote.js
+++ b/app/assets/javascripts/admin/plugins/summernote.js
@@ -3,6 +3,7 @@ $(function () {
     'use strict';
 
     var configs = [];
+
     configs['mini'] = {
         toolbar: [
             ['font', ['bold', 'italic']],
@@ -26,7 +27,8 @@ $(function () {
         disableDragAndDrop: true
     };
 
-    configs['default'] = {
+
+    configs['full'] = {
         popover: {
             image: [
                 ['remove', ['removeMedia']]
@@ -37,6 +39,8 @@ $(function () {
             ['font', ['bold', 'italic']],
             ['position', ['superscript', 'subscript']],
             ['para', ['ul', 'ol']],
+            ['table', ['table']],
+            ['insert', ['link', 'picture', 'video']],
             ['view', ['codeview']]
         ],
         styleTags: [
@@ -66,16 +70,49 @@ $(function () {
         }
     };
 
+
+    configs['default'] = {
+        popover: {
+            image: [
+                ['remove', ['removeMedia']]
+            ]
+        },
+        toolbar: [
+            ['style', ['style']],
+            ['font', ['bold', 'italic']],
+            ['position', ['superscript', 'subscript']],
+            ['para', ['ul', 'ol']],
+            ['view', ['codeview']]
+        ],
+        styleTags: [
+            'p',
+            'blockquote',
+            'pre',
+            'h2',
+            'h3',
+            'h4'
+        ],
+        followingToolbar: true,
+        disableDragAndDrop: true
+    };
+
     $.extend($.summernote.lang['en-US'].image, {
         dragImageHere: 'Drag file here',
         dropImage: 'Drop file'
     });
 
     $('[data-provider="summernote"]').each(function () {
-        var config = $(this).attr('data-summernote-config');
+        var config = $(this).attr('data-summernote-config'),
+            options = {};
         config = config || 'default';
-        $(this).summernote(configs[config]);
+        options = configs[config];
+        $(this).summernote(options);
     });
 
+    // https://github.com/summernote/summernote/issues/4170
+    $("button[data-toggle='dropdown']").each(function (index) { 
+        $(this).removeAttr("data-toggle").attr("data-bs-toggle", "dropdown"); 
+    }); 
+
     window.SUMMERNOTE_CONFIGS = configs;
 });
diff --git a/app/assets/stylesheets/commons/_summernote.sass b/app/assets/stylesheets/commons/_summernote.sass
index 37a6859b7..4f074176c 100644
--- a/app/assets/stylesheets/commons/_summernote.sass
+++ b/app/assets/stylesheets/commons/_summernote.sass
@@ -4,7 +4,7 @@
         color: black
         font-weight: bold
     .note-btn.dropdown-toggle:after
-        content: none
+        margin-left: 10px
     .note-editable
         img, video
             height: auto
@@ -12,6 +12,7 @@
     button
         background: transparent
         border: none
+        margin-right: 10px
         &.active
             color: #666666 !important
     blockquote
-- 
GitLab