X-Git-Url: https://scm.cri.minesparis.psl.eu/git/Portfolio.git/blobdiff_plain/2da869b2b46179d64c05eaac4081226fdbbbc9ff..e73353500c67453ef9663d67eaeee7dd46c358ee:/skins/photo_film_viewer.js?ds=sidebyside diff --git a/skins/photo_film_viewer.js b/skins/photo_film_viewer.js deleted file mode 100644 index fa929b2..0000000 --- a/skins/photo_film_viewer.js +++ /dev/null @@ -1,860 +0,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; -(function(){ - -var keyLeft = 37, keyRight = 39; -var isTextMime = /^text\/.+/i; -var isAddToSelection = /.*\/add_to_selection$/; -var imgRequestedSize = /size=(\d+)/; -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; } - this.film = film; - this.slider = slider; - this.rail = slider.parentNode; - this.sliderSpeedRatio = undefined; - this.sliderRatio = undefined; - this.selectedSlide = undefined; - this.selectedSlideInSelection = undefined; - this.cartSlide = document.getElementById('cart_slide'); - this.image = image; - this.stretchable = image.parentNode; - this.viewMode = 'medium'; - - this.buttons = []; - this.toolbar = toolbar; - 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, i; - for (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 || - y < 0 || - 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; } - else { - if (this.viewMode === 'full') { - this.mosaique.unload(); - this.mosaique = null; - this.viewMode = 'medium'; - } - disableDefault(evt); - disablePropagation(evt); - target.blur(); - history.pushState(target.href, '', target.href); - - var imgBaseUrl = target.href; - var canonicalImgUrl = this.translateImgUrl(imgBaseUrl); - - var ajaxUrl = imgBaseUrl + '/photo_view_ajax'; - var thisFS = this; - - //this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=600'; - var thumbnail = target.getElementsByTagName('IMG')[0]; - var bestFitSize = this.getBestFitSize(thumbnail.height/thumbnail.width); - this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=' + bestFitSize; - - // update buttons - var fullScreenLink = this.buttons.full_screen.parentNode; - fullScreenLink.href = canonicalImgUrl + '/zoom_view'; - - var toggleSelectionBtn = this.buttons.toggle_selection; - var toggleSelectionLink = toggleSelectionBtn.parentNode; - 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'; - toggleSelectionLink.href = canonicalImgUrl + '/remove_to_selection'; - } - else { - toggleSelectionBtn.src = portal_url() + '/select_flag_btn.gif'; - toggleSelectionBtn.alt = toggleSelectionLink.title = 'Ajouter à la sélection'; - toggleSelectionLink.href = canonicalImgUrl + '/add_to_selection'; - } - - 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; - if (metadataButton) { - var metadataEditLink = metadataButton.parentNode; - metadataEditLink.href = canonicalImgUrl + '/photo_edit_form'; - } - - - var req = new XMLHttpRequest(); - req.onreadystatechange = function() { - switch (req.readyState) { - case 1 : - showProgressImage(); - break; - case 2 : - try { - if (! isTextMime.exec(req.getResponseHeader('Content-Type'))) { - req.onreadystatechange = null; - req.abort(); - hideProgressImage(); - window.location.href = thisFS._fallBackUrl; - } - } - catch(e){} - break; - case 4 : - hideProgressImage(); - if (req.status === 200) { thisFS.populateViewer(req); } - break; - } - }; - - req.open("GET", ajaxUrl, true); - req.send(null); - - // update old displayed slide className - var className = this.selectedSlide.className; - var classes = className.split(' '); - var newClasses = []; - var name, i; - - 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.pendingSlideShowSlide = this.selectedSlide; - return this.slideShowSlide.href; -}; - -FilmSlider.prototype.slideShowNext = function() { - var nextSlide = this.slideShowSlide.parentNode.nextSibling; - if (nextSlide && nextSlide.nodeType===3) { nextSlide = nextSlide.nextSibling; } - - if (nextSlide) { - nextSlide = nextSlide.getElementsByTagName('a')[0]; - 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.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'), 10); - this.centerSlide(index); -}; - - -/* UTILS */ -function Point(x, y) { - this.x = Math.round(x); - this.y = Math.round(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.toString = function() { return "(" + String(this.x) + ", " + String(this.y) + ")"; }; - -}());