Skip to content

Commit a3f1004

Browse files
committed
Request Markdown rendering on page load
1 parent 249a676 commit a3f1004

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

martor/static/martor/js/martor.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@
128128
$(obj).find('.modal-help-guide').attr({'data-field-name': field_name});
129129
$(obj).find('.modal-emoji').attr({'data-field-name': field_name});
130130

131-
// Set if editor has changed.
132-
editor.on('change', function(evt){
133-
var value = editor.getValue();
134-
textareaId.val(value);
135-
});
136-
137131
// resize the editor using `resizable.min.js`
138132
$('#'+editorId).resizable({
139133
direction: 'bottom',
@@ -146,7 +140,7 @@
146140
var currentTab = $('.tab.segment[data-tab=preview-tab-'+field_name+']');
147141
var previewTabButton = $('.item[data-tab=preview-tab-'+field_name+']');
148142
var refreshPreview = function() {
149-
var value = editor.getValue();
143+
var value = textareaId.val();
150144
var form = new FormData();
151145
form.append('content', value);
152146
form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
@@ -171,9 +165,19 @@
171165
});
172166
};
173167

174-
if (editorConfig.living === 'true') {
175-
editor.on('change', refreshPreview);
176-
}else {
168+
// Refresh the preview unconditionally on first load.
169+
refreshPreview();
170+
171+
// Set if editor has changed.
172+
editor.on('change', function (evt) {
173+
var value = editor.getValue();
174+
textareaId.val(value);
175+
if (editorConfig.living === 'true') {
176+
refreshPreview();
177+
}
178+
});
179+
180+
if (editorConfig.living !== 'true') {
177181
previewTabButton.click(function(){
178182
// hide the `.martor-toolbar` for this current editor if under preview.
179183
$(this).closest('.tab-martor-menu').find('.martor-toolbar').hide();

0 commit comments

Comments
 (0)