X-Git-Url: https://scm.cri.mines-paristech.fr/git/Portfolio.git/blobdiff_plain/011a53d5681ad1f5fa88a534ec041c93d3e7be95..6abfa75e909be774c2e52e3442c08507f64c1419:/skins/photo_film_viewer.js?ds=sidebyside diff --git a/skins/photo_film_viewer.js b/skins/photo_film_viewer.js index cf55fd9..c6f583b 100644 --- a/skins/photo_film_viewer.js +++ b/skins/photo_film_viewer.js @@ -1,13 +1,10 @@ /* -* © 2008 Benoît Pin – Centre de recherche en informatique – École des mines de Paris -* http://plinn.org -* Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/ -* $Id: photo_film_viewer.js 1303 2009-08-21 22:19:05Z pin $ -* $URL: http://svn.luxia.fr/svn/labo/projects/zope/Portfolio/trunk/skins/photo_film_viewer.js $ +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; - (function(){ var keyLeft = 37, keyRight = 39; @@ -19,9 +16,9 @@ var DEFAULT_IMAGE_SIZES = [500, 600, 800]; FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) { var thisSlider = 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,20 +31,25 @@ FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) { this.stretchable = image.parentNode; this.viewMode = 'medium'; - this.buttons = new Array(); + this.buttons = []; this.toolbar = toolbar; - var bcElements = breadcrumbs.getElementsByTagName('a'); - this.lastBCElement = bcElements[bcElements.length-1]; - var imgSrcParts = image.src.split('/'); - this.lastBCElement.innerHTML = imgSrcParts[imgSrcParts.length-2]; + if (breadcrumbs) { + var bcElements = breadcrumbs.getElementsByTagName('a'); + this.lastBCElement = bcElements[bcElements.length-1]; + var imgSrcParts = image.src.split('/'); + this.lastBCElement.innerHTML = imgSrcParts[imgSrcParts.length-2]; + this.hasBreadcrumbs = true; + } + else { + this.hasBreadcrumbs = false; + } 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(); + } +}; + +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') { + if (this.viewMode === 'full') { this.mosaique.unload(); this.mosaique = null; this.viewMode = 'medium'; @@ -304,14 +403,10 @@ FilmSlider.prototype.thumbnailClickHandler = function(evt) { disableDefault(evt); disablePropagation(evt); target.blur(); + 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; @@ -322,12 +417,12 @@ 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'); + this.selectedSlideInSelection = (target.className==='selected'); if (this.selectedSlideInSelection) { toggleSelectionBtn.src = portal_url() + '/unselect_flag_btn.gif'; toggleSelectionBtn.alt = toggleSelectionLink.title = 'Retirer de la sélection'; @@ -339,16 +434,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'; } @@ -371,13 +466,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); @@ -386,18 +477,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 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.selectedSlide; - this.nextSlideShowSlide = this.selectedSlide; + this.slideShowSlide = this.pendingSlideShowSlide = this.selectedSlide; return this.slideShowSlide.href; }; FilmSlider.prototype.slideShowNext = function() { - this.slideShowSlide = this.nextSlideShowSlide; 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]; - this.nextSlideShowSlide = nextSlide; - return nextSlide.href; + this.pendingSlideShowSlide = nextSlide; + return this.pendingSlideShowSlide.href; } else { var row = this.slideShowSlide.parentNode.parentNode; var first = row.firstChild; - if (first.nodeType==3) - first = first.nextSibling; - this.nextSlideShowSlide = first.getElementsByTagName('a')[0]; - return this.nextSlideShowSlide.href; + if (first.nodeType===3) { first = first.nextSibling; } + this.pendingSlideShowSlide = first.getElementsByTagName('a')[0]; + return this.pendingSlideShowSlide.href; + } +}; + +FilmSlider.prototype.slideShowPrevious = function() { + var previousSlide = this.slideShowSlide.parentNode.previousSibling; + if (previousSlide && previousSlide.nodeType===3) { previousSlide = previousSlide.previousSibling; } + + if (previousSlide) { + previousSlide = previousSlide.getElementsByTagName('a')[0]; + this.pendingSlideShowSlide = previousSlide; + return this.pendingSlideShowSlide.href; + } + else { + var row = this.slideShowSlide.parentNode.parentNode; + var last = row.lastChild; + if (last.nodeType===3) { last = last.previousSibling; } + this.pendingSlideShowSlide = last.getElementsByTagName('a')[0]; + return this.pendingSlideShowSlide.href; } }; +FilmSlider.prototype.slideShowImageLoaded = function() { + this.slideShowSlide = this.pendingSlideShowSlide; +}; + 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); }; @@ -660,7 +854,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) + ")"; }; -})(); +}());