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