simplemde编辑器 新按钮上传图片
以下为显示编辑器的js
var inlineAttachmentConfig = {
uploadUrl: "/upload/attachment",
progressText: '![图片上传中...]()',
errorText: '图片上传失败',
extraParams: {
'_token': $('meta[name="csrf-token"]').attr('content')
},
};
var simplemde = new SimpleMDE({
element: document.getElementById("post-message"),
toolbar: ["bold", "quote", "code", "table", "horizontal-rule", "unordered-list", "ordered-list", "link", {name: "uploadimage", action: UploadImage, className: "fa fa-image", title: "upload image"}, "side-by-side", "fullscreen"],
status: false,
autofocus: true,
placeholder: '请使用 Markdown 格式书写。',
autoDownloadFontAwesome: false,
});
function UploadImage(){
var input = document.getElementById('upInput');
input.click();
}
function upupImage(editor) {
fs = $("#upInput")[0].files;
var formData = new FormData()
formData.append("file", fs[0])
fileUpload(formData)
}
function fileUpload(formData) {
$.ajax({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
url: '/upload/attachment',
type: 'POST',
cache: false,
data: formData,
timeout: 5000,
processData: false,
contentType: false,
xhrFields: {
withCredentials: true
},
success: function (data) {
simplemde.codemirror.replaceSelection("")
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("上传出错了")
}
});
}
inlineAttachment.editors.codemirror4.attach(simplemde.codemirror, inlineAttachmentConfig);
codemirror-4.inline-attachment.min.js
inline-attachment.min.js
是粘贴上传