Skip to content

Commit e674bd8

Browse files
authored
Merge pull request #90 from DMOJ/preview-on-load
Request Markdown rendering on page load
2 parents bc046ef + a3f1004 commit e674bd8

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
@@ -125,12 +125,6 @@
125125
$(obj).find('.modal-help-guide').attr({'data-field-name': field_name});
126126
$(obj).find('.modal-emoji').attr({'data-field-name': field_name});
127127

128-
// Set if editor has changed.
129-
editor.on('change', function(evt){
130-
var value = editor.getValue();
131-
textareaId.val(value);
132-
});
133-
134128
// resize the editor using `resizable.min.js`
135129
$('#'+editorId).resizable({
136130
direction: 'bottom',
@@ -143,7 +137,7 @@
143137
var currentTab = $('.tab.segment[data-tab=preview-tab-'+field_name+']');
144138
var previewTabButton = $('.item[data-tab=preview-tab-'+field_name+']');
145139
var refreshPreview = function() {
146-
var value = editor.getValue();
140+
var value = textareaId.val();
147141
var form = new FormData();
148142
form.append('content', value);
149143
form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
@@ -170,9 +164,19 @@
170164
});
171165
};
172166

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

0 commit comments

Comments
 (0)