Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support drag and drop images to the documents #220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/config.js
Expand Up @@ -33,8 +33,8 @@ var Config = {
"name": "日本語"
}
],
"lang": "zh-cn",
"theme": "night",
"lang": "en-us",
"theme": "",
"view": "list",
"mdTheme": "github2"
};
61 changes: 56 additions & 5 deletions public/js/app/page.js
Expand Up @@ -2260,19 +2260,70 @@ function userMenu(allUsers) {
});
}

$(function() {
initUploadImage();
Writting.init();
function InitDragAndDropImages(){

// disable drag & drop
// disable default drag & drop
document.body.addEventListener('dragover', function(e){
e.preventDefault();
e.stopPropagation();
}, false);

document.body.addEventListener('drop', function(e){

var note = Note.getCurNote();
if(note)
{
if(!Note.readOnly)
{
var files = e.dataTransfer.files;
var imageTypes = ['image/png', 'image/gif', 'image/bmp', 'image/jpg', 'image/jpeg'];

for(var i=0;i<files.length; i++){
if (e.dataTransfer && e.dataTransfer.files) {
var fileType = files[i].type;
if (imageTypes.includes(fileType)) {
console.log(e.dataTransfer.files[i].path);
var imagePath = e.dataTransfer.files[i].path;

FileService.uploadImage(imagePath, function(newImage, msg) {
if(newImage) {
var note = Note.getCurNote();
var url = EvtService.getImageLocalUrl(newImage.FileId);
if(!note.IsMarkdown) {
tinymce.activeEditor.insertContent('<img src="' + url + '">');
} else {
MD.insertLink(url, '', true);
}
} else {
alert(msg || "error");
}
});


} else {
console.log('dropped file is not an image', files[i]);
}
}
}
}
else{
console.log("note is read only");
}
}
else{
console.log("no note...:)");
}


e.preventDefault();
e.stopPropagation();
}, false);
}

$(function() {
initUploadImage();
Writting.init();

InitDragAndDropImages();

// 为了解决linux下重复粘贴的问题
var everPaste;
Expand Down