16ffb88231078d54c0944ff02ecf277a710fba80
2 copyright 2008-2014 Benoit Pin - Centre de recherche en informatique - MINES ParisTech
4 Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
11 var keyLeft
= 37, keyRight
= 39;
12 var isTextMime
= /^text\/.+/i;
13 var isAddToSelection
= /.*\/add_to_selection$/;
14 var imgRequestedSize
= /size=(\d+)/;
15 var DEFAULT_IMAGE_SIZES
= [500, 600, 800];
17 FilmSlider = function(filmBar
, slider
, ctxInfos
, image
, toolbar
, breadcrumbs
) {
18 var thisSlider
= this;
20 this.filmBar
= filmBar
;
21 this.filmBarWidth
= getObjectWidth(this.filmBar
);
22 var film
= filmBar
.firstChild
;
23 if (film
.nodeType
=== 3) { film
= film
.nextSibling
; }
26 this.rail
= slider
.parentNode
;
27 this.sliderSpeedRatio
= undefined;
28 this.sliderRatio
= undefined;
29 this.selectedSlide
= undefined;
30 this.selectedSlideInSelection
= undefined;
31 this.cartSlide
= document
.getElementById('cart_slide');
33 this.stretchable
= image
.parentNode
;
34 this.viewMode
= 'medium';
37 this.toolbar
= toolbar
;
39 var bcElements
= breadcrumbs
.getElementsByTagName('a');
40 this.lastBCElement
= bcElements
[bcElements
.length
-1];
41 var imgSrcParts
= image
.src
.split('/');
42 this.lastBCElement
.innerHTML
= imgSrcParts
[imgSrcParts
.length
-2];
43 this.hasBreadcrumbs
= true;
46 this.hasBreadcrumbs
= false;
49 var buttons
= toolbar
.getElementsByTagName('img');
51 for (i
=0 ; i
<buttons
.length
; i
++) {
53 name
= b
.getAttribute('name');
54 if (name
) { this.buttons
[name
] = b
; }
57 this.pendingImage
= new Image();
58 this.pendingImage
.onload = function() {
59 thisSlider
.refreshImage();
61 this.initialized
= false;
63 this.film
.style
.left
='0';
64 this.film
.style
.top
='0';
66 this.filmLength
= ctxInfos
.filmLength
;
67 this.center
= ctxInfos
.center
;
68 this.slideSize
= ctxInfos
.slideSize
;
69 this.ctxUrlTranslation
= ctxInfos
.ctxUrlTranslation
;
71 this.ddHandlers
= {'down' : function(evt
){thisSlider
.mouseDownHandler(evt
);},
72 'move' : function(evt
){thisSlider
.mouseMoveHandler(evt
);},
73 'up' : function(evt
){thisSlider
.mouseUpHandler(evt
);},
74 'out' : function(evt
){thisSlider
.mouseOutHandler(evt
);}
77 if (browser
.isMobile
) {
78 this.rail
.className
= 'hidden';
83 this.addEventListeners();
86 if (!browser
.isMobile
) {
87 FilmSlider
.prototype.resizeSlider = function(evt
) {
88 var filmBarWidth
= this.filmBarWidth
;
89 if (!filmBarWidth
) { return; }
90 var filmWidth
= this.slideSize
* this.filmLength
;
91 var sliderRatio
= this.sliderRatio
= filmBarWidth
/ filmWidth
;
92 var sliderWidth
= filmBarWidth
* sliderRatio
;
93 this.rail
.style
.width
= filmBarWidth
+ 'px';
94 this.rail
.style
.display
= 'block';
95 this.rail
.style
.visibility
= 'visible';
96 if (sliderRatio
< 1) {
97 this.slider
.style
.width
= Math
.round(sliderWidth
) + 'px';
98 this.slider
.style
.visibility
= 'visible';
101 this.slider
.style
.visibility
= 'hidden';
104 this.winSize
= {'width' : getWindowWidth(),
105 'height' : getWindowHeight()};
106 this.maxRightPosition
= filmBarWidth
- sliderWidth
;
107 this.sliderSpeedRatio
= - (filmBarWidth
- sliderWidth
) / (filmWidth
- filmBarWidth
);
108 if (!this.initialized
) {
109 this.centerSlide(this.center
);
110 this.selectedSlide
= this.filmBar
.getElementsByTagName('img')[this.center
].parentNode
;
111 this.initialized
= true;
117 // pas de barre de scroll horizontal pour les tablettes
118 FilmSlider
.prototype.resizeSlider = function(evt
) {
119 this.filmMaxX
= - (getObjectWidth(this.film
) - this.filmBarWidth
);
120 if (!this.initialized
) {
121 this.centerSlide(this.center
);
122 this.selectedSlide
= this.filmBar
.getElementsByTagName('img')[this.center
].parentNode
;
123 this.initialized
= true;
128 FilmSlider
.prototype._checkSizeAfterLoad = function(evt
) {
130 this.filmBarWidth
= this._barSizes
[this._barSizes
.length
] = getObjectWidth(this.filmBar
);
133 this._checkSizeIntervalId
= setInterval(function(evt
){self
._checkSize(evt
);}, 25);
134 setTimeout(function(evt
){self
._checkSizeStability();}, 250);
137 FilmSlider
.prototype._checkSize = function(evt
) {
138 this._barSizes
[this._barSizes
.length
] = getObjectWidth(this.filmBar
);
139 if (this._barSizes
.length
>= 2 &&
140 this._barSizes
[this._barSizes
.length
-2] !== this._barSizes
[this._barSizes
.length
-1]) {
141 this.filmBarWidth
= this._barSizes
[this._barSizes
.length
-1];
142 this.initialized
= false;
147 FilmSlider
.prototype._checkSizeStability = function(evt
) {
150 var checkAgain = function(evt
){self
._checkSizeStability();};
151 for (i
=0 ; i
<this._barSizes
.length
- 1 ; i
++) {
152 if (this._barSizes
[i
] !== this._barSizes
[i
+1]) {
154 setTimeout(checkAgain
, 250);
158 clearInterval(this._checkSizeIntervalId
);
159 delete this._barSizes
;
160 delete this._checkSizeIntervalId
;
163 FilmSlider
.prototype.fitToScreen = function(evt
) {
165 var thisSlider
= this;
166 addListener(window
, 'resize', function(evt
){thisSlider
._fitToScreen();});
169 FilmSlider
.prototype._fitToScreen = function(evt
) {
170 var wh
= getWindowHeight();
172 if (!browser
.isMobile
) {
173 rb
= getObjectTop(this.rail
) + getObjectHeight(this.rail
); // rail bottom
176 rb
= getObjectTop(this.filmBar
) + getObjectHeight(this.filmBar
); // film bottom
179 var sh
= getObjectHeight(this.stretchable
);
180 var newSize
= sh
+ delta
;
181 this.stretchable
.style
.height
= newSize
+ 'px';
183 var ratio
= this.image
.height
/ this.image
.width
;
184 var bestFitSize
= this.getBestFitSize(ratio
);
185 var currentSize
= parseInt(imgRequestedSize
.exec(this.image
.src
)[1], 10);
186 if (currentSize
!== bestFitSize
) {
187 var src
= this.image
.src
.replace(imgRequestedSize
, 'size=' + bestFitSize
);
188 this.pendingImage
.src
= src
;
190 this.shrinkImage(this.image
);
193 FilmSlider
.prototype.getBestFitSize = function(ratio
) {
194 var fw
= getObjectWidth(this.stretchable
) - 1;
195 var fh
= getObjectHeight(this.stretchable
) - 1;
199 for (i
=DEFAULT_IMAGE_SIZES
.length
-1 ; i
>0 ; i
--) {
200 irw
= DEFAULT_IMAGE_SIZES
[i
];
202 if (irw
<= fw
&& irh
<= fh
) { break; }
206 for (i
=DEFAULT_IMAGE_SIZES
.length
-1 ; i
>0 ; i
--) {
207 irh
= DEFAULT_IMAGE_SIZES
[i
];
209 if (irw
<= fw
&& irh
<= fh
) { break; }
212 return DEFAULT_IMAGE_SIZES
[i
];
215 FilmSlider
.prototype.shrinkImage = function(img
) {
216 var dispWidth
= parseInt(this.stretchable
.style
.width
);
217 var imgWidth
= img
.width
;
218 var dispHeight
= parseInt(this.stretchable
.style
.height
);
219 var imgHeight
= img
.height
;
222 if (imgHeight
> dispHeight
) {
223 ratio
= dispHeight
/ imgHeight
;
224 imgWidth
= imgWidth
* ratio
;
225 imgHeight
= dispHeight
;
227 if (imgWidth
> dispWidth
) {
228 ratio
= dispWidth
/ imgWidth
;
229 imgHeight
= imgHeight
* ratio
;
230 imgWidth
= dispWidth
;
232 img
.width
= imgWidth
;
233 img
.height
= imgHeight
;
236 if (!browser
.isMobile
) {
237 FilmSlider
.prototype.centerSlide = function(slideIndex
) {
238 if (this.sliderRatio
> 1) { return; }
239 var filmBarWidth
= getObjectWidth(this.filmBar
);
240 var x
= slideIndex
* this.slideSize
;
241 x
= x
- (filmBarWidth
- this.slideSize
) / 2.0;
242 x
= x
* this.sliderSpeedRatio
;
243 var p
= new Point( -x
, 0 );
244 this.setSliderPosition(p
);
248 FilmSlider
.prototype.centerSlide = function(slideIndex
) {
249 var filmBarWidth
= getObjectWidth(this.filmBar
);
250 var x
= slideIndex
* this.slideSize
;
251 x
= x
- (filmBarWidth
- this.slideSize
) / 2.0;
252 this.setFilmPosition(-x
);
256 FilmSlider
.prototype.setSliderPosition = function(point
) {
257 if(point
.x
< 0) { point
.x
= 0; }
258 if (point
.x
> this.maxRightPosition
) { point
.x
= this.maxRightPosition
; }
259 this.slider
.style
.left
= point
.x
+ 'px';
260 this.setFilmPosition(point
);
263 if (!browser
.isMobile
) {
264 FilmSlider
.prototype.setFilmPosition = function(point
) {
265 this.film
.style
.left
= point
.x
/ this.sliderSpeedRatio
+ 'px';
269 FilmSlider
.prototype.setFilmPosition = function(x
) {
271 x
= Math
.max(this.filmMaxX
, x
);
272 this.film
.style
.left
= String(x
) + 'px';
276 FilmSlider
.prototype.getSliderPosition = function() {
277 var x
= parseInt(this.slider
.style
.left
, 10);
278 var y
= parseInt(this.slider
.style
.top
, 10);
279 var p
= new Point(x
, y
);
283 FilmSlider
.prototype.getFilmPosition = function() {
284 var x
= parseInt(this.film
.style
.left
, 10);
285 var y
= parseInt(this.film
.style
.top
, 10);
286 var p
= new Point(x
, y
);
290 FilmSlider
.prototype.loadSibling = function(previous
) {
293 slide
= this.selectedSlide
.parentNode
.previousSibling
;
294 if (slide
&& slide
.nodeType
===3) { slide
= slide
.previousSibling
; }
297 slide
= this.selectedSlide
.parentNode
.nextSibling
;
298 if (slide
&& slide
.nodeType
===3) { slide
= slide
.nextSibling
; }
301 if (!slide
) { return; }
303 var target
= slide
.getElementsByTagName('a')[0];
304 raiseMouseEvent(target
, 'click');
305 var index
= parseInt(target
.getAttribute('portfolio:position'), 10);
306 this.centerSlide(index
);
310 FilmSlider
.prototype.addEventListeners = function() {
311 var thisSlider
= this;
312 addListener(window
, 'resize', function(evt
){thisSlider
.resizeSlider(evt
);});
313 addListener(this.filmBar
, 'click', function(evt
){thisSlider
.thumbnailClickHandler(evt
);});
314 addListener(this.toolbar
, 'click', function(evt
){thisSlider
.toolbarClickHandler(evt
);});
315 addListener(window
, 'load', function(evt
){thisSlider
.fitToScreen(evt
);});
316 addListener(window
, 'load', function(evt
){thisSlider
._checkSizeAfterLoad(evt
);});
317 addListener(window
, 'load', function(evt
){thisSlider
.startThumbnailsLoadQueue(evt
);});
320 addListener(this.slider
, 'mousedown', this.ddHandlers
.down
);
321 if(browser
.isDOM2Event
){
322 if (browser
.isAppleWebKit
) {
323 this.filmBar
.addEventListener('mousewheel', function(evt
){thisSlider
.mouseWheelHandler(evt
);}, false);
326 addListener(this.filmBar
, 'DOMMouseScroll', function(evt
){thisSlider
.mouseWheelHandler(evt
);});
329 else if (browser
.isIE6up
) {
330 addListener(this.filmBar
, 'mousewheel', function(evt
){thisSlider
.mouseWheelHandler(evt
);});
332 if (browser
.isMobile
) {
333 this.filmBar
.addEventListener('touchstart', function(evt
){thisSlider
.touchStartHandler(evt
);}, false);
334 this.filmBar
.addEventListener('touchmove', function(evt
){thisSlider
.touchMoveHandler(evt
);}, false);
335 this.filmBar
.addEventListener('touchend', function(evt
){thisSlider
.touchEndHandler(evt
);}, false);
338 addListener(document
, 'keydown', function(evt
){thisSlider
.keyDownHandler(evt
);});
339 addListener(document
, 'keypress', function(evt
){thisSlider
.keyPressHandler(evt
);});
343 FilmSlider
.prototype.mouseDownHandler = function(evt
) {
344 this.initialClickPoint
= new Point(evt
.clientX
, evt
.clientY
);
345 this.initialPosition
= this.getSliderPosition();
346 this.dragInProgress
= true;
347 addListener(document
, 'mousemove', this.ddHandlers
.move);
348 addListener(document
, 'mouseup', this.ddHandlers
.up
);
349 addListener(document
.body
, 'mouseout', this.ddHandlers
.out
);
353 FilmSlider
.prototype.mouseMoveHandler = function(evt
) {
354 if(!this.dragInProgress
) { return; }
357 evt
= getEventObject(evt
);
358 var currentPoint
= new Point(evt
.clientX
, evt
.clientY
);
359 var displacement
= currentPoint
.diff(this.initialClickPoint
);
360 this.setSliderPosition(this.initialPosition
.add(displacement
));
363 FilmSlider
.prototype.mouseUpHandler = function(evt
) {
364 this.dragInProgress
= false;
365 evt
= getEventObject(evt
);
366 this.mouseMoveHandler(evt
);
370 FilmSlider
.prototype.mouseOutHandler = function(evt
) {
371 evt
= getEventObject(evt
);
375 x
> this.winSize
.width
||
377 y
> this.winSize
.height
379 this.mouseUpHandler(evt
);
383 FilmSlider
.prototype.translateImgUrl = function(url
) {
385 if (this.ctxUrlTranslation
[0]) {
386 canonicalImgUrl
= url
.replace(this.ctxUrlTranslation
[0],
387 this.ctxUrlTranslation
[1]);
390 canonicalImgUrl
= url
;
392 return canonicalImgUrl
;
395 FilmSlider
.prototype.thumbnailClickHandler = function(evt
) {
396 var target
= getTargetedObject(evt
);
397 while (target
.tagName
!== 'A' && target
!== this.filmBar
) { target
= target
.parentNode
; }
398 if (target
.tagName
!== 'A') { return; }
400 if (this.viewMode
=== 'full') {
401 this.mosaique
.unload();
402 this.mosaique
= null;
403 this.viewMode
= 'medium';
406 disablePropagation(evt
);
408 history
.pushState(target
.href
, '', target
.href
);
410 var imgBaseUrl
= target
.href
;
411 var canonicalImgUrl
= this.translateImgUrl(imgBaseUrl
);
413 var ajaxUrl
= imgBaseUrl
+ '/photo_view_ajax';
416 //this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=600';
417 var thumbnail
= target
.getElementsByTagName('IMG')[0];
418 var bestFitSize
= this.getBestFitSize(thumbnail
.height
/thumbnail
.width
);
419 this.pendingImage
.src
= canonicalImgUrl
+ '/getResizedImage?size=' + bestFitSize
;
422 var fullScreenLink
= this.buttons
.full_screen
.parentNode
;
423 fullScreenLink
.href
= canonicalImgUrl
+ '/zoom_view';
425 var toggleSelectionBtn
= this.buttons
.toggle_selection
;
426 var toggleSelectionLink
= toggleSelectionBtn
.parentNode
;
427 this.selectedSlideInSelection
= (target
.className
==='selected');
428 if (this.selectedSlideInSelection
) {
429 toggleSelectionBtn
.src
= portal_url() + '/unselect_flag_btn.gif';
430 toggleSelectionBtn
.alt
= toggleSelectionLink
.title
= 'Retirer de la sélection';
431 toggleSelectionLink
.href
= canonicalImgUrl
+ '/remove_to_selection';
434 toggleSelectionBtn
.src
= portal_url() + '/select_flag_btn.gif';
435 toggleSelectionBtn
.alt
= toggleSelectionLink
.title
= 'Ajouter à la sélection';
436 toggleSelectionLink
.href
= canonicalImgUrl
+ '/add_to_selection';
439 var showBuyableButtonLink
= this.buttons
.show_buyable
.parentNode
;
440 showBuyableButtonLink
.href
= canonicalImgUrl
+ '/get_slide_buyable_items';
441 this.cartSlide
.innerHTML
= '';
442 this.cartSlide
.style
.visibility
='hidden';
445 var metadataButton
= this.buttons
.edit_metadata
;
446 if (metadataButton
) {
447 var metadataEditLink
= metadataButton
.parentNode
;
448 metadataEditLink
.href
= canonicalImgUrl
+ '/photo_edit_form';
452 var req
= new XMLHttpRequest();
453 req
.onreadystatechange = function() {
454 switch (req
.readyState
) {
460 if (! isTextMime
.exec(req
.getResponseHeader('Content-Type'))) {
461 req
.onreadystatechange
= null;
464 window
.location
.href
= thisFS
._fallBackUrl
;
471 if (req
.status
=== 200) { thisFS
.populateViewer(req
); }
476 req
.open("GET", ajaxUrl
, true);
479 // update old displayed slide className
480 var className
= this.selectedSlide
.className
;
481 var classes
= className
.split(' ');
485 for (i
=0 ; i
<classes
.length
; i
++) {
487 if (name
!== 'displayed') {
488 newClasses
.push(name
);
492 this.selectedSlide
.className
= newClasses
.join(' ');
494 // hightlight new displayed slide
495 this.selectedSlide
= target
;
496 className
= this.selectedSlide
.className
;
497 classes
= className
.split(' ');
498 classes
.push('displayed');
499 this.selectedSlide
.className
= classes
.join(' ');
503 FilmSlider
.prototype.toolbarClickHandler = function(evt
) {
504 var target
= getTargetedObject(evt
);
505 var button
, link
, url
;
506 if(target
.tagName
=== 'IMG' && target
.getAttribute('name')) {
507 switch(target
.getAttribute('name')) {
510 disablePropagation(evt
);
512 link
= button
.parentNode
;
514 this.loadSibling(true);
518 disablePropagation(evt
);
520 link
= button
.parentNode
;
522 this.loadSibling(false);
526 disablePropagation(evt
);
527 target
.parentNode
.blur();
528 if (this.viewMode
=== 'full') {
529 this.mosaique
.unload();
530 this.mosaique
= null;
531 this.viewMode
= 'medium';
534 var main
= document
.getElementById('photo_viewer');
535 url
= target
.parentNode
.href
;
536 url
= url
.substring(0, url
.length
- '/zoom_view'.length
);
537 var margins
= {'top':0, 'right':-1, 'bottom':0, 'left':0};
538 this.mosaique
= new Mosaique(main
, url
, margins
);
539 this.viewMode
= 'full';
542 case 'toggle_selection':
544 disablePropagation(evt
);
546 link
= button
.parentNode
;
549 var req
= new XMLHttpRequest();
551 req
.open("POST", url
, true);
552 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
556 var parts
= url
.split('/');
557 var canonicalImgUrl
= parts
.slice(0, parts
.length
-1).join('/');
559 if (isAddToSelection
.test(url
)) {
560 button
.src
= portal_url() + '/unselect_flag_btn.gif';
561 button
.alt
= link
.title
= 'Retirer de la sélection';
562 link
.href
= canonicalImgUrl
+ '/remove_to_selection';
563 this.selectedSlide
.className
= 'selected displayed';
564 this.image
.parentNode
.className
= 'selected';
565 this.selectedSlideInSelection
= true;
568 button
.src
= portal_url() + '/select_flag_btn.gif';
569 button
.alt
= link
.title
= 'Ajouter à la sélection';
570 link
.href
= canonicalImgUrl
+ '/add_to_selection';
571 this.selectedSlide
.className
= 'displayed';
572 this.image
.parentNode
.className
= '';
573 this.selectedSlideInSelection
= false;
579 disablePropagation(evt
);
581 link
= button
.parentNode
;
583 var slide
= this.cartSlide
;
584 slide
.innerHTML
= '';
585 slide
.style
.visibility
= 'visible';
586 var cw
= new CartWidget(slide
, link
.href
);
587 cw
.onCancel = function() {
588 CartWidget
.prototype.onCancel
.apply(this);
589 slide
.style
.visibility
= 'hidden';
591 cw
.onAfterConfirm = function() {
592 slide
.style
.visibility
= 'hidden';
600 case 'edit_metadata' :
602 disablePropagation(evt);
604 if (this.viewMode === 'full') {
605 this.mosaique.unload();
606 this.mosaique = null;
607 this.viewMode = 'medium';
610 var fi = new FragmentImporter(absolute_url());
611 fi.useMacro('metadata_edit_form_macros', 'iptc', 'image_metadata');
619 if(browser
.isDOM2Event
) {
620 if (browser
.isAppleWebKit
) {
621 FilmSlider
.prototype.mouseWheelHandler = function(evt
) {
623 var pos
= this.getSliderPosition();
624 pos
.x
-= evt
.wheelDelta
/ 40;
625 this.setSliderPosition(pos
);
629 FilmSlider
.prototype.mouseWheelHandler = function(evt
) {
631 var pos
= this.getSliderPosition();
632 pos
.x
+= evt
.detail
* 3;
633 this.setSliderPosition(pos
);
637 else if (browser
.isIE6up
) {
638 FilmSlider
.prototype.mouseWheelHandler = function() {
639 var evt
= window
.event
;
640 evt
.returnValue
= false;
641 var pos
= this.getSliderPosition();
642 pos
.x
-= evt
.wheelDelta
/ 40;
643 this.setSliderPosition(pos
);
647 FilmSlider
.prototype.touchStartHandler = function(evt
) {
648 this.filmStartX
= parseInt(this.film
.style
.left
, 10);
649 this.touchStartX
= evt
.changedTouches
[0].screenX
;
650 this.touchStartTime
= (new Date()).getTime();
653 FilmSlider
.prototype.touchMoveHandler = function(evt
) {
655 var delta
= this.touchStartX
- evt
.changedTouches
[0].screenX
;
656 var posX
= this.filmStartX
- delta
;
657 this.setFilmPosition(posX
);
658 this.lastMoveTime
= (new Date()).getTime();
661 FilmSlider
.prototype.touchEndHandler = function(evt
) {
662 var x
= evt
.changedTouches
[0].screenX
;
663 var delta
= x
- this.touchStartX
;
666 var now
= (new Date()).getTime();
667 if (now
- this.lastMoveTime
< 100) {
668 // au delà de 100 ms de maintient, on annule l'inertie
669 var speed
= delta
/ (now
- this.touchStartTime
);
670 var x0
= parseInt(this.film
.style
.left
, 10);
671 var t0
= (new Date()).getTime();
672 var d
= 500; // milisecondes
677 var animate = function() {
679 var t
= (new Date()).getTime() - t0
;
681 setTimeout(animate
, dt
);
682 delta
= delta
+ (1-t
/d) * speed * dt; // d
écelleration lin
éaire
683 self
.setFilmPosition(x0
+ delta
);
689 this.touchStartX
= undefined;
693 FilmSlider
.prototype.keyDownHandler = function(evt
) {
694 evt
= getEventObject(evt
);
695 switch (evt
.keyCode
) {
697 this.loadSibling(true);
700 this.loadSibling(false);
708 FilmSlider
.prototype.keyPressHandler = function(evt
) {
709 var target
= getTargetedObject(evt
);
710 if (target
.tagName
=== 'INPUT' || target
.tagName
=== 'TEXTAREA') { return; }
711 evt
= getEventObject(evt
);
712 var charPress
= String
.fromCharCode((evt
.keyCode
) ? evt
.keyCode
: evt
.which
);
716 raiseMouseEvent(this.buttons
.full_screen
, 'click');
721 FilmSlider
.prototype.populateViewer = function(req
) {
722 var elements
= req
.responseXML
.documentElement
.childNodes
;
724 for(i
=0 ; i
< elements
.length
; i
++ ) {
725 element
= elements
[i
];
726 switch (element
.nodeName
) {
728 var dest
= document
.getElementById(element
.getAttribute('id'));
729 if (dest
) { dest
.innerHTML
= element
.firstChild
.nodeValue
; }
731 case 'imageattributes' :
732 var link
= this.buttons
.back_to_portfolio
.parentNode
;
733 link
.href
= element
.getAttribute('back_to_context_url');
734 link
= this.buttons
.show_buyable
.parentNode
;
735 var buyable
= element
.getAttribute('buyable');
736 if(buyable
=== 'True') { link
.className
= null; }
737 else if(buyable
=== 'False') { link
.className
= 'hidden'; }
738 this.image
.alt
= element
.getAttribute('alt');
739 this.updateBreadcrumbs(element
.getAttribute('last_bc_url'),
740 element
.getAttribute('img_id'));
746 FilmSlider
.prototype.refreshImage = function() {
747 var dispWidth
= getObjectWidth(this.stretchable
);
748 var imgWidth
= this.pendingImage
.width
;
749 var dispHeight
= getObjectHeight(this.stretchable
);
750 var imgHeight
= this.pendingImage
.height
;
753 if (imgHeight
> dispHeight
) {
754 ratio
= dispHeight
/ imgHeight
;
755 imgWidth
= imgWidth
* ratio
;
756 imgHeight
= dispHeight
;
758 if (imgWidth
> dispWidth
) {
759 ratio
= dispWidth
/ imgWidth
;
760 imgHeight
= imgHeight
* ratio
;
761 imgWidth
= dispWidth
;
764 this.image
.style
.visibility
= 'hidden';
765 this.image
.src
= this.pendingImage
.src
;
766 this.image
.width
= imgWidth
;
767 this.image
.height
= imgHeight
;
768 this.image
.style
.visibility
= 'visible';
769 if (this.selectedSlideInSelection
) { this.image
.parentNode
.className
= 'selected'; }
770 else { this.image
.parentNode
.className
= ''; }
773 FilmSlider
.prototype.updateBreadcrumbs = function(url
, title
) {
774 if (this.hasBreadcrumbs
) {
775 this.lastBCElement
.href
= url
;
776 this.lastBCElement
.innerHTML
= title
;
780 FilmSlider
.prototype.startThumbnailsLoadQueue = function(evt
) {
781 var thumbnails
= this.film
.getElementsByTagName('img');
782 if (thumbnails
.length
=== 1) { return; }
783 this.thumbnailsLoadingOrder
= [];
784 var leftSize
= this.center
;
785 var rightSize
= thumbnails
.length
- this.center
- 1;
787 for (i
=1 ; i
<=Math
.min(leftSize
, rightSize
) ; i
++) {
788 this.thumbnailsLoadingOrder
.push(thumbnails
[this.center
+ i
]);
789 this.thumbnailsLoadingOrder
.push(thumbnails
[this.center
- i
]);
791 if (leftSize
> rightSize
) {
792 for (i
= this.center
- rightSize
- 1 ; i
>= 0 ; i
--) {
793 this.thumbnailsLoadingOrder
.push(thumbnails
[i
]);
796 else if (leftSize
< rightSize
) {
797 for (i
= this.center
+ leftSize
+ 1 ; i
< thumbnails
.length
; i
++) {
798 this.thumbnailsLoadingOrder
.push(thumbnails
[i
]);
801 var next
= this.thumbnailsLoadingOrder
.shift();
803 addListener(next
, 'load', function(evt
){self
._loadNextThumb(evt
);});
804 next
.src
= this.translateImgUrl(next
.parentNode
.href
) + '/getThumbnail';
807 FilmSlider
.prototype._loadNextThumb = function(evt
) {
808 var next
= this.thumbnailsLoadingOrder
.shift();
811 addListener(next
, 'load', function(evt
){self
._loadNextThumb(evt
);});
812 next
.src
= this.translateImgUrl(next
.parentNode
.href
) + '/getThumbnail';
816 FilmSlider
.prototype.startSlideShow = function() {
817 this.slideShowSlide
= this.pendingSlideShowSlide
= this.selectedSlide
;
818 return this.slideShowSlide
.href
;
821 FilmSlider
.prototype.slideShowNext = function() {
822 var nextSlide
= this.slideShowSlide
.parentNode
.nextSibling
;
823 if (nextSlide
&& nextSlide
.nodeType
===3) { nextSlide
= nextSlide
.nextSibling
; }
826 nextSlide
= nextSlide
.getElementsByTagName('a')[0];
827 this.pendingSlideShowSlide
= nextSlide
;
828 return this.pendingSlideShowSlide
.href
;
831 var row
= this.slideShowSlide
.parentNode
.parentNode
;
832 var first
= row
.firstChild
;
833 if (first
.nodeType
===3) { first
= first
.nextSibling
; }
834 this.pendingSlideShowSlide
= first
.getElementsByTagName('a')[0];
835 return this.pendingSlideShowSlide
.href
;
839 FilmSlider
.prototype.slideShowPrevious = function() {
840 var previousSlide
= this.slideShowSlide
.parentNode
.previousSibling
;
841 if (previousSlide
&& previousSlide
.nodeType
===3) { previousSlide
= previousSlide
.previousSibling
; }
844 previousSlide
= previousSlide
.getElementsByTagName('a')[0];
845 this.pendingSlideShowSlide
= previousSlide
;
846 return this.pendingSlideShowSlide
.href
;
849 var row
= this.slideShowSlide
.parentNode
.parentNode
;
850 var last
= row
.lastChild
;
851 if (last
.nodeType
===3) { last
= last
.previousSibling
; }
852 this.pendingSlideShowSlide
= last
.getElementsByTagName('a')[0];
853 return this.pendingSlideShowSlide
.href
;
857 FilmSlider
.prototype.slideShowImageLoaded = function() {
858 this.slideShowSlide
= this.pendingSlideShowSlide
;
861 FilmSlider
.prototype.stopSlideShow = function() {
862 raiseMouseEvent(this.slideShowSlide
, 'click');
863 var index
= parseInt(this.selectedSlide
.getAttribute('portfolio:position'), 10);
864 this.centerSlide(index
);
869 function Point(x
, y
) {
870 this.x
= Math
.round(x
);
871 this.y
= Math
.round(y
);
873 Point
.prototype.diff = function(point
) { return new Point(this.x
- point
.x
, this.y
- point
.y
); };
874 Point
.prototype.add = function(point
) { return new Point(this.x
+ point
.x
, this.y
+ point
.y
); };
875 Point
.prototype.mul = function(k
) { return new Point(this.x
* k
, this.y
*k
); };
876 Point
.prototype.toString = function() { return "(" + String(this.x
) + ", " + String(this.y
) + ")"; };