From 6aaa21b176094765246a2421e9a7b373e02cb695 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sun, 4 Sep 2016 11:54:17 +0200 Subject: [PATCH] WIP: new photo uploader. --- public/js/upload_queue.js | 38 +++++++++++++++++++++ templates/MediaUploader.php | 67 +++++++------------------------------ 2 files changed, 51 insertions(+), 54 deletions(-) create mode 100644 public/js/upload_queue.js 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 '
-

Upload new media

+

Upload new photos

Select files

-
    -
  • -
    - -
  • -
  • -
    - -
  • -
  • -
    - -
  • -
+
-
-

Link tags

-
    -
  • -
+
- - -
- '; + + + '; } }