|
103 | 103 | y = 30; |
104 | 104 |
|
105 | 105 | var filename = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; |
| 106 | + |
| 107 | + function touchHandler(event) |
| 108 | +{ |
| 109 | + var touches = event.changedTouches, |
| 110 | + first = touches[0], |
| 111 | + type = ""; |
| 112 | + switch(event.type) |
| 113 | + { |
| 114 | + case "touchstart": type = "mousedown"; break; |
| 115 | + case "touchmove": type = "mousemove"; break; |
| 116 | + case "touchend": type = "mouseup"; break; |
| 117 | + default: return; |
| 118 | + } |
| 119 | + |
| 120 | + var simulatedEvent = document.createEvent("MouseEvent"); |
| 121 | + simulatedEvent.initMouseEvent(type, true, true, window, 1, |
| 122 | + first.screenX, first.screenY, |
| 123 | + first.clientX, first.clientY, false, |
| 124 | + false, false, false, 0/*left*/, null); |
| 125 | + |
| 126 | + first.target.dispatchEvent(simulatedEvent); |
| 127 | + event.preventDefault(); |
| 128 | +} |
106 | 129 |
|
107 | 130 | init(); |
108 | 131 |
|
109 | 132 | function init() { |
110 | 133 | canvas = document.getElementById('drawingCanvas'); |
111 | | - document.body.addEventListener("touchstart", function (e) {if(e.target == canvas){e.preventDefault();}}, false); |
112 | | - document.body.addEventListener("touchend", function (e) {if(e.target == canvas){e.preventDefault();}}, false); |
113 | | - document.body.addEventListener("touchmove", function (e) {if(e.target == canvas){e.preventDefault();}}, false); |
| 134 | + document.addEventListener("touchstart", touchHandler, true); |
| 135 | + document.addEventListener("touchmove", touchHandler, true); |
| 136 | + document.addEventListener("touchend", touchHandler, true); |
| 137 | + document.addEventListener("touchcancel", touchHandler, true); |
114 | 138 | ctx = canvas.getContext("2d"); |
115 | 139 | w = canvas.width; |
116 | 140 | h = canvas.height; |
|
0 commit comments