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