Browse Source

#WOA-2374|resolved|Clear HTML if text is empty

ihork 8 years ago
parent
commit
b639aed882
1 changed files with 13 additions and 0 deletions
  1. 13
    0
      src/editor.html

+ 13
- 0
src/editor.html View File

863
 				});
863
 				});
864
 			}
864
 			}
865
 
865
 
866
+			function clearHtmlIfTextIsEmpty(editorId) {
867
+				var $editor = $(`#${editorId}`);
868
+
869
+				$editor.on('input', function() {
870
+					if (!(this.textContent || this.querySelectorAll('img, li').length)) {
871
+						this.innerHTML = '';
872
+					}
873
+				});
874
+			}
875
+
866
 			zss_editor.init = function() {
876
 			zss_editor.init = function() {
867
 
877
 
868
 				disableLineBreakIfNecessary('zss_editor_title');
878
 				disableLineBreakIfNecessary('zss_editor_title');
871
 				setupTouchEndEnableEditing('zss_editor_title');
881
 				setupTouchEndEnableEditing('zss_editor_title');
872
 				setupTouchEndEnableEditing('zss_editor_content');
882
 				setupTouchEndEnableEditing('zss_editor_content');
873
 
883
 
884
+				clearHtmlIfTextIsEmpty('zss_editor_title');
885
+				clearHtmlIfTextIsEmpty('zss_editor_content');
886
+
874
 				$(document).on('selectionchange',function(e){
887
 				$(document).on('selectionchange',function(e){
875
 					console.log('selectionchange');
888
 					console.log('selectionchange');
876
 					zss_editor.calculateEditorHeightWithCaretPosition();
889
 					zss_editor.calculateEditorHeightWithCaretPosition();