48bdf7f460634dc043e9a76072c5d27d0e03042c
[Portfolio.git] / skins / portfolio_upload.js
1 // © 2013 Benoît Pin MINES ParisTech
2
3 var DDImageUploader;
4 var MAX_PREVIEW = 2; // à virer
5
6 (function(){
7 // nombre maximun d'image chargées en local
8 var MAX_PREVIEW = 2;
9 var isThumbnail = /.*\/getThumbnail$/;
10
11 DDImageUploader = function(dropbox, uploadUrl) {
12 DDFileUploaderBase.apply(this, [dropbox, uploadUrl]);
13
14 this.existingSlides = this.indexExistingSlides();
15 this.slideSize = 222;
16 this.progressBarMaxSize = 200; // pixels
17 this.thumbnailSize = 180;
18 this.previewQueue = [];
19 this._previewQueueRunning = false;
20 this.previewsLoaded = 0;
21 };
22
23 copyPrototype(DDImageUploader, DDFileUploaderBase);
24
25 DDImageUploader.prototype.indexExistingSlides = function() {
26 var images = this.dropbox.getElementsByTagName('img');
27 var i;
28 var index = [];
29 for (i=0 ; i < images.length ; i++) {
30 if (isThumbnail.test(images[i].src)) {
31 index[images[i].src] = images[i]; }
32 }
33 return index;
34 };
35
36 // Methods about upload.
37 DDImageUploader.prototype.handleFiles = function(files) {
38 var file, i, slide;
39 for (i = 0; i < files.length; i++) {
40 file = files[i];
41 slide = this.createSlide(file);
42 this.previewQueuePush(slide);
43 this.uploadQueuePush(slide);
44 }
45 };
46
47
48 // Methods about preview queue.
49 DDImageUploader.prototype.previewQueuePush = function(slide) {
50 this.previewQueue.push(slide);
51 if (!this._previewQueueRunning) {
52 this.startPreviewQueue();
53 }
54 };
55
56 DDImageUploader.prototype.startPreviewQueue = function() {
57 this._previewQueueRunning = true;
58 this.previewQueueLoadNext();
59 };
60
61 DDImageUploader.prototype.previewQueueLoadNext = function() {
62 if (this.previewQueue.length && this.previewsLoaded < MAX_PREVIEW) {
63 var slide = this.previewQueue.shift();
64 this.previewUploadedImage(slide);
65 this.previewsLoaded++;
66 }
67 else {
68 this._previewQueueRunning = false;
69 }
70 };
71
72
73
74 }());