Funktion dropzone_toggle()
This commit is contained in:
parent
394a770a26
commit
37efdc7c81
26
script.js
26
script.js
@ -4,23 +4,19 @@ filetypes = ['image/png', 'image/jpeg', 'image/gif'];
|
|||||||
|
|
||||||
dropzone.addEventListener('dragover', function(e) {
|
dropzone.addEventListener('dragover', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.classList.remove('inactive');
|
dropzone_toggle("on");
|
||||||
this.classList.add('active');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dropzone.addEventListener('dragleave', function(e) {
|
dropzone.addEventListener('dragleave', function(e) {
|
||||||
this.classList.remove('active');
|
dropzone_toggle("off");
|
||||||
this.classList.add('inactive');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dropzone.addEventListener('mousedown', function(e) {
|
dropzone.addEventListener('mousedown', function(e) {
|
||||||
this.classList.remove('inactive');
|
dropzone_toggle("on");
|
||||||
this.classList.add('active');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dropzone.addEventListener('mouseup', function(e) {
|
dropzone.addEventListener('mouseup', function(e) {
|
||||||
this.classList.remove('active');
|
dropzone_toggle("off");
|
||||||
this.classList.add('inactive');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
dropzone.addEventListener('click', function(e) {
|
dropzone.addEventListener('click', function(e) {
|
||||||
@ -38,9 +34,7 @@ dropzone.addEventListener('click', function(e) {
|
|||||||
|
|
||||||
dropzone.addEventListener('drop', function(e) {
|
dropzone.addEventListener('drop', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
dropzone_toggle("off");
|
||||||
this.classList.remove('active');
|
|
||||||
this.classList.add('inactive');
|
|
||||||
|
|
||||||
file = e.dataTransfer.files[0];
|
file = e.dataTransfer.files[0];
|
||||||
if(filetypes.includes(file.type)) {
|
if(filetypes.includes(file.type)) {
|
||||||
@ -48,6 +42,16 @@ dropzone.addEventListener('drop', function(e) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function dropzone_toggle(state) {
|
||||||
|
if(state == "on") {
|
||||||
|
dropzone.classList.remove('inactive');
|
||||||
|
dropzone.classList.add('active');
|
||||||
|
} else if(state == "off") {
|
||||||
|
dropzone.classList.remove('active');
|
||||||
|
dropzone.classList.add('inactive');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function upload(file) {
|
function upload(file) {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
data.append('upload', file)
|
data.append('upload', file)
|
||||||
|
Loading…
Reference in New Issue
Block a user