48bdf7f460634dc043e9a76072c5d27d0e03042c
1 // © 2013 Benoît Pin MINES ParisTech
4 var MAX_PREVIEW
= 2; // à virer
7 // nombre maximun d'image chargées en local
9 var isThumbnail
= /.*\/getThumbnail$/;
11 DDImageUploader = function(dropbox
, uploadUrl
) {
12 DDFileUploaderBase
.apply(this, [dropbox
, uploadUrl
]);
14 this.existingSlides
= this.indexExistingSlides();
16 this.progressBarMaxSize
= 200; // pixels
17 this.thumbnailSize
= 180;
18 this.previewQueue
= [];
19 this._previewQueueRunning
= false;
20 this.previewsLoaded
= 0;
23 copyPrototype(DDImageUploader
, DDFileUploaderBase
);
25 DDImageUploader
.prototype.indexExistingSlides = function() {
26 var images
= this.dropbox
.getElementsByTagName('img');
29 for (i
=0 ; i
< images
.length
; i
++) {
30 if (isThumbnail
.test(images
[i
].src
)) {
31 index
[images
[i
].src
] = images
[i
]; }
36 // Methods about upload.
37 DDImageUploader
.prototype.handleFiles = function(files
) {
39 for (i
= 0; i
< files
.length
; i
++) {
41 slide
= this.createSlide(file
);
42 this.previewQueuePush(slide
);
43 this.uploadQueuePush(slide
);
48 // Methods about preview queue.
49 DDImageUploader
.prototype.previewQueuePush = function(slide
) {
50 this.previewQueue
.push(slide
);
51 if (!this._previewQueueRunning
) {
52 this.startPreviewQueue();
56 DDImageUploader
.prototype.startPreviewQueue = function() {
57 this._previewQueueRunning
= true;
58 this.previewQueueLoadNext();
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
++;
68 this._previewQueueRunning
= false;