blob: 6c70643fb2ae3d7db2e3aeb0862470b2922ac112 [file] [log] [blame]
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +01001// *********** HERE STARTS camera.js *************
2
Javier López-Contreras052503f2018-12-26 12:34:42 +01003function cameraGoto(nodeX, nodeY) {
4 sigma.misc.animation.camera( s.camera,
5 { x: nodeX, y: nodeY, ratio: 1 },
6 { duration: s.settings('animationsTime') || 300 }
7 );
8}
9
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010010function is_touch_device() {
avm99963027b5b02018-12-28 02:31:46 +010011 var prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
12 var mq = function(query) {
13 return window.matchMedia(query).matches;
14 }
Javier López-Contreras052503f2018-12-26 12:34:42 +010015
avm99963027b5b02018-12-28 02:31:46 +010016 if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
17 return true;
18 }
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010019
avm99963027b5b02018-12-28 02:31:46 +010020 // include the 'heartz' as a way to have a non matching MQ to help terminate the join
21 // https://git.io/vznFH
22 var query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join('');
23 return mq(query);
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010024}
25
26function initCamera() {
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010027 if(!is_touch_device()) {
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010028 document.querySelector("#zoomin").addEventListener("click", function() {
29 s.camera.goTo({
30 ratio: Math.max(s.camera.settings("zoomMin"), s.camera.ratio / Math.sqrt(2))
31 });
Javier López-Contreras052503f2018-12-26 12:34:42 +010032 });
avm99963027b5b02018-12-28 02:31:46 +010033
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010034 document.querySelector("#zoomout").addEventListener("click", function() {
35 s.camera.goTo({
36 ratio: Math.min(s.camera.settings("zoomMax"), s.camera.ratio * Math.sqrt(2))
37 });
38 });
avm99963027b5b02018-12-28 02:31:46 +010039 } else {
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010040 document.querySelector("#zoomin").style.display = "none";
41 document.querySelector("#zoomout").style.display = "none";
avm99963027b5b02018-12-28 02:31:46 +010042
Javier López-Contreras6d1d72d2018-12-27 23:17:18 +010043 document.querySelector("#circle-mode").style.bottom = "110px";
44 document.querySelector("#settings").style.bottom = "60px";
45 document.querySelector("#search").style.bottom = "10px";
46 }
Javier López-Contreras052503f2018-12-26 12:34:42 +010047}