From d37ec7555024e9f52377893755676622cda407f1 Mon Sep 17 00:00:00 2001
From: Antonin <zepcome@gmail.com>
Date: Mon, 27 Jun 2016 12:24:12 +0200
Subject: [PATCH] Added configuration option for enabling rich editor by
 default.

---
 adminstuds.php                    | 1 +
 app/inc/config.template.php       | 1 +
 create_poll.php                   | 1 +
 js/app/adminstuds.js              | 4 +++-
 js/app/create_poll.js             | 4 +++-
 tpl/admin/config.tpl              | 1 +
 tpl/part/description_markdown.tpl | 4 ++--
 7 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/adminstuds.php b/adminstuds.php
index 5750828a..ec9d96ee 100644
--- a/adminstuds.php
+++ b/adminstuds.php
@@ -422,5 +422,6 @@ $smarty->assign('hidden', false);
 $smarty->assign('accessGranted', true);
 $smarty->assign('resultPubliclyVisible', true);
 $smarty->assign('editedVoteUniqueId', '');
+$smarty->assign('default_to_marldown_editor', $config['markdown_editor_by_default']);
 
 $smarty->display('studs.tpl');
diff --git a/app/inc/config.template.php b/app/inc/config.template.php
index bcbd21b2..4e38cdc5 100644
--- a/app/inc/config.template.php
+++ b/app/inc/config.template.php
@@ -92,4 +92,5 @@ $config = [
     'default_poll_duration' => 180,         // default values for the new poll duration (number of days).
     /* create_classic_poll.php */
     'user_can_add_img_or_link' => true,     // user can add link or URL when creating his poll.
+    'markdown_editor_by_default' => true    // The markdown editor for the description is enabled by default
 ];
\ No newline at end of file
diff --git a/create_poll.php b/create_poll.php
index 550101fb..7e8570c4 100644
--- a/create_poll.php
+++ b/create_poll.php
@@ -265,6 +265,7 @@ $smarty->assign('title', $title);
 $smarty->assign('useRemoteUser', $useRemoteUser);
 $smarty->assign('errors', $errors);
 $smarty->assign('use_smtp', $config['use_smtp']);
+$smarty->assign('default_to_marldown_editor', $config['markdown_editor_by_default']);
 $smarty->assign('goToStep2', GO_TO_STEP_2);
 
 $smarty->assign('poll_type', $poll_type);
diff --git a/js/app/adminstuds.js b/js/app/adminstuds.js
index 9b4bcd3c..c77d06f1 100644
--- a/js/app/adminstuds.js
+++ b/js/app/adminstuds.js
@@ -53,7 +53,9 @@ $(document).ready(function() {
         $('.js-desc textarea').focus();
         if (firstOpening) {
             firstOpening = false;
-            wrapper.enable();
+            if ($('#rich-editor-button').hasClass('active')) {
+                wrapper.enable();
+            }
         }
         return false;
     });
diff --git a/js/app/create_poll.js b/js/app/create_poll.js
index ffa79951..81b14437 100644
--- a/js/app/create_poll.js
+++ b/js/app/create_poll.js
@@ -91,6 +91,8 @@ $(document).ready(function () {
     }
 
     var wrapper = new MDEWrapper($('#poll_comments')[0], $('#rich-editor-button'), $('#simple-editor-button'));
-    wrapper.enable();
+    if ($('#rich-editor-button').hasClass('active')) {
+        wrapper.enable();
+    }
 
 });
\ No newline at end of file
diff --git a/tpl/admin/config.tpl b/tpl/admin/config.tpl
index bb5d9dcf..7d92011d 100644
--- a/tpl/admin/config.tpl
+++ b/tpl/admin/config.tpl
@@ -92,4 +92,5 @@ $config = [
     'default_poll_duration' => 180,         // default values for the new poll duration (number of days).
     /* create_classic_poll.php */
     'user_can_add_img_or_link' => true,     // user can add link or URL when creating his poll.
+    'markdown_editor_by_default' => true    // The markdown editor for the description is enabled by default
 ];
\ No newline at end of file
diff --git a/tpl/part/description_markdown.tpl b/tpl/part/description_markdown.tpl
index 7029be24..e2bb823d 100644
--- a/tpl/part/description_markdown.tpl
+++ b/tpl/part/description_markdown.tpl
@@ -1,8 +1,8 @@
 {* Description buttons for markdown *}
 
 <div class="btn-group" role="group" aria-label="...">
-    <button type="button" id="rich-editor-button" class="btn btn-default btn-xs active">{__('PollInfo', 'Rich editor')}</button>
-    <button type="button" id="simple-editor-button" class="btn btn-default btn-xs">{__('PollInfo', 'Simple editor')}</button>
+    <button type="button" id="rich-editor-button" class="btn btn-default btn-xs{if $default_to_marldown_editor} active{/if}">{__('PollInfo', 'Rich editor')}</button>
+    <button type="button" id="simple-editor-button" class="btn btn-default btn-xs{if !$default_to_marldown_editor} active{/if}">{__('PollInfo', 'Simple editor')}</button>
 </div>
 
 <a href="" data-toggle="modal" data-target="#markdown_modal"><i class="glyphicon glyphicon-info-sign"></i></a><!-- TODO Add accessibility -->
-- 
GitLab