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/
10 var keyLeft
= 37, keyRight
= 39;
11 var isTextMime
= /^text\/.+/i;
12 var isAddToSelection
= /.*\/add_to_selection$/;
13 var imgRequestedSize
= /size=(\d+)/;
14 var DEFAULT_IMAGE_SIZES
= [500, 600, 800];
16 FilmSlider = function(filmBar
, slider
, ctxInfos
, image
, toolbar
, breadcrumbs
) {
17 var thisSlider
= this;
18 this.filmBar
= filmBar
;
19 this.filmBarWidth
= getObjectWidth(this.filmBar
);
20 var film
= filmBar
.firstChild
;
21 if (film
.nodeType
=== 3) { film
= film
.nextSibling
; }
24 this.rail
= slider
.parentNode
;
25 this.sliderSpeedRatio
= undefined;
26 this.sliderRatio
= undefined;
27 this.selectedSlide
= undefined;
28 this.selectedSlideInSelection
= undefined;
29 this.cartSlide
= document
.getElementById('cart_slide');
31 this.stretchable
= image
.parentNode
;
32 this.viewMode
= 'medium';
35 this.toolbar
= toolbar
;
37 var bcElements
= breadcrumbs
.getElementsByTagName('a');
38 this.lastBCElement
= bcElements
[bcElements
.length
-1];
39 var imgSrcParts
= image
.src
.split('/');
40 this.lastBCElement
.innerHTML
= imgSrcParts
[imgSrcParts
.length
-2];
41 this.hasBreadcrumbs
= true;
44 this.hasBreadcrumbs
= false;
47 var buttons
= toolbar
.getElementsByTagName('img');
49 for (i
=0 ; i
<buttons
.length
; i
++) {
51 name
= b
.getAttribute('name');
52 if (name
) { this.buttons
[name
] = b
; }
55 this.pendingImage
= new Image();
56 this.pendingImage
.onload = function() {
57 thisSlider
.refreshImage();
59 this.initialized
= false;
61 this.film
.style
.left
='0';
62 this.film
.style
.top
='0';
64 this.filmLength
= ctxInfos
.filmLength
;
65 this.center
= ctxInfos
.center
;
66 this.slideSize
= ctxInfos
.slideSize
;
67 this.ctxUrlTranslation
= ctxInfos
.ctxUrlTranslation
;
69 this.ddHandlers
= {'down' : function(evt
){thisSlider
.mouseDownHandler(evt
);},
70 'move' : function(evt
){thisSlider
.mouseMoveHandler(evt
);},
71 'up' : function(evt
){thisSlider
.mouseUpHandler(evt
);},
72 'out' : function(evt
){thisSlider
.mouseOutHandler(evt
);}
75 if (browser
.isMobile
) {
76 this.rail
.className
= 'hidden';
81 this.addEventListeners();
84 if (!browser
.isMobile
) {
85 FilmSlider
.prototype.resizeSlider = function(evt
) {
86 var filmBarWidth
= this.filmBarWidth
;
87 if (!filmBarWidth
) { return; }
88 var filmWidth
= this.slideSize
* this.filmLength
;
89 var sliderRatio
= this.sliderRatio
= filmBarWidth
/ filmWidth
;
90 var sliderWidth
= filmBarWidth
* sliderRatio
;
91 this.rail
.style
.width
= filmBarWidth
+ 'px';
92 this.rail
.style
.display
= 'block';
93 this.rail
.style
.visibility
= 'visible';
94 if (sliderRatio
< 1) {
95 this.slider
.style
.width
= Math
.round(sliderWidth
) + 'px';
96 this.slider
.style
.visibility
= 'visible';
99 this.slider
.style
.visibility
= 'hidden';
102 this.winSize
= {'width' : getWindowWidth(),
103 'height' : getWindowHeight()};
104 this.maxRightPosition
= filmBarWidth
- sliderWidth
;
105 this.sliderSpeedRatio
= - (filmBarWidth
- sliderWidth
) / (filmWidth
- filmBarWidth
);
106 if (!this.initialized
) {
107 this.centerSlide(this.center
);
108 this.selectedSlide
= this.filmBar
.getElementsByTagName('img')[this.center
].parentNode
;
109 this.initialized
= true;
115 // pas de barre de scroll horizontal pour les tablettes
116 FilmSlider
.prototype.resizeSlider = function(evt
) {
117 this.filmMaxX
= - (getObjectWidth(this.film
) - this.filmBarWidth
);
118 if (!this.initialized
) {
119 this.centerSlide(this.center
);
120 this.selectedSlide
= this.filmBar
.getElementsByTagName('img')[this.center
].parentNode
;
121 this.initialized
= true;
126 FilmSlider
.prototype._checkSizeAfterLoad = function(evt
) {
128 this.filmBarWidth
= this._barSizes
[this._barSizes
.length
] = getObjectWidth(this.filmBar
);
131 this._checkSizeIntervalId
= setInterval(function(evt
){self
._checkSize(evt
);}, 25);
132 setTimeout(function(evt
){self
._checkSizeStability();}, 250);
135 FilmSlider
.prototype._checkSize = function(evt
) {
136 this._barSizes
[this._barSizes
.length
] = getObjectWidth(this.filmBar
);
137 if (this._barSizes
.length
>= 2 &&
138 this._barSizes
[this._barSizes
.length
-2] !== this._barSizes
[this._barSizes
.length
-1]) {
139 this.filmBarWidth
= this._barSizes
[this._barSizes
.length
-1];
140 this.initialized
= false;
145 FilmSlider
.prototype._checkSizeStability = function(evt
) {
148 var checkAgain = function(evt
){self
._checkSizeStability();};
149 for (i
=0 ; i
<this._barSizes
.length
- 1 ; i
++) {
150 if (this._barSizes
[i
] !== this._barSizes
[i
+1]) {
152 setTimeout(checkAgain
, 250);
156 clearInterval(this._checkSizeIntervalId
);
157 delete this._barSizes
;
158 delete this._checkSizeIntervalId
;
161 FilmSlider
.prototype.fitToScreen = function(evt
) {
163 var thisSlider
= this;
164 addListener(window
, 'resize', function(evt
){thisSlider
._fitToScreen();});
167 FilmSlider
.prototype._fitToScreen = function(evt
) {
168 var wh
= getWindowHeight();
170 if (!browser
.isMobile
) {
171 rb
= getObjectTop(this.rail
) + getObjectHeight(this.rail
); // rail bottom
174 rb
= getObjectTop(this.filmBar
) + getObjectHeight(this.filmBar
); // film bottom
177 var sh
= getObjectHeight(this.stretchable
);
178 var newSize
= sh
+ delta
;
179 this.stretchable
.style
.height
= newSize
+ 'px';
181 var ratio
= this.image
.height
/ this.image
.width
;
182 var bestFitSize
= this.getBestFitSize(ratio
);
183 var currentSize
= parseInt(imgRequestedSize
.exec(this.image
.src
)[1], 10);
184 if (currentSize
!== bestFitSize
) {
185 var src
= this.image
.src
.replace(imgRequestedSize
, 'size=' + bestFitSize
);
186 this.pendingImage
.src
= src
;
188 this.adjustImage(this.image
);
191 FilmSlider
.prototype.getBestFitSize = function(ratio
) {
192 var fw
= getObjectWidth(this.stretchable
) - 1;
193 var fh
= getObjectHeight(this.stretchable
) - 1;
197 for (i
=DEFAULT_IMAGE_SIZES
.length
-1 ; i
>0 ; i
--) {
198 irw
= DEFAULT_IMAGE_SIZES
[i
];
200 if (irw
<= fw
&& irh
<= fh
) { break; }
204 for (i
=DEFAULT_IMAGE_SIZES
.length
-1 ; i
>0 ; i
--) {
205 irh
= DEFAULT_IMAGE_SIZES
[i
];
207 if (irw
<= fw
&& irh
<= fh
) { break; }
210 return DEFAULT_IMAGE_SIZES
[i
];
213 FilmSlider
.prototype.adjustImage = function(img
) {
214 var dispWidth
= parseInt(this.stretchable
.style
.width
, 10);
215 var imgWidth
= img
.naturalWidth
;
216 var dispHeight
= parseInt(this.stretchable
.style
.height
, 10);
217 var imgHeight
= img
.naturalHeight
;
220 if (imgHeight
> dispHeight
) {
221 ratio
= dispHeight
/ imgHeight
;
222 imgWidth
= imgWidth
* ratio
;
223 imgHeight
= dispHeight
;
225 if (imgWidth
> dispWidth
) {
226 ratio
= dispWidth
/ imgWidth
;
227 imgHeight
= imgHeight
* ratio
;
228 imgWidth
= dispWidth
;
230 img
.width
= imgWidth
;
231 img
.height
= imgHeight
;
234 if (!browser
.isMobile
) {
235 FilmSlider
.prototype.centerSlide = function(slideIndex
) {
236 if (this.sliderRatio
> 1) { return; }
237 var filmBarWidth
= getObjectWidth(this.filmBar
);
238 var x
= slideIndex
* this.slideSize
;
239 x
= x
- (filmBarWidth
- this.slideSize
) / 2.0;
240 x
= x
* this.sliderSpeedRatio
;
241 var p
= new Point( -x
, 0 );
242 this.setSliderPosition(p
);
246 FilmSlider
.prototype.centerSlide = function(slideIndex
) {
247 var filmBarWidth
= getObjectWidth(this.filmBar
);
248 var x
= slideIndex
* this.slideSize
;
249 x
= x
- (filmBarWidth
- this.slideSize
) / 2.0;
250 this.setFilmPosition(-x
);
254 FilmSlider
.prototype.setSliderPosition = function(point
) {
255 if(point
.x
< 0) { point
.x
= 0; }
256 if (point
.x
> this.maxRightPosition
) { point
.x
= this.maxRightPosition
; }
257 this.slider
.style
.left
= point
.x
+ 'px';
258 this.setFilmPosition(point
);
261 if (!browser
.isMobile
) {
262 FilmSlider
.prototype.setFilmPosition = function(point
) {
263 this.film
.style
.left
= point
.x
/ this.sliderSpeedRatio
+ 'px';
267 FilmSlider
.prototype.setFilmPosition = function(x
) {
269 x
= Math
.max(this.filmMaxX
, x
);
270 this.film
.style
.left
= String(x
) + 'px';
274 FilmSlider
.prototype.getSliderPosition = function() {
275 var x
= parseInt(this.slider
.style
.left
, 10);
276 var y
= parseInt(this.slider
.style
.top
, 10);
277 var p
= new Point(x
, y
);
281 FilmSlider
.prototype.getFilmPosition = function() {
282 var x
= parseInt(this.film
.style
.left
, 10);
283 var y
= parseInt(this.film
.style
.top
, 10);
284 var p
= new Point(x
, y
);
288 FilmSlider
.prototype.loadSibling = function(previous
) {
291 slide
= this.selectedSlide
.parentNode
.previousSibling
;
292 if (slide
&& slide
.nodeType
===3) { slide
= slide
.previousSibling
; }
295 slide
= this.selectedSlide
.parentNode
.nextSibling
;
296 if (slide
&& slide
.nodeType
===3) { slide
= slide
.nextSibling
; }
299 if (!slide
) { return; }
301 var target
= slide
.getElementsByTagName('a')[0];
302 raiseMouseEvent(target
, 'click');
303 var index
= parseInt(target
.getAttribute('portfolio:position'), 10);
304 this.centerSlide(index
);
308 FilmSlider
.prototype.addEventListeners = function() {
309 var thisSlider
= this;
310 addListener(window
, 'resize', function(evt
){thisSlider
.resizeSlider(evt
);});
311 addListener(this.filmBar
, 'click', function(evt
){thisSlider
.thumbnailClickHandler(evt
);});
312 addListener(this.toolbar
, 'click', function(evt
){thisSlider
.toolbarClickHandler(evt
);});
313 addListener(window
, 'load', function(evt
){thisSlider
.fitToScreen(evt
);});
314 addListener(window
, 'load', function(evt
){thisSlider
._checkSizeAfterLoad(evt
);});
315 addListener(window
, 'load', function(evt
){thisSlider
.startThumbnailsLoadQueue(evt
);});
318 addListener(this.slider
, 'mousedown', this.ddHandlers
.down
);
319 if(browser
.isDOM2Event
){
320 if (browser
.isAppleWebKit
) {
321 this.filmBar
.addEventListener('mousewheel', function(evt
){thisSlider
.mouseWheelHandler(evt
);}, false);
324 addListener(this.filmBar
, 'DOMMouseScroll', function(evt
){thisSlider
.mouseWheelHandler(evt
);});
327 else if (browser
.isIE6up
) {
328 addListener(this.filmBar
, 'mousewheel', function(evt
){thisSlider
.mouseWheelHandler(evt
);});
330 if (browser
.isMobile
) {
331 this.filmBar
.addEventListener('touchstart', function(evt
){thisSlider
.touchStartHandler(evt
);}, false);
332 this.filmBar
.addEventListener('touchmove', function(evt
){thisSlider
.touchMoveHandler(evt
);}, false);
333 this.filmBar
.addEventListener('touchend', function(evt
){thisSlider
.touchEndHandler(evt
);}, false);
336 addListener(document
, 'keydown', function(evt
){thisSlider
.keyDownHandler(evt
);});
337 addListener(document
, 'keypress', function(evt
){thisSlider
.keyPressHandler(evt
);});
341 FilmSlider
.prototype.mouseDownHandler = function(evt
) {
342 this.initialClickPoint
= new Point(evt
.clientX
, evt
.clientY
);
343 this.initialPosition
= this.getSliderPosition();
344 this.dragInProgress
= true;
345 addListener(document
, 'mousemove', this.ddHandlers
.move);
346 addListener(document
, 'mouseup', this.ddHandlers
.up
);
347 addListener(document
.body
, 'mouseout', this.ddHandlers
.out
);
351 FilmSlider
.prototype.mouseMoveHandler = function(evt
) {
352 if(!this.dragInProgress
) { return; }
355 evt
= getEventObject(evt
);
356 var currentPoint
= new Point(evt
.clientX
, evt
.clientY
);
357 var displacement
= currentPoint
.diff(this.initialClickPoint
);
358 this.setSliderPosition(this.initialPosition
.add(displacement
));
361 FilmSlider
.prototype.mouseUpHandler = function(evt
) {
362 this.dragInProgress
= false;
363 evt
= getEventObject(evt
);
364 this.mouseMoveHandler(evt
);
368 FilmSlider
.prototype.mouseOutHandler = function(evt
) {
369 evt
= getEventObject(evt
);
373 x
> this.winSize
.width
||
375 y
> this.winSize
.height
377 this.mouseUpHandler(evt
);
381 FilmSlider
.prototype.translateImgUrl = function(url
) {
383 if (this.ctxUrlTranslation
[0]) {
384 canonicalImgUrl
= url
.replace(this.ctxUrlTranslation
[0],
385 this.ctxUrlTranslation
[1]);
388 canonicalImgUrl
= url
;
390 return canonicalImgUrl
;
393 FilmSlider
.prototype.thumbnailClickHandler = function(evt
) {
394 var target
= getTargetedObject(evt
);
395 while (target
.tagName
!== 'A' && target
!== this.filmBar
) { target
= target
.parentNode
; }
396 if (target
.tagName
!== 'A') { return; }
398 if (this.viewMode
=== 'full') {
399 this.mosaique
.unload();
400 this.mosaique
= null;
401 this.viewMode
= 'medium';
404 disablePropagation(evt
);
406 history
.pushState(target
.href
, '', target
.href
);
408 var imgBaseUrl
= target
.href
;
409 var canonicalImgUrl
= this.translateImgUrl(imgBaseUrl
);
411 var ajaxUrl
= imgBaseUrl
+ '/photo_view_ajax';
414 //this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=600';
415 var thumbnail
= target
.getElementsByTagName('IMG')[0];
416 var bestFitSize
= this.getBestFitSize(thumbnail
.height
/thumbnail
.width
);
417 this.pendingImage
.src
= canonicalImgUrl
+ '/getResizedImage?size=' + bestFitSize
;
420 var fullScreenLink
= this.buttons
.full_screen
.parentNode
;
421 fullScreenLink
.href
= canonicalImgUrl
+ '/zoom_view';
423 var toggleSelectionBtn
= this.buttons
.toggle_selection
;
424 var toggleSelectionLink
= toggleSelectionBtn
.parentNode
;
425 this.selectedSlideInSelection
= (target
.className
==='selected');
426 if (this.selectedSlideInSelection
) {
427 toggleSelectionBtn
.src
= portal_url() + '/unselect_flag_btn.gif';
428 toggleSelectionBtn
.alt
= toggleSelectionLink
.title
= 'Retirer de la sélection';
429 toggleSelectionLink
.href
= canonicalImgUrl
+ '/remove_to_selection';
432 toggleSelectionBtn
.src
= portal_url() + '/select_flag_btn.gif';
433 toggleSelectionBtn
.alt
= toggleSelectionLink
.title
= 'Ajouter à la sélection';
434 toggleSelectionLink
.href
= canonicalImgUrl
+ '/add_to_selection';
437 var showBuyableButtonLink
= this.buttons
.show_buyable
.parentNode
;
438 showBuyableButtonLink
.href
= canonicalImgUrl
+ '/get_slide_buyable_items';
439 this.cartSlide
.innerHTML
= '';
440 this.cartSlide
.style
.visibility
='hidden';
443 var metadataButton
= this.buttons
.edit_metadata
;
444 if (metadataButton
) {
445 var metadataEditLink
= metadataButton
.parentNode
;
446 metadataEditLink
.href
= canonicalImgUrl
+ '/photo_edit_form';
450 var req
= new XMLHttpRequest();
451 req
.onreadystatechange = function() {
452 switch (req
.readyState
) {
458 if (! isTextMime
.exec(req
.getResponseHeader('Content-Type'))) {
459 req
.onreadystatechange
= null;
462 window
.location
.href
= thisFS
._fallBackUrl
;
469 if (req
.status
=== 200) { thisFS
.populateViewer(req
); }
474 req
.open("GET", ajaxUrl
, true);
477 // update old displayed slide className
478 var className
= this.selectedSlide
.className
;
479 var classes
= className
.split(' ');
483 for (i
=0 ; i
<classes
.length
; i
++) {
485 if (name
!== 'displayed') {
486 newClasses
.push(name
);
490 this.selectedSlide
.className
= newClasses
.join(' ');
492 // hightlight new displayed slide
493 this.selectedSlide
= target
;
494 className
= this.selectedSlide
.className
;
495 classes
= className
.split(' ');
496 classes
.push('displayed');
497 this.selectedSlide
.className
= classes
.join(' ');
501 FilmSlider
.prototype.toolbarClickHandler = function(evt
) {
502 var target
= getTargetedObject(evt
);
503 var button
, link
, url
;
504 if(target
.tagName
=== 'IMG' && target
.getAttribute('name')) {
505 switch(target
.getAttribute('name')) {
508 disablePropagation(evt
);
510 link
= button
.parentNode
;
512 this.loadSibling(true);
516 disablePropagation(evt
);
518 link
= button
.parentNode
;
520 this.loadSibling(false);
524 disablePropagation(evt
);
525 target
.parentNode
.blur();
526 if (this.viewMode
=== 'full') {
527 this.mosaique
.unload();
528 this.mosaique
= null;
529 this.viewMode
= 'medium';
532 var main
= document
.getElementById('photo_viewer');
533 url
= target
.parentNode
.href
;
534 url
= url
.substring(0, url
.length
- '/zoom_view'.length
);
535 var margins
= {'top':0, 'right':-1, 'bottom':0, 'left':0};
536 this.mosaique
= new Mosaique(main
, url
, margins
);
537 this.viewMode
= 'full';
540 case 'toggle_selection':
542 disablePropagation(evt
);
544 link
= button
.parentNode
;
547 var req
= new XMLHttpRequest();
549 req
.open("POST", url
, true);
550 req
.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
554 var parts
= url
.split('/');
555 var canonicalImgUrl
= parts
.slice(0, parts
.length
-1).join('/');
557 if (isAddToSelection
.test(url
)) {
558 button
.src
= portal_url() + '/unselect_flag_btn.gif';
559 button
.alt
= link
.title
= 'Retirer de la sélection';
560 link
.href
= canonicalImgUrl
+ '/remove_to_selection';
561 this.selectedSlide
.className
= 'selected displayed';
562 this.image
.parentNode
.className
= 'selected';
563 this.selectedSlideInSelection
= true;
566 button
.src
= portal_url() + '/select_flag_btn.gif';
567 button
.alt
= link
.title
= 'Ajouter à la sélection';
568 link
.href
= canonicalImgUrl
+ '/add_to_selection';
569 this.selectedSlide
.className
= 'displayed';
570 this.image
.parentNode
.className
= '';
571 this.selectedSlideInSelection
= false;
577 disablePropagation(evt
);
579 link
= button
.parentNode
;
581 var slide
= this.cartSlide
;
582 slide
.innerHTML
= '';
583 slide
.style
.visibility
= 'visible';
584 var cw
= new CartWidget(slide
, link
.href
);
585 cw
.onCancel = function() {
586 CartWidget
.prototype.onCancel
.apply(this);
587 slide
.style
.visibility
= 'hidden';
589 cw
.onAfterConfirm = function() {
590 slide
.style
.visibility
= 'hidden';
598 case 'edit_metadata' :
600 disablePropagation(evt);
602 if (this.viewMode === 'full') {
603 this.mosaique.unload();
604 this.mosaique = null;
605 this.viewMode = 'medium';
608 var fi = new FragmentImporter(absolute_url());
609 fi.useMacro('metadata_edit_form_macros', 'iptc', 'image_metadata');
617 if(browser
.isDOM2Event
) {
618 if (browser
.isAppleWebKit
) {
619 FilmSlider
.prototype.mouseWheelHandler = function(evt
) {
621 var pos
= this.getSliderPosition();
622 pos
.x
-= evt
.wheelDelta
/ 40;
623 this.setSliderPosition(pos
);
627 FilmSlider
.prototype.mouseWheelHandler = function(evt
) {
629 var pos
= this.getSliderPosition();
630 pos
.x
+= evt
.detail
* 3;
631 this.setSliderPosition(pos
);
635 else if (browser
.isIE6up
) {
636 FilmSlider
.prototype.mouseWheelHandler = function() {
637 var evt
= window
.event
;
638 evt
.returnValue
= false;
639 var pos
= this.getSliderPosition();
640 pos
.x
-= evt
.wheelDelta
/ 40;
641 this.setSliderPosition(pos
);
645 FilmSlider
.prototype.touchStartHandler = function(evt
) {
646 this.filmStartX
= parseInt(this.film
.style
.left
, 10);
647 this.touchStartX
= evt
.changedTouches
[0].screenX
;
648 this.touchStartTime
= (new Date()).getTime();
651 FilmSlider
.prototype.touchMoveHandler = function(evt
) {
653 var delta
= this.touchStartX
- evt
.changedTouches
[0].screenX
;
654 var posX
= this.filmStartX
- delta
;
655 this.setFilmPosition(posX
);
656 this.lastMoveTime
= (new Date()).getTime();
659 FilmSlider
.prototype.touchEndHandler = function(evt
) {
660 var x
= evt
.changedTouches
[0].screenX
;
661 var delta
= x
- this.touchStartX
;
664 var now
= (new Date()).getTime();
665 if (now
- this.lastMoveTime
< 100) {
666 // au delà de 100 ms de maintient, on annule l'inertie
667 var speed
= delta
/ (now
- this.touchStartTime
);
668 var x0
= parseInt(this.film
.style
.left
, 10);
669 var t0
= (new Date()).getTime();
670 var d
= 500; // milisecondes
675 var animate = function() {
677 var t
= (new Date()).getTime() - t0
;
679 setTimeout(animate
, dt
);
680 delta
= delta
+ (1-t
/d) * speed * dt; // d
écelleration lin
éaire
681 self
.setFilmPosition(x0
+ delta
);
687 this.touchStartX
= undefined;
691 FilmSlider
.prototype.keyDownHandler = function(evt
) {
692 evt
= getEventObject(evt
);
693 switch (evt
.keyCode
) {
695 this.loadSibling(true);
698 this.loadSibling(false);
706 FilmSlider
.prototype.keyPressHandler = function(evt
) {
707 var target
= getTargetedObject(evt
);
708 if (target
.tagName
=== 'INPUT' || target
.tagName
=== 'TEXTAREA') { return; }
709 evt
= getEventObject(evt
);
710 var charPress
= String
.fromCharCode((evt
.keyCode
) ? evt
.keyCode
: evt
.which
);
714 raiseMouseEvent(this.buttons
.full_screen
, 'click');
719 FilmSlider
.prototype.populateViewer = function(req
) {
720 var elements
= req
.responseXML
.documentElement
.childNodes
;
722 for(i
=0 ; i
< elements
.length
; i
++ ) {
723 element
= elements
[i
];
724 switch (element
.nodeName
) {
726 var dest
= document
.getElementById(element
.getAttribute('id'));
727 if (dest
) { dest
.innerHTML
= element
.firstChild
.nodeValue
; }
729 case 'imageattributes' :
730 var link
= this.buttons
.back_to_portfolio
.parentNode
;
731 link
.href
= element
.getAttribute('back_to_context_url');
732 link
= this.buttons
.show_buyable
.parentNode
;
733 var buyable
= element
.getAttribute('buyable');
734 if(buyable
=== 'True') { link
.className
= null; }
735 else if(buyable
=== 'False') { link
.className
= 'hidden'; }
736 this.image
.alt
= element
.getAttribute('alt');
737 this.updateBreadcrumbs(element
.getAttribute('last_bc_url'),
738 element
.getAttribute('img_id'));
744 FilmSlider
.prototype.refreshImage = function() {
745 this.adjustImage(this.pendingImage
);
746 this.image
.style
.visibility
= 'hidden';
747 this.image
.src
= this.pendingImage
.src
;
748 this.image
.width
= this.pendingImage
.width
;
749 this.image
.height
= this.pendingImage
.height
;
750 this.image
.style
.visibility
= 'visible';
751 if (this.selectedSlideInSelection
) { this.image
.parentNode
.className
= 'selected'; }
752 else { this.image
.parentNode
.className
= ''; }
755 FilmSlider
.prototype.updateBreadcrumbs = function(url
, title
) {
756 if (this.hasBreadcrumbs
) {
757 this.lastBCElement
.href
= url
;
758 this.lastBCElement
.innerHTML
= title
;
762 FilmSlider
.prototype.startThumbnailsLoadQueue = function(evt
) {
763 var thumbnails
= this.film
.getElementsByTagName('img');
764 if (thumbnails
.length
=== 1) { return; }
765 this.thumbnailsLoadingOrder
= [];
766 var leftSize
= this.center
;
767 var rightSize
= thumbnails
.length
- this.center
- 1;
769 for (i
=1 ; i
<=Math
.min(leftSize
, rightSize
) ; i
++) {
770 this.thumbnailsLoadingOrder
.push(thumbnails
[this.center
+ i
]);
771 this.thumbnailsLoadingOrder
.push(thumbnails
[this.center
- i
]);
773 if (leftSize
> rightSize
) {
774 for (i
= this.center
- rightSize
- 1 ; i
>= 0 ; i
--) {
775 this.thumbnailsLoadingOrder
.push(thumbnails
[i
]);
778 else if (leftSize
< rightSize
) {
779 for (i
= this.center
+ leftSize
+ 1 ; i
< thumbnails
.length
; i
++) {
780 this.thumbnailsLoadingOrder
.push(thumbnails
[i
]);
783 var next
= this.thumbnailsLoadingOrder
.shift();
785 addListener(next
, 'load', function(evt
){self
._loadNextThumb(evt
);});
786 next
.src
= this.translateImgUrl(next
.parentNode
.href
) + '/getThumbnail';
789 FilmSlider
.prototype._loadNextThumb = function(evt
) {
790 var next
= this.thumbnailsLoadingOrder
.shift();
793 addListener(next
, 'load', function(evt
){self
._loadNextThumb(evt
);});
794 next
.src
= this.translateImgUrl(next
.parentNode
.href
) + '/getThumbnail';
798 FilmSlider
.prototype.startSlideShow = function() {
799 this.slideShowSlide
= this.pendingSlideShowSlide
= this.selectedSlide
;
800 return this.slideShowSlide
.href
;
803 FilmSlider
.prototype.slideShowNext = function() {
804 var nextSlide
= this.slideShowSlide
.parentNode
.nextSibling
;
805 if (nextSlide
&& nextSlide
.nodeType
===3) { nextSlide
= nextSlide
.nextSibling
; }
808 nextSlide
= nextSlide
.getElementsByTagName('a')[0];
809 this.pendingSlideShowSlide
= nextSlide
;
810 return this.pendingSlideShowSlide
.href
;
813 var row
= this.slideShowSlide
.parentNode
.parentNode
;
814 var first
= row
.firstChild
;
815 if (first
.nodeType
===3) { first
= first
.nextSibling
; }
816 this.pendingSlideShowSlide
= first
.getElementsByTagName('a')[0];
817 return this.pendingSlideShowSlide
.href
;
821 FilmSlider
.prototype.slideShowPrevious = function() {
822 var previousSlide
= this.slideShowSlide
.parentNode
.previousSibling
;
823 if (previousSlide
&& previousSlide
.nodeType
===3) { previousSlide
= previousSlide
.previousSibling
; }
826 previousSlide
= previousSlide
.getElementsByTagName('a')[0];
827 this.pendingSlideShowSlide
= previousSlide
;
828 return this.pendingSlideShowSlide
.href
;
831 var row
= this.slideShowSlide
.parentNode
.parentNode
;
832 var last
= row
.lastChild
;
833 if (last
.nodeType
===3) { last
= last
.previousSibling
; }
834 this.pendingSlideShowSlide
= last
.getElementsByTagName('a')[0];
835 return this.pendingSlideShowSlide
.href
;
839 FilmSlider
.prototype.slideShowImageLoaded = function() {
840 this.slideShowSlide
= this.pendingSlideShowSlide
;
843 FilmSlider
.prototype.stopSlideShow = function() {
844 raiseMouseEvent(this.slideShowSlide
, 'click');
845 var index
= parseInt(this.selectedSlide
.getAttribute('portfolio:position'), 10);
846 this.centerSlide(index
);
851 function Point(x
, y
) {
852 this.x
= Math
.round(x
);
853 this.y
= Math
.round(y
);
855 Point
.prototype.diff = function(point
) { return new Point(this.x
- point
.x
, this.y
- point
.y
); };
856 Point
.prototype.add = function(point
) { return new Point(this.x
+ point
.x
, this.y
+ point
.y
); };
857 Point
.prototype.mul = function(k
) { return new Point(this.x
* k
, this.y
*k
); };
858 Point
.prototype.toString = function() { return "(" + String(this.x
) + ", " + String(this.y
) + ")"; };