WIP: new photo uploader.

This commit is contained in:
2016-09-04 11:54:17 +02:00
parent f96ab144ef
commit 6aaa21b176
2 changed files with 51 additions and 54 deletions

38
public/js/upload_queue.js Normal file
View File

@@ -0,0 +1,38 @@
function UploadQueue(options) {
this.queue = options.queue_element;
this.previews = options.preview_area;
this.addEvents();
}
UploadQueue.prototype.addEvents = function() {
var that = this;
that.queue.addEventListener('change', function() {
that.clearArea();
for (var i = 0; i < that.queue.files.length; i++) {
that.addPreviewForFile(that.queue.files[i]);
};
});
};
UploadQueue.prototype.clearArea = function() {
this.previews.innerHTML = '';
}
UploadQueue.prototype.addPreviewForFile = function(file) {
if (!file) {
return false;
}
var preview = document.createElement('img');
preview.id = ''
preview.style.maxWidth = '150px';
preview.style.maxHeight = '150px';
var reader = new FileReader();
var that = this;
reader.addEventListener('load', function() {
preview.src = reader.result;
that.previews.appendChild(preview);
}, false);
reader.readAsDataURL(file);
};