فهرست منبع

#3957 - Quill: not allow empty paragraphs

roman.lesnikov@gmail.com 4 سال پیش
والد
کامیت
138e07f316

+ 11 - 1
inc/js/editor.quill.js

@@ -61,6 +61,12 @@ function bx_editor_init(oEditor, oParams){
             }
         }
     }
+    
+    sVal = $(oParams.selector).val();    
+    if(!oParams.empty_tags){
+        sVal = sVal.replaceAll('<p><br></p>','');    
+    }
+    
     $(oParams.selector).after("<div id='" + oParams.name + "' class='bx-def-font-inputs bx-form-input-textarea bx-form-input-html bx-form-input-html-quill " + oParams.css_class + "'>" + $(oParams.selector).val() + "</div>" );
     $(oParams.selector).hide();
     
@@ -332,7 +338,11 @@ function bx_editor_init(oEditor, oParams){
     });
     
     oEditor.on('text-change', function(delta, oldDelta, source) {
-        $(oParams.selector).val(oEditor.container.firstChild.innerHTML);
+        sVal = oEditor.container.firstChild.innerHTML;
+        if(!oParams.empty_tags){
+            sVal = sVal.replaceAll('<p><br></p>','');
+        }
+        $(oParams.selector).val(sVal); 
     });
     
     return oEditor

+ 1 - 0
install/sql/system.sql

@@ -323,6 +323,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_live_updates_interval', '_adm_stg_cpt_option_sys_live_updates_interval', '10000', 'digit', '', '', '', '', 60),
 
 (@iCategoryId, 'sys_quill_insert_as_plain_text', '_adm_stg_cpt_option_sys_quill_insert_as_plain_text', '', 'checkbox', '', '', '', '', 65),
+(@iCategoryId, 'sys_quill_allow_empty_tags', '_adm_stg_cpt_option_sys_quill_allow_empty_tags', 'on', 'checkbox', '', '', '', '', 66),
 
 (@iCategoryId, 'sys_quill_allowed_tags_mini', '_adm_stg_cpt_option_sys_quill_allowed_tags_mini', '[\'link\', \'size\', \'image\', \'menthion-link\', \'embed-link\']', 'digit', '', '', '', '', 67),
 (@iCategoryId, 'sys_quill_allowed_tags_standard', '_adm_stg_cpt_option_sys_quill_allowed_tags_standard', '', 'digit', '', '', '', '', 68),

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1664,6 +1664,7 @@
     <string name="_adm_stg_err_option_template"><![CDATA[Template cannot be empty and must have a valid name.]]></string>
     <string name="_adm_stg_cpt_option_use_like_operator"><![CDATA[Use operator LIKE for search (recommended for small content)]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_insert_as_plain_text"><![CDATA[Quill - paste as plain text]]></string>
+    <string name="_adm_stg_cpt_option_sys_quill_allow_empty_tags"><![CDATA[Quill - allow empty tags]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_allowed_tags_mini"><![CDATA[Quill - allowed formats for mini editor]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_allowed_tags_standard"><![CDATA[Quill - allowed formats for standard editor]]></string>
      <string name="_adm_stg_cpt_option_sys_quill_allowed_tags_full"><![CDATA[Quill - allowed formats for full editor]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1651,6 +1651,7 @@
     <string name="_adm_stg_err_option_template"><![CDATA[Тема не может быть пустой и должна иметь приемлемое название.]]></string>
     <string name="_adm_stg_cpt_option_use_like_operator"><![CDATA[Использовать для поиска оператор LIKE (рекомендуется для небольшого содержимого)]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_insert_as_plain_text"><![CDATA[Quill - вставлять как текст]]></string>
+    <string name="_adm_stg_cpt_option_sys_quill_allow_empty_tags"><![CDATA[Quill - разрешить пустые теги]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_allowed_tags_mini"><![CDATA[Quill - разрешенные форматы  для мини редактора]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_allowed_tags_standard"><![CDATA[Quill - разрешенные форматы  для стандартного редактора]]></string>
     <string name="_adm_stg_cpt_option_sys_quill_allowed_tags_full"><![CDATA[Quill - разрешенные форматы  для полного редактора]]></string>

+ 2 - 0
template/scripts/BxBaseEditorQuill.php

@@ -27,6 +27,7 @@ class BxBaseEditorQuill extends BxDolEditor
             root_url: '{bx_url_root}',
             query_params: {bx_var_query_params},
             insert_as_plain_text: {insert_as_plain_text},
+            empty_tags: {empty_tags},
             allowed_tags: {allowed_tags}
         }
         {bx_var_editor_name} = bx_editor_init({bx_var_editor_name}, oParams);";
@@ -127,6 +128,7 @@ class BxBaseEditorQuill extends BxDolEditor
             'bx_var_form_id' => $aAttrs['form_id'],
             'toolbar' => $sToolbarItems ? '[' . $sToolbarItems . ']' : 'false',
             'insert_as_plain_text' => getParam('sys_quill_insert_as_plain_text') == 'on' ? 'true' : 'false',
+            'empty_tags' => getParam('sys_quill_allow_empty_tags') == 'on' ? 'true' : 'false',
             'allowed_tags' => $sAllowedTags == '' ? 'false' : $sAllowedTags,
             'bx_var_css_additional_class' => $sToolbarItems ? '' : 'bx-form-input-html-quill-empty',
             'bx_var_element_name' => str_replace(['-', ' '], '_', $aAttrs['element_name']),