566984a16111fb180041858105bab062175513a7
[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 var posX = Math.min(0, this.filmStartX - delta);
596 this.film.style.left = String(posX) + 'px';
597 };
598
599 FilmSlider.prototype.touchEndHandler = function(evt) {
600 this.touchStartX = undefined;
601 };
602
603
604 FilmSlider.prototype.keyDownHandler = function(evt) {
605 evt = getEventObject(evt);
606 switch (evt.keyCode) {
607 case keyLeft :
608 this.loadSibling(true);
609 break;
610 case keyRight :
611 this.loadSibling(false);
612 break;
613 default:
614 return;
615 }
616 };
617
618
619 FilmSlider.prototype.keyPressHandler = function(evt) {
620 var target = getTargetedObject(evt);
621 if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') { return; }
622 evt = getEventObject(evt);
623 var charPress = String.fromCharCode((evt.keyCode) ? evt.keyCode : evt.which);
624 switch(charPress) {
625 case 'f':
626 case 'F':
627 raiseMouseEvent(this.buttons.full_screen, 'click');
628 break;
629 }
630 };
631
632 FilmSlider.prototype.populateViewer = function(req) {
633 var elements = req.responseXML.documentElement.childNodes;
634 var i;
635 for(i=0 ; i < elements.length ; i++ ) {
636 element = elements[i];
637 switch (element.nodeName) {
638 case 'fragment' :
639 var dest = document.getElementById(element.getAttribute('id'));
640 if (dest) { dest.innerHTML = element.firstChild.nodeValue; }
641 break;
642 case 'imageattributes' :
643 var link = this.buttons.back_to_portfolio.parentNode;
644 link.href = element.getAttribute('back_to_context_url');
645 link = this.buttons.show_buyable.parentNode;
646 var buyable = element.getAttribute('buyable');
647 if(buyable === 'True') { link.className = null; }
648 else if(buyable === 'False') { link.className = 'hidden'; }
649 this.image.alt = element.getAttribute('alt');
650 this.updateBreadcrumbs(element.getAttribute('last_bc_url'),
651 element.getAttribute('img_id'));
652 break;
653 }
654 }
655 };
656
657 FilmSlider.prototype.refreshImage = function() {
658 this.image.style.visibility = 'hidden';
659 this.image.src = this.pendingImage.src;
660 this.image.width = this.pendingImage.width;
661 this.image.height = this.pendingImage.height;
662 this.image.style.visibility = 'visible';
663 if (this.selectedSlideInSelection) { this.image.parentNode.className = 'selected'; }
664 else { this.image.parentNode.className = ''; }
665 };
666
667 FilmSlider.prototype.updateBreadcrumbs = function(url, title) {
668 if (this.hasBreadcrumbs) {
669 this.lastBCElement.href = element.getAttribute('lastBcUrl');
670 this.lastBCElement.innerHTML = element.getAttribute('img_id');
671 }
672 };
673
674 FilmSlider.prototype.startSlideShow = function() {
675 this.slideShowSlide = this.pendingSlideShowSlide = this.selectedSlide;
676 return this.slideShowSlide.href;
677 };
678
679 FilmSlider.prototype.slideShowNext = function() {
680 var nextSlide = this.slideShowSlide.parentNode.nextSibling;
681 if (nextSlide && nextSlide.nodeType===3) { nextSlide = nextSlide.nextSibling; }
682
683 if (nextSlide) {
684 nextSlide = nextSlide.getElementsByTagName('a')[0];
685 this.pendingSlideShowSlide = nextSlide;
686 return this.pendingSlideShowSlide.href;
687 }
688 else {
689 var row = this.slideShowSlide.parentNode.parentNode;
690 var first = row.firstChild;
691 if (first.nodeType===3) { first = first.nextSibling; }
692 this.pendingSlideShowSlide = first.getElementsByTagName('a')[0];
693 return this.pendingSlideShowSlide.href;
694 }
695 };
696
697 FilmSlider.prototype.slideShowPrevious = function() {
698 var previousSlide = this.slideShowSlide.parentNode.previousSibling;
699 if (previousSlide && previousSlide.nodeType===3) { previousSlide = previousSlide.previousSibling; }
700
701 if (previousSlide) {
702 previousSlide = previousSlide.getElementsByTagName('a')[0];
703 this.pendingSlideShowSlide = previousSlide;
704 return this.pendingSlideShowSlide.href;
705 }
706 else {
707 var row = this.slideShowSlide.parentNode.parentNode;
708 var last = row.lastChild;
709 if (last.nodeType===3) { last = last.previousSibling; }
710 this.pendingSlideShowSlide = last.getElementsByTagName('a')[0];
711 return this.pendingSlideShowSlide.href;
712 }
713 };
714
715 FilmSlider.prototype.slideShowImageLoaded = function() {
716 this.slideShowSlide = this.pendingSlideShowSlide;
717 };
718
719 FilmSlider.prototype.stopSlideShow = function() {
720 raiseMouseEvent(this.slideShowSlide, 'click');
721 var index = parseInt(this.selectedSlide.getAttribute('portfolio:position'), 10);
722 this.centerSlide(index);
723 };
724
725
726 /* UTILS */
727 function Point(x, y) {
728 this.x = Math.round(x);
729 this.y = Math.round(y);
730 }
731 Point.prototype.diff = function(point) { return new Point(this.x - point.x, this.y - point.y); };
732 Point.prototype.add = function(point) { return new Point(this.x + point.x, this.y + point.y); };
733 Point.prototype.mul = function(k) { return new Point(this.x * k, this.y *k); };
734 Point.prototype.toString = function() { return "(" + String(this.x) + ", " + String(this.y) + ")"; };
735
736 }());