+ slide = this.createSlide(file);
+ this.previewQueuePush(slide);
+ this.uploadQueuePush(slide);
+ }
+};
+
+DDFileUploader.prototype.upload = function(slide) {
+ var reader = new FileReader();
+ var req = new XMLHttpRequest();
+ var file = slide.file;
+ this.uploadedSlide = slide;
+ this.previewImg = slide.img;
+ this.progressBar = slide.progressBar;
+ var self = this;
+
+ addListener(req.upload, 'progress', function(evt){self.progressHandler(evt);});
+ addListener(req, 'readystatechange',
+ function(evt) {
+ if (req.readyState === 4) {
+ self.uploadCompleteHandler(req);
+ }
+ });
+
+ req.open("PUT", this.uploadUrl);
+ req.setRequestHeader("Content-Type", file.type);
+ req.setRequestHeader("X-File-Name", file.name);
+ addListener(reader, 'load',
+ function(evt){
+ try {
+ req.sendAsBinary(evt.target.result);
+ }
+ catch(e){}
+ });
+ reader.readAsBinaryString(file);
+};
+
+DDFileUploader.prototype.uploadCompleteHandler = function(req) {
+ var slide = this.uploadedSlide;
+ this.uploadedSlide.removeChild(slide.label);
+ this.uploadedSlide.removeChild(slide.progressBar);
+ slide.innerHTML = req.responseXML.documentElement.firstChild.data;
+ this.previewsLoaded--;
+ this.previewQueueLoadNext();
+ this.uploadQueueLoadNext();
+};
+
+DDFileUploader.prototype.progressHandler = function(evt) {
+ if (evt.lengthComputable) {
+ var progress = evt.loaded / evt.total;
+ this.updateProgressBar(progress);
+ var currentOpacity = this.previewImg.style.opacity;
+ this.previewImg.style.opacity = Math.max(currentOpacity, progress);
+ }
+};
+
+// Method about queues
+
+DDFileUploader.prototype.previewQueuePush = function(slide) {
+ this.previewQueue.push(slide);
+ if (!this._previewQueueRunning) {
+ this.startPreviewQueue();
+ }
+};
+
+DDFileUploader.prototype.startPreviewQueue = function() {
+ this._previewQueueRunning = true;
+ this.previewQueueLoadNext();
+};
+
+DDFileUploader.prototype.previewQueueLoadNext = function() {
+ if (this.previewQueue.length && this.previewsLoaded < MAX_PREVIEW) {
+ var slide = this.previewQueue.shift();
+ console.info('previewQueueLoadNext', this.previewsLoaded, slide.file.name);
+ this.previewUploadedImage(slide);
+ this.previewsLoaded++;
+ }
+ else {
+ console.warn('previewQueueLoadNext skipped', this.previewsLoaded);
+ this._previewQueueRunning = false;
+ }
+};
+
+DDFileUploader.prototype.uploadQueuePush = function(slide) {
+ this.uploadQueue.push(slide);
+ if (!this._uploadQueueRunning) {
+ this.startUploadQueue();