Introduction d'un système de remise scriptable.
[Portfolio.git] / skins / photo_film_viewer.js
index 884dac0..c6f583b 100644 (file)
@@ -5,7 +5,6 @@ Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
 */
 
 var FilmSlider;
 */
 
 var FilmSlider;
-
 (function(){
 
 var keyLeft = 37, keyRight = 39;
 (function(){
 
 var keyLeft = 37, keyRight = 39;
@@ -146,10 +145,11 @@ FilmSlider.prototype._checkSize = function(evt) {
 FilmSlider.prototype._checkSizeStability = function(evt) {
        var self = this;
        var i;
 FilmSlider.prototype._checkSizeStability = function(evt) {
        var self = this;
        var i;
+       var checkAgain = function(evt){self._checkSizeStability();};
        for (i=0 ; i<this._barSizes.length - 1 ; i++) {
                if (this._barSizes[i] !== this._barSizes[i+1]) {
                        this._barSizes = [];
        for (i=0 ; i<this._barSizes.length - 1 ; i++) {
                if (this._barSizes[i] !== this._barSizes[i+1]) {
                        this._barSizes = [];
-                       setTimeout(function(evt){self._checkSizeStability();}, 250);
+                       setTimeout(checkAgain, 250);
                        return;
                }
        }
                        return;
                }
        }
@@ -166,11 +166,12 @@ FilmSlider.prototype.fitToScreen = function(evt) {
 
 FilmSlider.prototype._fitToScreen = function(evt) {
        var wh = getWindowHeight();
 
 FilmSlider.prototype._fitToScreen = function(evt) {
        var wh = getWindowHeight();
+       var rb;
        if (!browser.isMobile) {
        if (!browser.isMobile) {
-               var rb = getObjectTop(this.rail) + getObjectHeight(this.rail); // rail bottom
+               rb = getObjectTop(this.rail) + getObjectHeight(this.rail); // rail bottom
        }
        else {
        }
        else {
-               var rb = getObjectTop(this.filmBar) + getObjectHeight(this.filmBar); // film bottom
+               rb = getObjectTop(this.filmBar) + getObjectHeight(this.filmBar); // film bottom
        }
        var delta = wh - rb;
        var sh = getObjectHeight(this.stretchable);
        }
        var delta = wh - rb;
        var sh = getObjectHeight(this.stretchable);
@@ -184,6 +185,7 @@ FilmSlider.prototype._fitToScreen = function(evt) {
                var src = this.image.src.replace(imgRequestedSize, 'size=' + bestFitSize);
                this.pendingImage.src = src;
        }
                var src = this.image.src.replace(imgRequestedSize, 'size=' + bestFitSize);
                this.pendingImage.src = src;
        }
+       this.adjustImage(this.image);
 };
 
 FilmSlider.prototype.getBestFitSize = function(ratio) {
 };
 
 FilmSlider.prototype.getBestFitSize = function(ratio) {
@@ -208,6 +210,27 @@ FilmSlider.prototype.getBestFitSize = function(ratio) {
        return DEFAULT_IMAGE_SIZES[i];
 };
 
        return DEFAULT_IMAGE_SIZES[i];
 };
 
+FilmSlider.prototype.adjustImage = function(img) {
+       var dispWidth = parseInt(this.stretchable.style.width);
+       var imgWidth = img.naturalWidth;
+       var dispHeight = parseInt(this.stretchable.style.height);
+       var imgHeight = img.naturalHeight;
+       var ratio;
+
+       if (imgHeight > dispHeight) {
+               ratio = dispHeight / imgHeight;
+               imgWidth = imgWidth * ratio;
+               imgHeight = dispHeight;
+       }
+       if (imgWidth > dispWidth) {
+               ratio = dispWidth / imgWidth;
+               imgHeight = imgHeight * ratio;
+               imgWidth = dispWidth;
+       }
+       img.width = imgWidth;
+       img.height = imgHeight;
+};
+
 if (!browser.isMobile) {
        FilmSlider.prototype.centerSlide = function(slideIndex) {
                if (this.sliderRatio > 1) { return; }
 if (!browser.isMobile) {
        FilmSlider.prototype.centerSlide = function(slideIndex) {
                if (this.sliderRatio > 1) { return; }
@@ -630,36 +653,36 @@ FilmSlider.prototype.touchMoveHandler = function(evt) {
        var delta = this.touchStartX - evt.changedTouches[0].screenX;
        var posX = this.filmStartX - delta;
        this.setFilmPosition(posX);
        var delta = this.touchStartX - evt.changedTouches[0].screenX;
        var posX = this.filmStartX - delta;
        this.setFilmPosition(posX);
-    this.lastMoveTime = (new Date()).getTime();
+       this.lastMoveTime = (new Date()).getTime();
 };
 
 FilmSlider.prototype.touchEndHandler = function(evt) {
 };
 
 FilmSlider.prototype.touchEndHandler = function(evt) {
-    var x = evt.changedTouches[0].screenX;
+       var x = evt.changedTouches[0].screenX;
        var delta = x - this.touchStartX;
        if (delta) {
                disableDefault(evt);
        var delta = x - this.touchStartX;
        if (delta) {
                disableDefault(evt);
-        var now = (new Date()).getTime();
-        if (now - this.lastMoveTime < 100) {
-            // au delà de 100 ms de maintient, on annule l'inertie
-               var speed = delta / (now - this.touchStartTime)
-               var x0 = parseInt(this.film.style.left, 10);
-               var t0 = (new Date()).getTime();
-               var d = 500; // milisecondes
-            var delta = 0;
-            var dt = 25
-               var self = this;
+               var now = (new Date()).getTime();
+               if (now - this.lastMoveTime < 100) {
+                       // au delà de 100 ms de maintient, on annule l'inertie
+                       var speed = delta / (now - this.touchStartTime);
+                       var x0 = parseInt(this.film.style.left, 10);
+                       var t0 = (new Date()).getTime();
+                       var d = 500; // milisecondes
+                       delta = 0;
+                       var dt = 25;
+                       var self = this;
        
        
-               function animate() {
-                // inertie
-                       var t = (new Date()).getTime() - t0;
-                       if (t < d) {
-                               setTimeout(animate, dt);
-                               delta = delta + (1-t/d) * speed * dt; // décelleration linéaire
-                               self.setFilmPosition(x0 + delta);
-                       }
-               }
-               animate();
-        }
+                       var animate = function() {
+                               // inertie
+                               var t = (new Date()).getTime() - t0;
+                               if (t < d) {
+                                       setTimeout(animate, dt);
+                                       delta = delta + (1-t/d) * speed * dt; // décelleration linéaire
+                                       self.setFilmPosition(x0 + delta);
+                               }
+                       };
+                       animate();
+               }
        }
        this.touchStartX = undefined;
 };
        }
        this.touchStartX = undefined;
 };
@@ -719,6 +742,7 @@ FilmSlider.prototype.populateViewer = function(req) {
 };
 
 FilmSlider.prototype.refreshImage = function() {
 };
 
 FilmSlider.prototype.refreshImage = function() {
+       this.adjustImage(this.pendingImage);
        this.image.style.visibility = 'hidden';
        this.image.src = this.pendingImage.src;
        this.image.width = this.pendingImage.width;
        this.image.style.visibility = 'hidden';
        this.image.src = this.pendingImage.src;
        this.image.width = this.pendingImage.width;
@@ -748,12 +772,11 @@ FilmSlider.prototype.startThumbnailsLoadQueue = function(evt) {
        }
        if (leftSize > rightSize) {
                for (i = this.center - rightSize - 1 ; i >= 0 ; i--) {
        }
        if (leftSize > rightSize) {
                for (i = this.center - rightSize - 1 ; i >= 0 ; i--) {
-                       console.log(i);
                        this.thumbnailsLoadingOrder.push(thumbnails[i]);
                }
        }
        else if (leftSize < rightSize) {
                        this.thumbnailsLoadingOrder.push(thumbnails[i]);
                }
        }
        else if (leftSize < rightSize) {
-               for (i = this.center + leftSize ; i < thumbnails.length ; i++) {
+               for (i = this.center + leftSize + 1 ; i < thumbnails.length ; i++) {
                        this.thumbnailsLoadingOrder.push(thumbnails[i]);
                }
        }
                        this.thumbnailsLoadingOrder.push(thumbnails[i]);
                }
        }