X-Git-Url: https://svn.cri.ensmp.fr/git/Portfolio.git/blobdiff_plain/e13b7fc85e4757b03dc5395f8bbf3592208a49bc..cd282ee58b2893790d06ce40a8b02c65481abbeb:/skins/photo_film_viewer.js?ds=sidebyside diff --git a/skins/photo_film_viewer.js b/skins/photo_film_viewer.js index ff6d619..3140763 100644 --- a/skins/photo_film_viewer.js +++ b/skins/photo_film_viewer.js @@ -1,12 +1,11 @@ /* -* © 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/ -* -* +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(){ @@ -18,10 +17,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,20 +34,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(); } - - 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; + 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.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'; @@ -305,14 +370,15 @@ 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]) + if (this.ctxUrlTranslation[0]) { canonicalImgUrl = imgBaseUrl.replace(this.ctxUrlTranslation[0], - this.ctxUrlTranslation[1]); - else - canonicalImgUrl = imgBaseUrl; + this.ctxUrlTranslation[1]); + } + else { canonicalImgUrl = imgBaseUrl; } var ajaxUrl = imgBaseUrl + '/photo_view_ajax'; var thisFS = this; @@ -323,12 +389,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'; @@ -340,16 +406,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'; } @@ -372,13 +438,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); @@ -387,18 +449,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--) { + 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 = 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 = next.parentNode.href + '/getThumbnail'; }; + FilmSlider.prototype.startSlideShow = function() { this.slideShowSlide = this.pendingSlideShowSlide = this.selectedSlide; return this.slideShowSlide.href; @@ -626,8 +773,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]; @@ -637,8 +783,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; } @@ -646,8 +791,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]; @@ -657,8 +801,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; } @@ -670,7 +813,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); }; @@ -682,7 +825,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) + ")"; }; -})(); +}());