Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Touch events are a thing.

  • Loading branch information...
commit 69ecdd667e20d6bd52ec1c0e324345b726c1b8b6 1 parent 9a2ba79
@pipt authored
Showing with 16 additions and 7 deletions.
  1. +16 −7 public/scribble.js
View
23 public/scribble.js
@@ -14,12 +14,15 @@ window.onload = function() {
Scribble.paper = Raphael('frame', 640, 480);
var rectangle = Scribble.paper.rect(0, 0, 640, 480);
rectangle.attr({fill: "#fff", stroke: "none"});
- $("svg").mousemove(Scribble.mousemove);
+ $("#frame svg").mousemove(Scribble.mousemove);
+ $("#frame svg").bind('touchmove', Scribble.mousemove);
if (window.Drawing) {
Scribble.replay();
}
$(document).mousedown(Scribble.startDraw);
$(document).mouseup(Scribble.stopDraw);
+ $(document).bind('touchstart', Scribble.startDraw);
+ $(document).bind('touchend', Scribble.stopDraw);
},
size: function(s) {
@@ -33,8 +36,14 @@ window.onload = function() {
},
mousemove: function(event) {
- var x = event.clientX - $('#frame').offset().left;
- var y = event.clientY - $('#frame').offset().top;
+ var targetEvent = null;
+ if (event.originalEvent.touches !== undefined) {
+ targetEvent = event.originalEvent.touches[0];
+ } else {
+ targetEvent = event;
+ }
+ var x = targetEvent.clientX - $('#frame').offset().left;
+ var y = targetEvent.clientY - $('#frame').offset().top;
if (Scribble.mouseDown && window.Drawing === undefined) {
if (Scribble.lastX != null) {
Scribble.draw(Scribble.lastX, Scribble.lastY, x, y);
@@ -43,6 +52,8 @@ window.onload = function() {
Scribble.lastX = x;
Scribble.lastY = y;
}
+ event.preventDefault();
+ return false;
},
draw: function(fromX, fromY, toX, toY) {
@@ -67,19 +78,17 @@ window.onload = function() {
},
startDraw: function(event) {
- if (event.button == 0) {
+ if (event.button == 0 || event.originalEvent.touches) {
Scribble.mouseDown = true;
}
- false;
},
stopDraw: function(event) {
- if (event.button == 0) {
+ if (event.button == 0 || event.originalEvent.touches) {
Scribble.mouseDown = false;
Scribble.lastX = null;
Scribble.lastY = null;
}
- false;
}
}
})();
Please sign in to comment.
Something went wrong with that request. Please try again.