|
128 | 128 | $(obj).find('.modal-help-guide').attr({'data-field-name': field_name}); |
129 | 129 | $(obj).find('.modal-emoji').attr({'data-field-name': field_name}); |
130 | 130 |
|
| 131 | + // Set if editor has changed. |
| 132 | + editor.on('change', function(evt){ |
| 133 | + var value = editor.getValue(); |
| 134 | + textareaId.val(value); |
| 135 | + }); |
| 136 | + |
131 | 137 | // resize the editor using `resizable.min.js` |
132 | 138 | $('#'+editorId).resizable({ |
133 | 139 | direction: 'bottom', |
|
139 | 145 | // update the preview if this menu is clicked |
140 | 146 | var currentTab = $('.tab.segment[data-tab=preview-tab-'+field_name+']'); |
141 | 147 | var previewTabButton = $('.item[data-tab=preview-tab-'+field_name+']'); |
| 148 | + var needsRefresh = true; |
142 | 149 | var refreshPreview = function() { |
| 150 | + if (!needsRefresh) { |
| 151 | + return; |
| 152 | + } |
| 153 | + |
143 | 154 | var value = textareaId.val(); |
144 | 155 | var form = new FormData(); |
145 | 156 | form.append('content', value); |
|
152 | 163 | processData: false, |
153 | 164 | contentType: false, |
154 | 165 | success: function(response) { |
155 | | - if(response){ |
156 | | - currentTab.html(response); |
157 | | - $('pre').each(function(i, block){ |
158 | | - hljs.highlightBlock(block); |
159 | | - }); |
160 | | - }else {currentTab.html('<p>Nothing to preview</p>');} |
| 166 | + if (response) { |
| 167 | + currentTab.html(response); |
| 168 | + $('pre').each(function (i, block) { |
| 169 | + hljs.highlightBlock(block); |
| 170 | + }); |
| 171 | + needsRefresh = false; |
| 172 | + } else { |
| 173 | + currentTab.html('<p>Nothing to preview</p>'); |
| 174 | + } |
161 | 175 | }, |
162 | 176 | error: function(response) { |
163 | 177 | console.log("error", response); |
|
171 | 185 | // Set if editor has changed. |
172 | 186 | editor.on('change', function (evt) { |
173 | 187 | var value = editor.getValue(); |
174 | | - textareaId.val(value); |
175 | | - if (editorConfig.living === 'true') { |
176 | | - refreshPreview(); |
| 188 | + if (value !== textareaId.val()) { |
| 189 | + textareaId.val(value); |
| 190 | + needsRefresh = true; |
| 191 | + if (editorConfig.living === 'true') { |
| 192 | + refreshPreview(); |
| 193 | + } |
177 | 194 | } |
178 | 195 | }); |
179 | 196 |
|
|
0 commit comments