|
|
|
|
@ -1,22 +1,21 @@
|
|
|
|
|
$(function () {
|
|
|
|
|
|
|
|
|
|
var $container = $("#edit-post-container");
|
|
|
|
|
var $editorContainer = $container.find(".edit-post-editor");
|
|
|
|
|
var $submitButton = $container.find("button[type=submit]");
|
|
|
|
|
var $form = $container.find("form#edit-post-form");
|
|
|
|
|
var editorDataKey = "tuiEditor";
|
|
|
|
|
var $titleLengthWarning = $("#title-length-warning");
|
|
|
|
|
var maxTitleLength = parseInt($titleLengthWarning.data("max-length"));
|
|
|
|
|
var $container = $('#edit-post-container');
|
|
|
|
|
var $editorContainer = $container.find('.edit-post-editor');
|
|
|
|
|
var $submitButton = $container.find('button[type=submit]');
|
|
|
|
|
var $form = $container.find('form#edit-post-form');
|
|
|
|
|
var editorDataKey = 'tuiEditor';
|
|
|
|
|
var $titleLengthWarning = $('#title-length-warning');
|
|
|
|
|
var maxTitleLength = parseInt($titleLengthWarning.data('max-length'));
|
|
|
|
|
|
|
|
|
|
var $title = $('#Post_Title');
|
|
|
|
|
var $coverImage = $("#CoverImage");
|
|
|
|
|
var $coverImage = $('#CoverImage');
|
|
|
|
|
var $postCoverImage = $('#Post_CoverImage');
|
|
|
|
|
var $coverImageFile = $('#CoverImageFile');
|
|
|
|
|
var $postFormSubmitButton = $('#PostFormSubmitButton');
|
|
|
|
|
|
|
|
|
|
var setCoverImage = function (file) {
|
|
|
|
|
$postCoverImage.val(file.fileUrl);
|
|
|
|
|
$coverImage.attr("src", file.fileUrl);
|
|
|
|
|
$coverImage.attr('src', file.fileUrl);
|
|
|
|
|
$postFormSubmitButton.removeAttr('disabled');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -25,14 +24,14 @@
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: "/api/blogging/files/images/upload",
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/api/blogging/files/images/upload',
|
|
|
|
|
data: formData,
|
|
|
|
|
contentType: false,
|
|
|
|
|
processData: false,
|
|
|
|
|
success: function (response) {
|
|
|
|
|
setCoverImage(response);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -48,7 +47,7 @@
|
|
|
|
|
|
|
|
|
|
checkTitleLength();
|
|
|
|
|
|
|
|
|
|
$title.on("change paste keyup", function () {
|
|
|
|
|
$title.on('change paste keyup', function () {
|
|
|
|
|
checkTitleLength();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -62,50 +61,50 @@
|
|
|
|
|
uploadCoverImage(file);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var uploadImage = function (file, callbackFn) {
|
|
|
|
|
var formData = new FormData();
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: "/api/blogging/files/images/upload",
|
|
|
|
|
type: 'POST',
|
|
|
|
|
url: '/api/blogging/files/images/upload',
|
|
|
|
|
data: formData,
|
|
|
|
|
contentType: false,
|
|
|
|
|
processData: false,
|
|
|
|
|
success: function (response) {
|
|
|
|
|
callbackFn(response.fileUrl);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var newPostEditor = $editorContainer.tuiEditor({
|
|
|
|
|
var newPostEditor = $editorContainer
|
|
|
|
|
.tuiEditor({
|
|
|
|
|
usageStatistics: false,
|
|
|
|
|
initialEditType: 'markdown',
|
|
|
|
|
previewStyle: 'tab',
|
|
|
|
|
height: "auto",
|
|
|
|
|
height: 'auto',
|
|
|
|
|
initialValue: $form.find("input[name='Post.Content']").val(),
|
|
|
|
|
hooks: {
|
|
|
|
|
addImageBlobHook: function (blob, callback, source) {
|
|
|
|
|
var imageAltText = blob.name;
|
|
|
|
|
|
|
|
|
|
uploadImage(blob,
|
|
|
|
|
function (fileUrl) {
|
|
|
|
|
uploadImage(blob, function (fileUrl) {
|
|
|
|
|
callback(fileUrl, imageAltText);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
events: {
|
|
|
|
|
load: function () {
|
|
|
|
|
$editorContainer.find(".loading-cover").remove();
|
|
|
|
|
$submitButton.prop("disabled", false);
|
|
|
|
|
$form.data("validator").settings.ignore = '.ignore';
|
|
|
|
|
$editorContainer.find('.loading-cover').remove();
|
|
|
|
|
$submitButton.prop('disabled', false);
|
|
|
|
|
$form.data('validator').settings.ignore = '.ignore';
|
|
|
|
|
$editorContainer.find(':input').addClass('ignore');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).data(editorDataKey);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.data(editorDataKey);
|
|
|
|
|
|
|
|
|
|
$container.find("form#edit-post-form").submit(function (e) {
|
|
|
|
|
$container.find('form#edit-post-form').submit(function (e) {
|
|
|
|
|
var $postTextInput = $form.find("input[name='Post.Content']");
|
|
|
|
|
|
|
|
|
|
var postText = newPostEditor.getMarkdown();
|
|
|
|
|
@ -122,6 +121,4 @@
|
|
|
|
|
$(this).off('submit').submit();
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|