WIP: new photo uploader.
This commit is contained in:
38
public/js/upload_queue.js
Normal file
38
public/js/upload_queue.js
Normal 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);
|
||||
};
|
||||
Reference in New Issue
Block a user