Added image pasting from clipboard

This commit is contained in:
Pitu 2017-01-30 03:25:34 -03:00
parent 0258c290ff
commit 6c2eb4e98e

View File

@ -105,6 +105,7 @@ upload.prepareDropzone = function(){
},
init: function() {
this.on('addedfile', function(file) {
myDropzone = this;
document.getElementById('uploads').style.display = 'block';
});
}
@ -139,6 +140,22 @@ upload.prepareDropzone = function(){
}
//Handle image paste event
window.addEventListener('paste', function(event) {
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) {
var item = items[index];
if (item.kind === 'file') {
var blob = item.getAsFile();
console.log(blob.type);
var file = new File([blob], "pasted-image."+blob.type.match(/(?:[^\/]*\/)([^;]*)/)[1]);
file.type = blob.type;
console.log(file);
myDropzone.addFile(file);
}
}
});
window.onload = function () {
upload.checkIfPublic();
};