Add copy and paste for images

Switch comparison operator to ===

Move to stricter parsing of clipboard items
This commit is contained in:
beejaygee 2017-02-05 18:21:35 +08:00
parent 1e498294e0
commit 76c165a10a

View file

@ -35,7 +35,8 @@
'click .choose-file': 'open',
'drop': 'openDropped',
'dragover': 'showArea',
'dragleave': 'hideArea'
'dragleave': 'hideArea',
'paste': 'onPaste'
},
open: function(e) {
@ -281,6 +282,19 @@
e.stopPropagation();
e.preventDefault();
this.$el.removeClass('dropoff');
},
onPaste: function(e) {
var items = e.originalEvent.clipboardData.items;
var imgBlob = null;
for (var i = 0; i < items.length; i++) {
if (items[i].type.split('/')[0] === 'image') {
imgBlob = items[i].getAsFile();
}
}
if (imgBlob !== null) {
this.file = imgBlob;
this.previewImages();
}
}
});
})();