templates, main: copy and paste images
Make use of the Clipboard API. Also vivi dis is for you Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
@@ -119,15 +119,12 @@ AUTHOR
|
||||
}
|
||||
|
||||
function dropHandler(ev) {
|
||||
console.log('File(s) dropped');
|
||||
|
||||
ev.preventDefault();
|
||||
|
||||
if (ev.dataTransfer.items) {
|
||||
for (var i = 0; i < ev.dataTransfer.items.length; i++) {
|
||||
if (ev.dataTransfer.items[i].kind === 'file') {
|
||||
var file = ev.dataTransfer.items[i].getAsFile();
|
||||
console.log('... file[' + i + '].name = ' + file.name);
|
||||
|
||||
var url = window.location.href;
|
||||
|
||||
@@ -140,18 +137,29 @@ AUTHOR
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 0; i < ev.dataTransfer.files.length; i++) {
|
||||
console.log('... file[' + i + '].name = ' + ev.dataTransfer.files[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function dragOverHandler(ev) {
|
||||
console.log('File(s) in drop zone');
|
||||
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
document.onpaste = function(pasteEvent) {
|
||||
var item = pasteEvent.clipboardData.items[0];
|
||||
var blob = item.getAsFile();
|
||||
|
||||
if (blob !== null && blob !== '') {
|
||||
var url = window.location.href;
|
||||
|
||||
postData(url, blob)
|
||||
.then(data => {
|
||||
window.location.href = data.url;
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.info(err + " url: " + url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
{% endblock body %}
|
||||
{% endblock body %}
|
||||
|
||||
Reference in New Issue
Block a user