Calcul de la retaille prenant en compte l'absence de barre de scroll horizontal
[Portfolio.git] / skins / photo_film_viewer.js
1 /*
2 copyright 2008-2014 Benoit Pin - Centre de recherche en informatique - MINES ParisTech
3 http://plinn.org
4 Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
5 */
6
7 var FilmSlider;
8
9 (function(){
10
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];
16
17 FilmSlider = function(filmBar, slider, ctxInfos, image, toolbar, breadcrumbs) {
18 var thisSlider = this;
19 this.filmBar = filmBar;
20 this.filmBarWidth = getObjectWidth(this.filmBar);
21 var film = filmBar.firstChild;
22 if (film.nodeType === 3) { film = film.nextSibling; }
23 this.film = film;
24 this.slider = slider;
25 this.rail = slider.parentNode;
26 this.sliderSpeedRatio = undefined;
27 this.sliderRatio = undefined;
28 this.selectedSlide = undefined;
29 this.selectedSlideInSelection = undefined;
30 this.cartSlide = document.getElementById('cart_slide');
31 this.image = image;
32 this.stretchable = image.parentNode;
33 this.viewMode = 'medium';
34
35 this.buttons = [];
36 this.toolbar = toolbar;
37 if (breadcrumbs) {
38 var bcElements = breadcrumbs.getElementsByTagName('a');
39 this.lastBCElement = bcElements[bcElements.length-1];
40 var imgSrcParts = image.src.split('/');
41 this.lastBCElement.innerHTML = imgSrcParts[imgSrcParts.length-2];
42 this.hasBreadcrumbs = true;
43 }
44 else {
45 this.hasBreadcrumbs = false;
46 }
47
48 var buttons = toolbar.getElementsByTagName('img');
49 var b, name, i;
50 for (i=0 ; i<buttons.length ; i++) {
51 b = buttons[i];
52 name = b.getAttribute('name');
53 if (name) { this.buttons[name] = b; }
54 }
55
56 this.pendingImage = new Image();
57 this.pendingImage.onload = function() {
58 thisSlider.refreshImage();
59 };
60 this.initialized = false;
61
62 this.film.style.left='0';
63 this.film.style.top='0';
64
65 this.filmLength = ctxInfos.filmLength;
66 this.center = ctxInfos.center;
67 this.slideSize = ctxInfos.slideSize;
68 this.ctxUrlTranslation = ctxInfos.ctxUrlTranslation;
69
70 this.ddHandlers = {'down' : function(evt){thisSlider.mouseDownHandler(evt);},
71 'move' : function(evt){thisSlider.mouseMoveHandler(evt);},
72 'up' : function(evt){thisSlider.mouseUpHandler(evt);},
73 'out' : function(evt){thisSlider.mouseOutHandler(evt);}
74 };
75
76 if (browser.isMobile) {
77 this.rail.className = 'hidden';
78 }
79 else {
80 this.resizeSlider();
81 }
82 this.addEventListeners();
83 };
84
85 if (!browser.isMobile) {
86 FilmSlider.prototype.resizeSlider = function(evt) {
87 var filmBarWidth = this.filmBarWidth;
88 if (!filmBarWidth) { return; }
89 var filmWidth = this.slideSize * this.filmLength;
90 var sliderRatio = this.sliderRatio = filmBarWidth / filmWidth;
91 var sliderWidth = filmBarWidth * sliderRatio;
92 this.rail.style.width = filmBarWidth + 'px';
93 this.rail.style.display = 'block';
94 this.rail.style.visibility = 'visible';
95 if (sliderRatio < 1) {
96 this.slider.style.width = Math.round(sliderWidth) + 'px';
97 this.slider.style.visibility = 'visible';
98 }
99 else {
100 this.slider.style.visibility = 'hidden';
101 }
102
103 this.winSize = {'width' : getWindowWidth(),
104 'height' : getWindowHeight()};
105 this.maxRightPosition = filmBarWidth - sliderWidth;
106 this.sliderSpeedRatio = - (filmBarWidth - sliderWidth) / (filmWidth - filmBarWidth);
107 if (!this.initialized) {
108 this.centerSlide(this.center);
109 this.selectedSlide = this.filmBar.getElementsByTagName('img')[this.center].parentNode;
110 this.initialized = true;
111 }
112 };
113 }
114
115 else {
116 // pas de barre de scroll horizontal pour les tablettes
117 FilmSlider.prototype.resizeSlider = function(evt) {};
118 }
119
120 FilmSlider.prototype._checkSizeAfterLoad = function(evt) {
121 this._barSizes = [];
122 this.filmBarWidth = this._barSizes[this._barSizes.length] = getObjectWidth(this.filmBar);
123 this.resizeSlider();
124 var self = this;
125 this._checkSizeIntervalId = setInterval(function(evt){self._checkSize(evt);}, 25);
126 setTimeout(function(evt){self._checkSizeStability();}, 250);
127 };
128
129 FilmSlider.prototype._checkSize = function(evt) {
130 this._barSizes[this._barSizes.length] = getObjectWidth(this.filmBar);
131 if (this._barSizes.length >= 2 &&
132 this._barSizes[this._barSizes.length-2] !== this._barSizes[this._barSizes.length-1]) {
133 this.filmBarWidth = this._barSizes[this._barSizes.length-1];
134 this.initialized = false;
135 this.resizeSlider();
136 }
137 };
138
139 FilmSlider.prototype._checkSizeStability = function(evt) {
140 var self = this;
141 var i;
142 for (i=0 ; i<this._barSizes.length - 1 ; i++) {
143 if (this._barSizes[i] !== this._barSizes[i+1]) {
144 this._barSizes = [];
145 setTimeout(function(evt){self._checkSizeStability();}, 250);
146 return;
147 }
148 }
149 clearInterval(this._checkSizeIntervalId);
150 delete this._barSizes;
151 delete this._checkSizeIntervalId;
152 };
153
154 FilmSlider.prototype.fitToScreen = function(evt) {
155 this._fitToScreen();
156 var thisSlider = this;
157 addListener(window, 'resize', function(evt){thisSlider._fitToScreen();});
158 };
159
160 FilmSlider.prototype._fitToScreen = function(evt) {
161 var wh = getWindowHeight();
162 if (!browser.isMobile) {
163 var rb = getObjectTop(this.rail) + getObjectHeight(this.rail); // rail bottom
164 }
165 else {
166 var rb = getObjectTop(this.filmBar) + getObjectHeight(this.filmBar); // film bottom
167 }
168 var delta = wh - rb;
169 var sh = getObjectHeight(this.stretchable);
170 var newSize = sh + delta;
171 this.stretchable.style.height = newSize + 'px';
172
173 var ratio = this.image.height / this.image.width;
174 var bestFitSize = this.getBestFitSize(ratio);
175 var currentSize = parseInt(imgRequestedSize.exec(this.image.src)[1], 10);
176 if (currentSize !== bestFitSize) {
177 var src = this.image.src.replace(imgRequestedSize, 'size=' + bestFitSize);
178 this.pendingImage.src = src;
179 }
180 };
181
182 FilmSlider.prototype.getBestFitSize = function(ratio) {
183 var fw = getObjectWidth(this.stretchable) - 1;
184 var fh = getObjectHeight(this.stretchable) - 1;
185
186 var i, irw, irh;
187 if (ratio < 1) {
188 for (i=DEFAULT_IMAGE_SIZES.length -1 ; i>0 ; i--) {
189 irw = DEFAULT_IMAGE_SIZES[i];
190 irh = irw * ratio;
191 if (irw <= fw && irh <= fh) { break; }
192 }
193 }
194 else {
195 for (i=DEFAULT_IMAGE_SIZES.length -1 ; i>0 ; i--) {
196 irh = DEFAULT_IMAGE_SIZES[i];
197 irw = irh / ratio;
198 if (irw <= fw && irh <= fh) { break; }
199 }
200 }
201 return DEFAULT_IMAGE_SIZES[i];
202 };
203
204 FilmSlider.prototype.centerSlide = function(slideIndex) {
205 if (this.sliderRatio > 1) { return; }
206 var filmBarWidth = getObjectWidth(this.filmBar);
207 var x = slideIndex * this.slideSize;
208 x = x - (filmBarWidth - this.slideSize) / 2.0;
209 x = x * this.sliderSpeedRatio;
210 var p = new Point( -x, 0 );
211 this.setSliderPosition(p);
212 };
213
214 FilmSlider.prototype.setSliderPosition = function(point) {
215 if(point.x < 0) { point.x = 0; }
216 if (point.x > this.maxRightPosition) { point.x = this.maxRightPosition; }
217 this.slider.style.left = point.x + 'px';
218 this.setFilmPosition(point);
219 };
220
221 FilmSlider.prototype.setFilmPosition = function(point) {
222 this.film.style.left = point.x / this.sliderSpeedRatio + 'px';
223 };
224
225 FilmSlider.prototype.getSliderPosition = function() {
226 var x = parseInt(this.slider.style.left, 10);
227 var y = parseInt(this.slider.style.top, 10);
228 var p = new Point(x, y);
229 return p;
230 };
231
232 FilmSlider.prototype.getFilmPosition = function() {
233 var x = parseInt(this.film.style.left, 10);
234 var y = parseInt(this.film.style.top, 10);
235 var p = new Point(x, y);
236 return p;
237 };
238
239 FilmSlider.prototype.loadSibling = function(previous) {
240 var slide = null;
241 if (previous) {
242 slide = this.selectedSlide.parentNode.previousSibling;
243 if (slide && slide.nodeType===3) { slide = slide.previousSibling; }
244 }
245 else {
246 slide = this.selectedSlide.parentNode.nextSibling;
247 if (slide && slide.nodeType===3) { slide = slide.nextSibling; }
248 }
249
250 if (!slide) { return; }
251 else {
252 var target = slide.getElementsByTagName('a')[0];
253 raiseMouseEvent(target, 'click');
254 var index = parseInt(target.getAttribute('portfolio:position'), 10);
255 this.centerSlide(index);
256 }
257 };
258
259 FilmSlider.prototype.addEventListeners = function() {
260 var thisSlider = this;
261 addListener(window, 'resize', function(evt){thisSlider.resizeSlider(evt);});
262 addListener(this.filmBar, 'click', function(evt){thisSlider.thumbnailClickHandler(evt);});
263 addListener(this.toolbar, 'click', function(evt){thisSlider.toolbarClickHandler(evt);});
264 addListener(window, 'load', function(evt){thisSlider.fitToScreen(evt);});
265 addListener(window, 'load', function(evt){thisSlider._checkSizeAfterLoad(evt);});
266
267 // dd listeners
268 addListener(this.slider, 'mousedown', this.ddHandlers.down);
269 if(browser.isDOM2Event){
270 if (browser.isAppleWebKit) {
271 this.filmBar.addEventListener('mousewheel', function(evt){thisSlider.mouseWheelHandler(evt);}, false);
272 }
273 else {
274 addListener(this.filmBar, 'DOMMouseScroll', function(evt){thisSlider.mouseWheelHandler(evt);});
275 }
276 }
277 else if (browser.isIE6up) {
278 addListener(this.filmBar, 'mousewheel', function(evt){thisSlider.mouseWheelHandler(evt);});
279 }
280 if (browser.isMobile) {
281 this.filmBar.addEventListener('touchstart', function(evt){thisSlider.touchStartHandler(evt);}, false);
282 this.filmBar.addEventListener('touchmove', function(evt){thisSlider.touchMoveHandler(evt);}, false);
283 this.filmBar.addEventListener('touchend', function(evt){thisSlider.touchEndHandler(evt);}, false);
284 }
285
286 addListener(document, 'keydown', function(evt){thisSlider.keyDownHandler(evt);});
287 addListener(document, 'keypress', function(evt){thisSlider.keyPressHandler(evt);});
288 };
289
290
291 FilmSlider.prototype.mouseDownHandler = function(evt) {
292 this.initialClickPoint = new Point(evt.clientX, evt.clientY);
293 this.initialPosition = this.getSliderPosition();
294 this.dragInProgress = true;
295 addListener(document, 'mousemove', this.ddHandlers.move);
296 addListener(document, 'mouseup', this.ddHandlers.up);
297 addListener(document.body, 'mouseout', this.ddHandlers.out);
298 };
299
300
301 FilmSlider.prototype.mouseMoveHandler = function(evt) {
302 if(!this.dragInProgress) { return; }
303
304 clearSelection();
305 evt = getEventObject(evt);
306 var currentPoint = new Point(evt.clientX, evt.clientY);
307 var displacement = currentPoint.diff(this.initialClickPoint);
308 this.setSliderPosition(this.initialPosition.add(displacement));
309 };
310
311 FilmSlider.prototype.mouseUpHandler = function(evt) {
312 this.dragInProgress = false;
313 evt = getEventObject(evt);
314 this.mouseMoveHandler(evt);
315 };
316
317
318 FilmSlider.prototype.mouseOutHandler = function(evt) {
319 evt = getEventObject(evt);
320 var x = evt.clientX;
321 var y = evt.clientY;
322 if (x < 0 ||
323 x > this.winSize.width ||
324 y < 0 ||
325 y > this.winSize.height
326 ) {
327 this.mouseUpHandler(evt);
328 }
329 };
330
331 FilmSlider.prototype.thumbnailClickHandler = function(evt) {
332 var target = getTargetedObject(evt);
333 while (target.tagName !== 'A' && target !== this.filmBar) { target = target.parentNode; }
334 if (target.tagName !== 'A') { return; }
335 else {
336 if (this.viewMode === 'full') {
337 this.mosaique.unload();
338 this.mosaique = null;
339 this.viewMode = 'medium';
340 }
341 disableDefault(evt);
342 disablePropagation(evt);
343 target.blur();
344 history.pushState(target.href, '', target.href);
345
346 var imgBaseUrl = target.href;
347 var canonicalImgUrl;
348 if (this.ctxUrlTranslation[0]) {
349 canonicalImgUrl = imgBaseUrl.replace(this.ctxUrlTranslation[0],
350 this.ctxUrlTranslation[1]);
351 }
352 else { canonicalImgUrl = imgBaseUrl; }
353
354 var ajaxUrl = imgBaseUrl + '/photo_view_ajax';
355 var thisFS = this;
356
357 //this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=600';
358 var thumbnail = target.getElementsByTagName('IMG')[0];
359 var bestFitSize = this.getBestFitSize(thumbnail.height/thumbnail.width);
360 this.pendingImage.src = canonicalImgUrl + '/getResizedImage?size=' + bestFitSize;
361
362 // update buttons
363 var fullScreenLink = this.buttons.full_screen.parentNode;
364 fullScreenLink.href = canonicalImgUrl + '/zoom_view';
365
366 var toggleSelectionBtn = this.buttons.toggle_selection;
367 var toggleSelectionLink = toggleSelectionBtn.parentNode;
368 this.selectedSlideInSelection = (target.className==='selected');
369 if (this.selectedSlideInSelection) {
370 toggleSelectionBtn.src = portal_url() + '/unselect_flag_btn.gif';
371 toggleSelectionBtn.alt = toggleSelectionLink.title = 'Retirer de la sélection';
372 toggleSelectionLink.href = canonicalImgUrl + '/remove_to_selection';
373 }
374 else {
375 toggleSelectionBtn.src = portal_url() + '/select_flag_btn.gif';
376 toggleSelectionBtn.alt = toggleSelectionLink.title = 'Ajouter à la sélection';
377 toggleSelectionLink.href = canonicalImgUrl + '/add_to_selection';
378 }
379
380 var showBuyableButtonLink = this.buttons.show_buyable.parentNode;
381 showBuyableButtonLink.href = canonicalImgUrl + '/get_slide_buyable_items';
382 this.cartSlide.innerHTML = '';
383 this.cartSlide.style.visibility='hidden';
384
385
386 var metadataButton = this.buttons.edit_metadata;
387 if (metadataButton) {
388 var metadataEditLink = metadataButton.parentNode;
389 metadataEditLink.href = canonicalImgUrl + '/photo_edit_form';
390 }
391
392
393 var req = new XMLHttpRequest();
394 req.onreadystatechange = function() {
395 switch (req.readyState) {
396 case 1 :
397 showProgressImage();
398 break;
399 case 2 :
400 try {
401 if (! isTextMime.exec(req.getResponseHeader('Content-Type'))) {
402 req.onreadystatechange = null;
403 req.abort();
404 hideProgressImage();
405 window.location.href = thisFS._fallBackUrl;
406 }
407 }
408 catch(e){}
409 break;
410 case 4 :
411 hideProgressImage();
412 if (req.status === 200) { thisFS.populateViewer(req); }
413 break;
414 }
415 };
416
417 req.open("GET", ajaxUrl, true);
418 req.send(null);
419
420 // update old displayed slide className
421 var className = this.selectedSlide.className;
422 var classes = className.split(' ');
423 var newClasses = [];
424 var name, i;
425
426 for (i=0 ; i<classes.length ; i++) {
427 name = classes[i];
428 if (name !== 'displayed') {
429 newClasses.push(name);
430 }
431 }
432
433 this.selectedSlide.className = newClasses.join(' ');
434
435 // hightlight new displayed slide
436 this.selectedSlide = target;
437 className = this.selectedSlide.className;
438 classes = className.split(' ');
439 classes.push('displayed');
440 this.selectedSlide.className = classes.join(' ');
441 }
442 };
443
444 FilmSlider.prototype.toolbarClickHandler = function(evt) {
445 var target = getTargetedObject(evt);
446 var button, link, url;
447 if(target.tagName === 'IMG' && target.getAttribute('name')) {
448 switch(target.getAttribute('name')) {
449 case 'previous' :
450 disableDefault(evt);
451 disablePropagation(evt);
452 button = target;
453 link = button.parentNode;
454 link.blur();
455 this.loadSibling(true);
456 break;
457 case 'next' :
458 disableDefault(evt);
459 disablePropagation(evt);
460 button = target;
461 link = button.parentNode;
462 link.blur();
463 this.loadSibling(false);
464 break;
465 case 'full_screen':
466 disableDefault(evt);
467 disablePropagation(evt);
468 target.parentNode.blur();
469 if (this.viewMode === 'full') {
470 this.mosaique.unload();
471 this.mosaique = null;
472 this.viewMode = 'medium';
473 return;
474 }
475 var main = document.getElementById('photo_viewer');
476 url = target.parentNode.href;
477 url = url.substring(0, url.length - '/zoom_view'.length);
478 var margins = {'top':0, 'right':-1, 'bottom':0, 'left':0};
479 this.mosaique = new Mosaique(main, url, margins);
480 this.viewMode = 'full';
481 break;
482
483 case 'toggle_selection':
484 disableDefault(evt);
485 disablePropagation(evt);
486 button = target;
487 link = button.parentNode;
488 link.blur();
489
490 var req = new XMLHttpRequest();
491 url = link.href;
492 req.open("POST", url, true);
493 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
494 req.send("ajax=1");
495
496 // toggle button
497 var parts = url.split('/');
498 var canonicalImgUrl = parts.slice(0, parts.length-1).join('/');
499
500 if (isAddToSelection.test(url)) {
501 button.src = portal_url() + '/unselect_flag_btn.gif';
502 button.alt = link.title = 'Retirer de la sélection';
503 link.href = canonicalImgUrl + '/remove_to_selection';
504 this.selectedSlide.className = 'selected displayed';
505 this.image.parentNode.className = 'selected';
506 this.selectedSlideInSelection = true;
507 }
508 else {
509 button.src = portal_url() + '/select_flag_btn.gif';
510 button.alt = link.title = 'Ajouter à la sélection';
511 link.href = canonicalImgUrl + '/add_to_selection';
512 this.selectedSlide.className = 'displayed';
513 this.image.parentNode.className = '';
514 this.selectedSlideInSelection = false;
515 }
516 break;
517
518 case 'show_buyable':
519 disableDefault(evt);
520 disablePropagation(evt);
521 button = target;
522 link = button.parentNode;
523 link.blur();
524 var slide = this.cartSlide;
525 slide.innerHTML = '';
526 slide.style.visibility = 'visible';
527 var cw = new CartWidget(slide, link.href);
528 cw.onCancel = function() {
529 CartWidget.prototype.onCancel.apply(this);
530 slide.style.visibility = 'hidden';
531 };
532 cw.onAfterConfirm = function() {
533 slide.style.visibility = 'hidden';
534 };
535 break;
536
537
538
539
540 /*
541 case 'edit_metadata' :
542 disableDefault(evt);
543 disablePropagation(evt);
544 target.blur();
545 if (this.viewMode === 'full') {
546 this.mosaique.unload();
547 this.mosaique = null;
548 this.viewMode = 'medium';
549 return;
550 }
551 var fi = new FragmentImporter(absolute_url());
552 fi.useMacro('metadata_edit_form_macros', 'iptc', 'image_metadata');
553 break;
554 */
555 }
556 }
557 };
558
559
560 if(browser.isDOM2Event) {
561 if (browser.isAppleWebKit) {
562 FilmSlider.prototype.mouseWheelHandler = function(evt) {
563 disableDefault(evt);
564 var pos = this.getSliderPosition();
565 pos.x -= evt.wheelDelta / 40;
566 this.setSliderPosition(pos);
567 };
568 }
569 else {
570 FilmSlider.prototype.mouseWheelHandler = function(evt) {
571 disableDefault(evt);
572 var pos = this.getSliderPosition();
573 pos.x += evt.detail * 3;
574 this.setSliderPosition(pos);
575 };
576 }
577 }
578 else if (browser.isIE6up) {
579 FilmSlider.prototype.mouseWheelHandler = function() {
580 var evt = window.event;
581 evt.returnValue = false;
582 var pos = this.getSliderPosition();
583 pos.x -= evt.wheelDelta / 40;
584 this.setSliderPosition(pos);
585 };
586 }
587
588 FilmSlider.prototype.touchStartHandler = function(evt) {
589 this.filmStartX = parseInt(this.film.style.left, 10);
590 this.touchStartX = evt.pageX;
591 };
592
593 FilmSlider.prototype.touchMoveHandler = function(evt) {
594 var delta = this.touchStartX - evt.pageX;
595 this.film.style.left = String(this.filmStartX - delta) + 'px';
596 };
597
598 FilmSlider.prototype.touchEndHandler = function(evt) {
599 this.touchStartX = undefined;
600 };
601
602
603 FilmSlider.prototype.keyDownHandler = function(evt) {
604 evt = getEventObject(evt);
605 switch (evt.keyCode) {
606 case keyLeft :
607 this.loadSibling(true);
608 break;
609 case keyRight :
610 this.loadSibling(false);
611 break;
612 default:
613 return;
614 }
615 };
616
617
618 FilmSlider.prototype.keyPressHandler = function(evt) {
619 var target = getTargetedObject(evt);
620 if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') { return; }
621 evt = getEventObject(evt);
622 var charPress = String.fromCharCode((evt.keyCode) ? evt.keyCode : evt.which);
623 switch(charPress) {
624 case 'f':
625 case 'F':
626 raiseMouseEvent(this.buttons.full_screen, 'click');
627 break;
628 }
629 };
630
631 FilmSlider.prototype.populateViewer = function(req) {
632 var elements = req.responseXML.documentElement.childNodes;
633 var i;
634 for(i=0 ; i < elements.length ; i++ ) {
635 element = elements[i];
636 switch (element.nodeName) {
637 case 'fragment' :
638 var dest = document.getElementById(element.getAttribute('id'));
639 if (dest) { dest.innerHTML = element.firstChild.nodeValue; }
640 break;
641 case 'imageattributes' :
642 var link = this.buttons.back_to_portfolio.parentNode;
643 link.href = element.getAttribute('back_to_context_url');
644 link = this.buttons.show_buyable.parentNode;
645 var buyable = element.getAttribute('buyable');
646 if(buyable === 'True') { link.className = null; }
647 else if(buyable === 'False') { link.className = 'hidden'; }
648 this.image.alt = element.getAttribute('alt');
649 this.updateBreadcrumbs(element.getAttribute('last_bc_url'),
650 element.getAttribute('img_id'));
651 break;
652 }
653 }
654 };
655
656 FilmSlider.prototype.refreshImage = function() {
657 this.image.style.visibility = 'hidden';
658 this.image.src = this.pendingImage.src;
659 this.image.width = this.pendingImage.width;
660 this.image.height = this.pendingImage.height;
661 this.image.style.visibility = 'visible';
662 if (this.selectedSlideInSelection) { this.image.parentNode.className = 'selected'; }
663 else { this.image.parentNode.className = ''; }
664 };
665
666 FilmSlider.prototype.updateBreadcrumbs = function(url, title) {
667 if (this.hasBreadcrumbs) {
668 this.lastBCElement.href = element.getAttribute('lastBcUrl');
669 this.lastBCElement.innerHTML = element.getAttribute('img_id');
670 }
671 };
672
673 FilmSlider.prototype.startSlideShow = function() {
674 this.slideShowSlide = this.pendingSlideShowSlide = this.selectedSlide;
675 return this.slideShowSlide.href;
676 };
677
678 FilmSlider.prototype.slideShowNext = function() {
679 var nextSlide = this.slideShowSlide.parentNode.nextSibling;
680 if (nextSlide && nextSlide.nodeType===3) { nextSlide = nextSlide.nextSibling; }
681
682 if (nextSlide) {
683 nextSlide = nextSlide.getElementsByTagName('a')[0];
684 this.pendingSlideShowSlide = nextSlide;
685 return this.pendingSlideShowSlide.href;
686 }
687 else {
688 var row = this.slideShowSlide.parentNode.parentNode;
689 var first = row.firstChild;
690 if (first.nodeType===3) { first = first.nextSibling; }
691 this.pendingSlideShowSlide = first.getElementsByTagName('a')[0];
692 return this.pendingSlideShowSlide.href;
693 }
694 };
695
696 FilmSlider.prototype.slideShowPrevious = function() {
697 var previousSlide = this.slideShowSlide.parentNode.previousSibling;
698 if (previousSlide && previousSlide.nodeType===3) { previousSlide = previousSlide.previousSibling; }
699
700 if (previousSlide) {
701 previousSlide = previousSlide.getElementsByTagName('a')[0];
702 this.pendingSlideShowSlide = previousSlide;
703 return this.pendingSlideShowSlide.href;
704 }
705 else {
706 var row = this.slideShowSlide.parentNode.parentNode;
707 var last = row.lastChild;
708 if (last.nodeType===3) { last = last.previousSibling; }
709 this.pendingSlideShowSlide = last.getElementsByTagName('a')[0];
710 return this.pendingSlideShowSlide.href;
711 }
712 };
713
714 FilmSlider.prototype.slideShowImageLoaded = function() {
715 this.slideShowSlide = this.pendingSlideShowSlide;
716 };
717
718 FilmSlider.prototype.stopSlideShow = function() {
719 raiseMouseEvent(this.slideShowSlide, 'click');
720 var index = parseInt(this.selectedSlide.getAttribute('portfolio:position'), 10);
721 this.centerSlide(index);
722 };
723
724
725 /* UTILS */
726 function Point(x, y) {
727 this.x = Math.round(x);
728 this.y = Math.round(y);
729 }
730 Point.prototype.diff = function(point) { return new Point(this.x - point.x, this.y - point.y); };
731 Point.prototype.add = function(point) { return new Point(this.x + point.x, this.y + point.y); };
732 Point.prototype.mul = function(k) { return new Point(this.x * k, this.y *k); };
733 Point.prototype.toString = function() { return "(" + String(this.x) + ", " + String(this.y) + ")"; };
734
735 }());