mirror of
https://0xacab.org/jvoisin/mat2-web.git
synced 2025-02-24 00:59:59 -05:00
Handle copy/paste
This commit is contained in:
parent
32f2411400
commit
d524c65209
@ -25,13 +25,40 @@
|
|||||||
dropZone.classList.remove(hoverClassName);
|
dropZone.classList.remove(hoverClassName);
|
||||||
});
|
});
|
||||||
|
|
||||||
// This is the most important event, the event that gives access to files
|
// Handle copy/paste
|
||||||
|
dropZone.addEventListener("paste", function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (e.clipboardData.items.length != 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = e.clipboardData.items[0];
|
||||||
|
if (item.type.indexOf("image") == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch('/', {
|
||||||
|
method: 'POST',
|
||||||
|
body: item.getAsFile(),
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(body => { // Yes, this is ugly
|
||||||
|
document.open()
|
||||||
|
document.write(body)
|
||||||
|
document.close()
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
dropZone.addEventListener("drop", function (e) {
|
dropZone.addEventListener("drop", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dropZone.classList.remove(hoverClassName);
|
dropZone.classList.remove(hoverClassName);
|
||||||
|
|
||||||
const files = Array.from(e.dataTransfer.files);
|
const files = Array.from(e.dataTransfer.files);
|
||||||
if (files.length > 0) {
|
if (files.length != 1 ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
data.append('file', file);
|
data.append('file', file);
|
||||||
@ -47,6 +74,5 @@
|
|||||||
document.write(body)
|
document.write(body)
|
||||||
document.close()
|
document.close()
|
||||||
})
|
})
|
||||||
}
|
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user