X-Git-Url: https://scm.cri.mines-paristech.fr/git/Portfolio.git/blobdiff_plain/1a28edcbf9b0c46fbab9bcc9fff0b065349f8f24..66235147e52b54a90a144bbc03627bd1114caf72:/skins/photo_film_viewer.js diff --git a/skins/photo_film_viewer.js b/skins/photo_film_viewer.js index 566984a..f1f650d 100644 --- a/skins/photo_film_viewer.js +++ b/skins/photo_film_viewer.js @@ -114,7 +114,14 @@ if (!browser.isMobile) { else { // pas de barre de scroll horizontal pour les tablettes - FilmSlider.prototype.resizeSlider = function(evt) {}; + FilmSlider.prototype.resizeSlider = function(evt) { + this.filmMaxX = - (getObjectWidth(this.film) - this.filmBarWidth); + if (!this.initialized) { + this.centerSlide(this.center); + this.selectedSlide = this.filmBar.getElementsByTagName('img')[this.center].parentNode; + this.initialized = true; + } + }; } FilmSlider.prototype._checkSizeAfterLoad = function(evt) { @@ -139,10 +146,11 @@ FilmSlider.prototype._checkSize = function(evt) { FilmSlider.prototype._checkSizeStability = function(evt) { var self = this; var i; + var checkAgain = function(evt){self._checkSizeStability();}; for (i=0 ; i 1) { return; } - var filmBarWidth = getObjectWidth(this.filmBar); - var x = slideIndex * this.slideSize; - x = x - (filmBarWidth - this.slideSize) / 2.0; - x = x * this.sliderSpeedRatio; - var p = new Point( -x, 0 ); - this.setSliderPosition(p); -}; +if (!browser.isMobile) { + FilmSlider.prototype.centerSlide = function(slideIndex) { + if (this.sliderRatio > 1) { return; } + var filmBarWidth = getObjectWidth(this.filmBar); + var x = slideIndex * this.slideSize; + x = x - (filmBarWidth - this.slideSize) / 2.0; + x = x * this.sliderSpeedRatio; + var p = new Point( -x, 0 ); + this.setSliderPosition(p); + }; +} +else { + FilmSlider.prototype.centerSlide = function(slideIndex) { + var filmBarWidth = getObjectWidth(this.filmBar); + var x = slideIndex * this.slideSize; + x = x - (filmBarWidth - this.slideSize) / 2.0; + this.setFilmPosition(-x); + }; +} FilmSlider.prototype.setSliderPosition = function(point) { if(point.x < 0) { point.x = 0; } @@ -218,9 +237,18 @@ FilmSlider.prototype.setSliderPosition = function(point) { this.setFilmPosition(point); }; -FilmSlider.prototype.setFilmPosition = function(point) { - this.film.style.left = point.x / this.sliderSpeedRatio + 'px'; -}; +if (!browser.isMobile) { + FilmSlider.prototype.setFilmPosition = function(point) { + this.film.style.left = point.x / this.sliderSpeedRatio + 'px'; + }; +} +else { + FilmSlider.prototype.setFilmPosition = function(x) { + x = Math.min(0, x); + x = Math.max(this.filmMaxX, x); + this.film.style.left = String(x) + 'px'; + }; +} FilmSlider.prototype.getSliderPosition = function() { var x = parseInt(this.slider.style.left, 10); @@ -263,6 +291,7 @@ FilmSlider.prototype.addEventListeners = function() { addListener(this.toolbar, 'click', function(evt){thisSlider.toolbarClickHandler(evt);}); addListener(window, 'load', function(evt){thisSlider.fitToScreen(evt);}); addListener(window, 'load', function(evt){thisSlider._checkSizeAfterLoad(evt);}); + addListener(window, 'load', function(evt){thisSlider.startThumbnailsLoadQueue(evt);}); // dd listeners addListener(this.slider, 'mousedown', this.ddHandlers.down); @@ -328,6 +357,18 @@ FilmSlider.prototype.mouseOutHandler = function(evt) { } }; +FilmSlider.prototype.translateImgUrl = function(url) { + var canonicalImgUrl; + if (this.ctxUrlTranslation[0]) { + canonicalImgUrl = url.replace(this.ctxUrlTranslation[0], + this.ctxUrlTranslation[1]); + } + else { + canonicalImgUrl = url; + } + return canonicalImgUrl; +}; + FilmSlider.prototype.thumbnailClickHandler = function(evt) { var target = getTargetedObject(evt); while (target.tagName !== 'A' && target !== this.filmBar) { target = target.parentNode; } @@ -344,12 +385,7 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { history.pushState(target.href, '', target.href); var imgBaseUrl = target.href; - var canonicalImgUrl; - if (this.ctxUrlTranslation[0]) { - canonicalImgUrl = imgBaseUrl.replace(this.ctxUrlTranslation[0], - this.ctxUrlTranslation[1]); - } - else { canonicalImgUrl = imgBaseUrl; } + var canonicalImgUrl = this.translateImgUrl(imgBaseUrl); var ajaxUrl = imgBaseUrl + '/photo_view_ajax'; var thisFS = this; @@ -587,16 +623,46 @@ else if (browser.isIE6up) { FilmSlider.prototype.touchStartHandler = function(evt) { this.filmStartX = parseInt(this.film.style.left, 10); - this.touchStartX = evt.pageX; + this.touchStartX = evt.changedTouches[0].screenX; + this.touchStartTime = (new Date()).getTime(); }; FilmSlider.prototype.touchMoveHandler = function(evt) { - var delta = this.touchStartX - evt.pageX; - var posX = Math.min(0, this.filmStartX - delta); - this.film.style.left = String(posX) + 'px'; + disableDefault(evt); + var delta = this.touchStartX - evt.changedTouches[0].screenX; + var posX = this.filmStartX - delta; + this.setFilmPosition(posX); + this.lastMoveTime = (new Date()).getTime(); }; FilmSlider.prototype.touchEndHandler = function(evt) { + var x = evt.changedTouches[0].screenX; + 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 + delta = 0; + var dt = 25; + var self = this; + + 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; }; @@ -666,11 +732,48 @@ FilmSlider.prototype.refreshImage = function() { FilmSlider.prototype.updateBreadcrumbs = function(url, title) { if (this.hasBreadcrumbs) { - this.lastBCElement.href = element.getAttribute('lastBcUrl'); - this.lastBCElement.innerHTML = element.getAttribute('img_id'); + this.lastBCElement.href = url; + this.lastBCElement.innerHTML = title; + } +}; + +FilmSlider.prototype.startThumbnailsLoadQueue = function(evt) { + var thumbnails = this.film.getElementsByTagName('img'); + if (thumbnails.length === 1) { return; } + this.thumbnailsLoadingOrder = []; + var leftSize = this.center; + var rightSize = thumbnails.length - this.center - 1; + var i; + for (i=1 ; i<=Math.min(leftSize, rightSize) ; i++) { + this.thumbnailsLoadingOrder.push(thumbnails[this.center + i]); + this.thumbnailsLoadingOrder.push(thumbnails[this.center - 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) { + for (i = this.center + leftSize ; i < thumbnails.length ; i++) { + this.thumbnailsLoadingOrder.push(thumbnails[i]); + } } + var next = this.thumbnailsLoadingOrder.shift(); + var self = this; + addListener(next, 'load', function(evt){self._loadNextThumb(evt);}); + next.src = this.translateImgUrl(next.parentNode.href) + '/getThumbnail'; }; +FilmSlider.prototype._loadNextThumb = function(evt) { + var next = this.thumbnailsLoadingOrder.shift(); + if (!next) {return;} + var self = this; + addListener(next, 'load', function(evt){self._loadNextThumb(evt);}); + next.src = this.translateImgUrl(next.parentNode.href) + '/getThumbnail'; +}; + + FilmSlider.prototype.startSlideShow = function() { this.slideShowSlide = this.pendingSlideShowSlide = this.selectedSlide; return this.slideShowSlide.href;