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