changeset 20:e4790d4419c1

iphone fix
author mgeorgi
date Fri, 22 Jun 2012 15:39:55 +0100
parents 9b35bf7a6f97
children 92903c908539 9d57fcc848c0
files nodejs-server/app.js
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs-server/app.js	Fri Jun 22 15:14:37 2012 +0100
+++ b/nodejs-server/app.js	Fri Jun 22 15:39:55 2012 +0100
@@ -19,11 +19,21 @@
   ],
  
   init: function() {
+    this.is_touch_device = 'ontouchstart' in document.documentElement;
     this.canvas = document.getElementById('canvas');
     this.label = document.getElementById('label');
     this.draw();
 
-    this.canvas.addEventListener('click', this.onMouseUp.bind(this));
+    if (this.is_touch_device) {
+      this.canvas.addEventListener('touchstart', function(event) {
+        Application.onMouseUp(event.targetTouches[0]);
+      });
+    }
+    else {
+      this.canvas.addEventListener('click', function(event) {
+        Application.onMouseUp(event);
+      });
+    }
   },
 
   tl: { r: 200, g: 0, b: 0 },
@@ -51,14 +61,11 @@
       var right = this.interpolateColor(this.tr, this.br, y / 320);
       for (var x = 0; x < 320; x += step) {
         var color = this.interpolateColor(left, right, x / 320);
-        list.push([x / 320, 1 - y / 320, color.r, color.g, color.b].join(','));
         ctx.fillStyle = "rgb(" + color.r + "," + color.g + "," + color.b + ")";
         ctx.fillRect(x, y, step, step);
       }
     }
 
-    console.log(list.join("\n"));
-
     ctx.beginPath();
     ctx.strokeStyle = "rgb(0,0,0)";
     ctx.moveTo(0, 160);
@@ -104,17 +111,11 @@
  
   request: function(url, callback) {
     var request = new XMLHttpRequest();
-    request.onreadystatechange = function() {
-      if (callback) {
-        callback(request.responseText);
-      }
-    }.bind(this);
     request.open("GET", url);
     request.send(null);
   },
 
   onMouseUp: function(event) {
-    event.preventDefault();
     this.setMarker(event);
     this.sendPosition(event);
     this.draw();