Use Pillar's built-in markdown when editing projects/creating posts.
This commit is contained in:
@@ -122,41 +122,38 @@ script(type="text/javascript").
|
|||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
};
|
};
|
||||||
|
|
||||||
var convert = new Markdown.getSanitizingConverter().makeHtml;
|
|
||||||
|
|
||||||
/* Build the markdown preview when typing in textarea */
|
/* Build the markdown preview when typing in textarea */
|
||||||
$(function() {
|
$(function() {
|
||||||
|
var $contentField = $('.form-group.description textarea'),
|
||||||
|
$contentPreview = $('<div class="node-edit-form-md-preview" />').insertAfter($contentField);
|
||||||
|
|
||||||
var $textarea = $('.form-group.content textarea'),
|
function parseDescriptionContent(content) {
|
||||||
$loader = $('<div class="md-preview-loading"><i class="pi-spin spin"></i></div>').insertAfter($textarea),
|
|
||||||
$preview = $('<div class="node-edit-form-md-preview" />').insertAfter($loader);
|
|
||||||
|
|
||||||
$loader.hide();
|
$.ajax({
|
||||||
|
url: "{{ url_for('nodes.preview_markdown')}}",
|
||||||
|
type: 'post',
|
||||||
|
data: {content: content},
|
||||||
|
headers: {"X-CSRFToken": csrf_token},
|
||||||
|
headers: {},
|
||||||
|
dataType: 'json'
|
||||||
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
$contentPreview.html(data.content);
|
||||||
|
})
|
||||||
|
.fail(function (err) {
|
||||||
|
toastr.error(xhrErrorResponseMessage(err), 'Parsing failed');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Delay function to not start converting heavy posts immediately
|
var options = {
|
||||||
var delay = (function(){
|
callback: parseDescriptionContent,
|
||||||
var timer = 0;
|
wait: 750,
|
||||||
return function(callback, ms){
|
highlight: false,
|
||||||
clearTimeout (timer);
|
allowSubmit: false,
|
||||||
timer = setTimeout(callback, ms);
|
captureLength: 2
|
||||||
};
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
$textarea.keyup(function() {
|
$contentField.typeWatch(options);
|
||||||
/* If there's an iframe (YouTube embed), delay markdown convert 1.5s */
|
|
||||||
if (/iframe/i.test($textarea.val())) {
|
|
||||||
$loader.show();
|
|
||||||
|
|
||||||
delay(function(){
|
|
||||||
// Convert markdown
|
|
||||||
$preview.html(convert($textarea.val()));
|
|
||||||
$loader.hide();
|
|
||||||
}, 1500 );
|
|
||||||
} else {
|
|
||||||
// Convert markdown
|
|
||||||
$preview.html(convert($textarea.val()));
|
|
||||||
};
|
|
||||||
}).trigger('keyup');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
@@ -122,7 +122,6 @@ script(type="text/javascript").
|
|||||||
$('.project-mode-edit').displayAs('inline-block');
|
$('.project-mode-edit').displayAs('inline-block');
|
||||||
|
|
||||||
ProjectUtils.setProjectAttributes({projectId: "{{project._id}}", isProject: true, nodeId: ''});
|
ProjectUtils.setProjectAttributes({projectId: "{{project._id}}", isProject: true, nodeId: ''});
|
||||||
var convert = new Markdown.getSanitizingConverter().makeHtml;
|
|
||||||
|
|
||||||
$('.button-save').on('click', function(e){
|
$('.button-save').on('click', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -136,36 +135,36 @@ script(type="text/javascript").
|
|||||||
/* Build the markdown preview when typing in textarea */
|
/* Build the markdown preview when typing in textarea */
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
var $textarea = $('.form-group.description textarea'),
|
var $contentField = $('.form-group.description textarea'),
|
||||||
$loader = $('<div class="md-preview-loading"><i class="pi-spin spin"></i></div>').insertAfter($textarea),
|
$contentPreview = $('<div class="node-edit-form-md-preview" />').insertAfter($contentField);
|
||||||
$preview = $('<div class="node-edit-form-md-preview" />').insertAfter($loader);
|
|
||||||
|
|
||||||
$loader.hide();
|
function parseDescriptionContent(content) {
|
||||||
|
|
||||||
// Delay function to not start converting heavy posts immediately
|
$.ajax({
|
||||||
var delay = (function(){
|
url: "{{ url_for('nodes.preview_markdown')}}",
|
||||||
var timer = 0;
|
type: 'post',
|
||||||
return function(callback, ms){
|
data: {content: content},
|
||||||
clearTimeout (timer);
|
headers: {"X-CSRFToken": csrf_token},
|
||||||
timer = setTimeout(callback, ms);
|
headers: {},
|
||||||
};
|
dataType: 'json'
|
||||||
})();
|
})
|
||||||
|
.done(function (data) {
|
||||||
|
$contentPreview.html(data.content);
|
||||||
|
})
|
||||||
|
.fail(function (err) {
|
||||||
|
toastr.error(xhrErrorResponseMessage(err), 'Parsing failed');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$textarea.keyup(function() {
|
var options = {
|
||||||
/* If there's an iframe (YouTube embed), delay markdown convert 1.5s */
|
callback: parseDescriptionContent,
|
||||||
if (/iframe/i.test($textarea.val())) {
|
wait: 750,
|
||||||
$loader.show();
|
highlight: false,
|
||||||
|
allowSubmit: false,
|
||||||
|
captureLength: 2
|
||||||
|
}
|
||||||
|
|
||||||
delay(function(){
|
$contentField.typeWatch(options);
|
||||||
// Convert markdown
|
|
||||||
$preview.html(convert($textarea.val()));
|
|
||||||
$loader.hide();
|
|
||||||
}, 1500 );
|
|
||||||
} else {
|
|
||||||
// Convert markdown
|
|
||||||
$preview.html(convert($textarea.val()));
|
|
||||||
};
|
|
||||||
}).trigger('keyup');
|
|
||||||
|
|
||||||
$('input, textarea').keypress(function () {
|
$('input, textarea').keypress(function () {
|
||||||
// Unused: save status of the page as 'edited'
|
// Unused: save status of the page as 'edited'
|
||||||
|
Reference in New Issue
Block a user