forked from Public/pics
39 lines
901 B
JavaScript
39 lines
901 B
JavaScript
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);
|
|
};
|