diff --git a/public/js/upload_queue.js b/public/js/upload_queue.js new file mode 100644 index 0000000..06c0983 --- /dev/null +++ b/public/js/upload_queue.js @@ -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); +}; diff --git a/templates/MediaUploader.php b/templates/MediaUploader.php index dbab5a7..5e9b683 100644 --- a/templates/MediaUploader.php +++ b/templates/MediaUploader.php @@ -12,66 +12,25 @@ class MediaUploader extends SubTemplate { echo '