X-Git-Url: https://scm.cri.ensmp.fr/git/Portfolio.git/blobdiff_plain/de796b93caf39451cab93560b5978620a21db2f3..dc502e53f9f6081d3c2bc4e9991feffcd60c15e1:/skins/photo_film_viewer.js diff --git a/skins/photo_film_viewer.js b/skins/photo_film_viewer.js index cfd7df5..16ffb88 100644 --- a/skins/photo_film_viewer.js +++ b/skins/photo_film_viewer.js @@ -1,13 +1,11 @@ /* -* © 2008-2014 Benoît Pin – Centre de recherche en informatique – MINES ParisTech -* http://plinn.org -* Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/ -* -* +copyright 2008-2014 Benoit Pin - Centre de recherche en informatique - MINES ParisTech +http://plinn.org +Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/ */ var FilmSlider; - +var s; (function(){ var keyLeft = 37, keyRight = 39; @@ -18,10 +16,11 @@ var DEFAULT_IMAGE_SIZES = [500, 600, 800]; FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) { var thisSlider = this; + s = this; this.filmBar = filmBar; + this.filmBarWidth = getObjectWidth(this.filmBar); var film = filmBar.firstChild; - if (film.nodeType === 3) - film = film.nextSibling; + if (film.nodeType === 3) { film = film.nextSibling; } this.film = film; this.slider = slider; this.rail = slider.parentNode; @@ -34,7 +33,7 @@ FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) { this.stretchable = image.parentNode; this.viewMode = 'medium'; - this.buttons = new Array(); + this.buttons = []; this.toolbar = toolbar; if (breadcrumbs) { var bcElements = breadcrumbs.getElementsByTagName('a'); @@ -48,12 +47,11 @@ FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) { } var buttons = toolbar.getElementsByTagName('img'); - var b, name; - for (var i=0 ; i= 2 && + this._barSizes[this._barSizes.length-2] !== this._barSizes[this._barSizes.length-1]) { + this.filmBarWidth = this._barSizes[this._barSizes.length-1]; + this.initialized = false; + this.resizeSlider(); } - - this.winSize = {'width' : getWindowWidth(), - 'height' : getWindowHeight()}; - this.maxRightPosition = filmBarWidth - sliderWidth - this.sliderSpeedRatio = - (filmBarWidth - sliderWidth) / (filmWidth - filmBarWidth); - if (!this.initialized) { - this.centerSlide(this.center); - this.selectedSlide = this.filmBar.getElementsByTagName('img')[this.center].parentNode; - this.initialized = true; +}; + +FilmSlider.prototype._checkSizeStability = function(evt) { + var self = this; + var i; + var checkAgain = function(evt){self._checkSizeStability();}; + for (i=0 ; i this.winSize['width'] || + x > this.winSize.width || y < 0 || - y > this.winSize['height'] - ){ + y > this.winSize.height + ) { this.mouseUpHandler(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; - if (target.tagName != 'A') - return; + while (target.tagName !== 'A' && target !== this.filmBar) { target = target.parentNode; } + if (target.tagName !== 'A') { return; } else { if (this.viewMode === 'full') { this.mosaique.unload(); @@ -311,15 +405,10 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { disableDefault(evt); disablePropagation(evt); target.blur(); - history.pushState(target.href, '', target.href); + 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; @@ -330,10 +419,10 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=' + bestFitSize; // update buttons - var fullScreenLink = this.buttons['full_screen'].parentNode; + var fullScreenLink = this.buttons.full_screen.parentNode; fullScreenLink.href = canonicalImgUrl + '/zoom_view'; - var toggleSelectionBtn = this.buttons['toggle_selection']; + var toggleSelectionBtn = this.buttons.toggle_selection; var toggleSelectionLink = toggleSelectionBtn.parentNode; this.selectedSlideInSelection = (target.className==='selected'); if (this.selectedSlideInSelection) { @@ -347,16 +436,16 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { toggleSelectionLink.href = canonicalImgUrl + '/add_to_selection'; } - var showBuyableButtonLink = this.buttons['show_buyable'].parentNode; + var showBuyableButtonLink = this.buttons.show_buyable.parentNode; showBuyableButtonLink.href = canonicalImgUrl + '/get_slide_buyable_items'; this.cartSlide.innerHTML = ''; this.cartSlide.style.visibility='hidden'; - var metadataButton = this.buttons['edit_metadata'] + var metadataButton = this.buttons.edit_metadata; if (metadataButton) { var metadataEditLink = metadataButton.parentNode; - metadataEditLink.href = canonicalImgUrl + '/photo_edit_form' + metadataEditLink.href = canonicalImgUrl + '/photo_edit_form'; } @@ -379,13 +468,9 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { break; case 4 : hideProgressImage(); - if (req.status === '200') - thisFS.populateViewer(req); - else - //window.location.href = target.href; - console.error(ajaxUrl); - - }; + if (req.status === 200) { thisFS.populateViewer(req); } + break; + } }; req.open("GET", ajaxUrl, true); @@ -394,18 +479,17 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { // update old displayed slide className var className = this.selectedSlide.className; var classes = className.split(' '); - var newClasses = new Array(); - var name; + var newClasses = []; + var name, i; - for (i in classes) { + for (i=0 ; i dispHeight) { + ratio = dispHeight / imgHeight; + imgWidth = imgWidth * ratio; + imgHeight = dispHeight; + } + if (imgWidth > dispWidth) { + ratio = dispWidth / imgWidth; + imgHeight = imgHeight * ratio; + imgWidth = dispWidth; + } + this.image.style.visibility = 'hidden'; this.image.src = this.pendingImage.src; - this.image.width = this.pendingImage.width; - this.image.height = this.pendingImage.height; + this.image.width = imgWidth; + this.image.height = imgHeight; this.image.style.visibility = 'visible'; - if (this.selectedSlideInSelection) - this.image.parentNode.className = 'selected'; - else - this.image.parentNode.className = ''; + if (this.selectedSlideInSelection) { this.image.parentNode.className = 'selected'; } + else { this.image.parentNode.className = ''; } }; 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--) { + this.thumbnailsLoadingOrder.push(thumbnails[i]); + } + } + else if (leftSize < rightSize) { + for (i = this.center + leftSize + 1 ; 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; @@ -640,8 +820,7 @@ FilmSlider.prototype.startSlideShow = function() { FilmSlider.prototype.slideShowNext = function() { var nextSlide = this.slideShowSlide.parentNode.nextSibling; - if (nextSlide && nextSlide.nodeType===3) - nextSlide = nextSlide.nextSibling; + if (nextSlide && nextSlide.nodeType===3) { nextSlide = nextSlide.nextSibling; } if (nextSlide) { nextSlide = nextSlide.getElementsByTagName('a')[0]; @@ -651,8 +830,7 @@ FilmSlider.prototype.slideShowNext = function() { else { var row = this.slideShowSlide.parentNode.parentNode; var first = row.firstChild; - if (first.nodeType===3) - first = first.nextSibling; + if (first.nodeType===3) { first = first.nextSibling; } this.pendingSlideShowSlide = first.getElementsByTagName('a')[0]; return this.pendingSlideShowSlide.href; } @@ -660,8 +838,7 @@ FilmSlider.prototype.slideShowNext = function() { FilmSlider.prototype.slideShowPrevious = function() { var previousSlide = this.slideShowSlide.parentNode.previousSibling; - if (previousSlide && previousSlide.nodeType===3) - previousSlide = previousSlide.previousSibling; + if (previousSlide && previousSlide.nodeType===3) { previousSlide = previousSlide.previousSibling; } if (previousSlide) { previousSlide = previousSlide.getElementsByTagName('a')[0]; @@ -671,8 +848,7 @@ FilmSlider.prototype.slideShowPrevious = function() { else { var row = this.slideShowSlide.parentNode.parentNode; var last = row.lastChild; - if (last.nodeType===3) - last = last.previousSibling; + if (last.nodeType===3) { last = last.previousSibling; } this.pendingSlideShowSlide = last.getElementsByTagName('a')[0]; return this.pendingSlideShowSlide.href; } @@ -684,7 +860,7 @@ FilmSlider.prototype.slideShowImageLoaded = function() { FilmSlider.prototype.stopSlideShow = function() { raiseMouseEvent(this.slideShowSlide, 'click'); - var index = parseInt(this.selectedSlide.getAttribute('portfolio:position')); + var index = parseInt(this.selectedSlide.getAttribute('portfolio:position'), 10); this.centerSlide(index); }; @@ -696,7 +872,7 @@ function Point(x, y) { } Point.prototype.diff = function(point) { return new Point(this.x - point.x, this.y - point.y); }; Point.prototype.add = function(point) { return new Point(this.x + point.x, this.y + point.y); }; -Point.prototype.mul = function(k) { return new Point(this.x * k, this.y *k)}; +Point.prototype.mul = function(k) { return new Point(this.x * k, this.y *k); }; Point.prototype.toString = function() { return "(" + String(this.x) + ", " + String(this.y) + ")"; }; -})(); +}());