restore drag drop

This commit is contained in:
Ali Abid 2019-03-03 22:28:10 -08:00
parent fba984d8b3
commit 40a74da964

View File

@ -2,23 +2,39 @@ $(".input_image").click(function (e) {
$(this).parent().find(".hidden_upload").click();
})
$(".input_image").on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
e.preventDefault();
e.stopPropagation();
})
function loadPreviewFromFiles(files) {
var ReaderObj = new FileReader()
ReaderObj.readAsDataURL(files[0])
ReaderObj.onloadend = function() {
$(".input_caption").hide()
$(".input_image img").attr("src", this.result)
}
}
$(".input_image").on('drop', function(e) {
files = e.originalEvent.dataTransfer.files;
loadPreviewFromFiles(files)
});
$(".hidden_upload").on("change", function() {
var files = !!this.files ? this.files : []
if (!files.length || !window.FileReader) {
return
}
if (/^image/.test(files[0].type)) {
var ReaderObj = new FileReader()
ReaderObj.readAsDataURL(files[0])
ReaderObj.onloadend = function() {
$(".input_caption").hide()
$(".input_image img").attr("src", this.result)
}
loadPreviewFromFiles(files)
} else {
alert("Invalid input")
}
})
$('body').on('click', '.submit', function(e) {
var src = $('.input_image img').attr('src');
ws.send(src, function(e) {