2023-03-22 23:10:33 +01:00
|
|
|
dropzone = document.getElementById('dropzone');
|
|
|
|
|
2023-03-23 11:15:05 +01:00
|
|
|
dropzone.addEventListener('dragover', function(e) {
|
2023-03-22 23:10:33 +01:00
|
|
|
this.classList.remove('nodrop');
|
|
|
|
this.classList.add('drop');
|
|
|
|
});
|
|
|
|
|
2023-03-23 11:15:05 +01:00
|
|
|
dropzone.addEventListener('dragleave', function(e) {
|
2023-03-23 17:47:00 +01:00
|
|
|
this.classList.remove('drop');
|
|
|
|
this.classList.add('nodrop');
|
|
|
|
});
|
2023-03-23 11:15:05 +01:00
|
|
|
|
2023-03-23 17:47:00 +01:00
|
|
|
dropzone.addEventListener('mousedown', function(e) {
|
|
|
|
this.classList.remove('nodrop');
|
|
|
|
this.classList.add('drop');
|
|
|
|
console.log('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
dropzone.addEventListener('mouseup', function(e) {
|
2023-03-22 23:10:33 +01:00
|
|
|
this.classList.remove('drop');
|
|
|
|
this.classList.add('nodrop');
|
2023-03-23 17:47:00 +01:00
|
|
|
console.log('unclick');
|
2023-03-22 23:10:33 +01:00
|
|
|
});
|
|
|
|
|
2023-03-23 11:15:05 +01:00
|
|
|
dropzone.addEventListener('click', function(e) {
|
2023-03-22 23:10:33 +01:00
|
|
|
input = document.createElement('input');
|
|
|
|
input.type = 'file';
|
|
|
|
input.click();
|
2023-03-23 00:35:35 +01:00
|
|
|
|
|
|
|
input.onchange = function(e) {
|
|
|
|
file = e.target.files[0];
|
2023-03-23 11:15:05 +01:00
|
|
|
if( file.type == 'image/png' || file.type == 'image/jpeg' ) {
|
2023-03-23 00:35:35 +01:00
|
|
|
upload(e.target.files[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-03-22 23:10:33 +01:00
|
|
|
|
2023-03-23 11:15:05 +01:00
|
|
|
dropzone.addEventListener('drop', function(e) {
|
2023-03-22 23:10:33 +01:00
|
|
|
e.preventDefault();
|
2023-03-23 11:15:05 +01:00
|
|
|
|
2023-03-22 23:10:33 +01:00
|
|
|
this.classList.remove('drop');
|
|
|
|
this.classList.add('nodrop');
|
|
|
|
|
|
|
|
file = e.dataTransfer.files[0];
|
2023-03-23 11:15:05 +01:00
|
|
|
if( file.type == 'image/png' || file.type == 'image/jpeg' ) {
|
2023-03-22 23:10:33 +01:00
|
|
|
upload(e.dataTransfer.files[0]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function upload(file) {
|
|
|
|
const data = new FormData();
|
|
|
|
data.append('upload', file)
|
|
|
|
|
2023-03-23 11:15:05 +01:00
|
|
|
fetch('upload.php', {
|
2023-03-22 23:10:33 +01:00
|
|
|
method: 'POST',
|
|
|
|
body: data
|
2023-03-23 11:15:05 +01:00
|
|
|
}).then(response => {
|
2023-03-22 23:10:33 +01:00
|
|
|
response.json().then(parsedValue => {
|
|
|
|
filename = parsedValue['filename'];
|
|
|
|
datadir = parsedValue['datadir'];
|
|
|
|
openUploadedFile(datadir, filename);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function openUploadedFile(datadir, filename) {
|
|
|
|
window.open(window.location.href + datadir + '/' + filename, '_self');
|
|
|
|
};
|