First off, great work! I'm enjoying this a lot.
I noticed that dragging blocks didn't work on the iPad. Wiring up some touch
events seems to fix it, more or less (there's some flakiness when the blocks
get near the bottom of the screen which *may* be related to scrolling, but I
haven't confirmed that).
In the init function in index.html:
// Touch event handler for Google Blockly.
// Tony Hursh. Based loosely on some code at: http://vetruvet.blogspot.com/2010/12/converting-single-touch-events-to-mouse.html
// Same license as Blockly itself.
Blockly.TouchEvents = {};
Blockly.TouchEvents.touchMapper = {
"touchstart" : "mousedown",
"touchmove" : "mousemove",
"touchend" : "mouseup"
};
Blockly.TouchEvents.touchHandler = function(event) {
if (event.touches.length > 1){
return; // Punt on multitouch events.
}
var touchPoint = event.changedTouches[0];
var mappedEvent = Blockly.TouchEvents.touchMapper[event.type];
if(mappedEvent == null){ // We don't handle this event type (whatever it is). Punt.
return;
}
var simulatedEvent = document.createEvent("MouseEvent");
simulatedEvent.initMouseEvent(mappedEvent, true, true, window, 1, touchPoint.screenX, touchPoint.screenY,
touchPoint.clientX, touchPoint.clientY, false, false, false, false, 0, null);
touchPoint.target.dispatchEvent(simulatedEvent);
event.preventDefault();
};
Blockly.svgDoc.ontouchstart = Blockly.TouchEvents.touchHandler;
Blockly.svgDoc.ontouchmove = Blockly.TouchEvents.touchHandler;
Blockly.svgDoc.ontouchend = Blockly.TouchEvents.touchHandler;