adding touch events for ios

This commit is contained in:
Micho 2013-05-23 18:39:01 +02:00
parent f54c020692
commit c8fcd5a28f
1 changed files with 59 additions and 19 deletions

View File

@ -34,8 +34,6 @@ $(function () {
init(); init();
setSpeed(2); setSpeed(2);
startPlay(); startPlay();
//update();
//setTimeout(stopPlay, 10000);
}) })
function setSpeed(speed) { function setSpeed(speed) {
@ -58,31 +56,42 @@ var mouseDragY;
var sliderDragStartTime; var sliderDragStartTime;
var selectedCount = 0; var selectedCount = 0;
function sliderDragStart() { function sliderDragStart(x) {
mouseDrag = true; mouseDrag = true;
sliderDrag = true; sliderDrag = true;
sliderDragStartTime = currentTime; sliderDragStartTime = currentTime;
mouseDragX = x;
mouseDragX0 = x;
} }
function mapDragStart() { function mapDragStart(x, y) {
mouseDrag = true; mouseDrag = true;
mapDrag = true; mapDrag = true;
mouseDragX = mouseDragX0; mouseDragX = x;
mouseDragY = mouseDragY0; mouseDragY = y;
clients.forEach(function (c) { c.selected = false; }); mouseDragX0 = x;
mouseDragY0 = y;
selectedCount = 0; selectedCount = 0;
activeCount = 0;
activeSelectedCount = 0;
clients.forEach(function (c) { c.selected = false; });
renderCanvas();
renderInfos();
} }
function mouseDragMove(event) { function mouseDragMove(x, y) {
if (mouseDrag) { if (mouseDrag) {
if (sliderDrag) { if (sliderDrag) {
currentTime = sliderDragStartTime + (mouseDragX0 - event.pageX); currentTime = sliderDragStartTime + (mouseDragX0 - x);
updateFrame(); updateFrame();
} }
if (mapDrag) { if (mapDrag) {
mouseDragX = event.pageX; mouseDragX = x;
mouseDragY = event.pageY; mouseDragY = y;
var p = $('#container').offset(); var p = $('#container').offset();
var x0 = Math.min(mouseDragX0, mouseDragX) - p.left; var x0 = Math.min(mouseDragX0, mouseDragX) - p.left;
var x1 = Math.max(mouseDragX0, mouseDragX) - p.left; var x1 = Math.max(mouseDragX0, mouseDragX) - p.left;
@ -111,8 +120,8 @@ function mouseDragMove(event) {
event.preventDefault(); event.preventDefault();
return false; return false;
} else { } else {
mouseDragX0 = event.pageX; mouseDragX0 = x;
mouseDragY0 = event.pageY; mouseDragY0 = y;
} }
} }
@ -140,12 +149,43 @@ function init() {
$('#speed2').click(function () { setSpeed(2); }); $('#speed2').click(function () { setSpeed(2); });
$('#speed3').click(function () { setSpeed(3); }); $('#speed3').click(function () { setSpeed(3); });
$('#sliderWrapper').mousedown(function () { sliderDragStart(); }); $('#sliderWrapper').mousedown(function (e) {
$('#container').mousedown(function () { mapDragStart(); }); sliderDragStart(e.pageX);
$(document).mousemove(function (e) { return mouseDragMove(e); }); e.preventDefault();
$(document).mouseup(function (e) { mouseDragStop(); }); return false;
});
$('#sliderWrapper').get(0).addEventListener('touchstart', function (e) {
sliderDragStart(e.touches[0].pageX);
e.preventDefault();
return false;
}, false);
$(document).on('selectstart', function (e) { e.preventDefault(); return !mouseDrag; }); $('#container').mousedown(function (e) {
mapDragStart(e.pageX, e.pageY);
e.preventDefault();
return false;
});
$('#container').get(0).addEventListener('touchstart', function (e) {
mapDragStart(e.touches[0].pageX, e.touches[0].pageY);
e.preventDefault();
return false;
}, false);
$(document).mousemove(function (e) {
mouseDragMove(e.pageX, e.pageY);
});
$(document).get(0).addEventListener('touchmove', function (e) {
mouseDragMove(e.touches[0].pageX, e.touches[0].pageY);
}, false);
$(document).mouseup(function () {
mouseDragStop();
});
$(document).get(0).addEventListener('touchend', function () {
mouseDragStop();
}, false);
var index = -1; var index = -1;
for (var time = -60; time <= (4*24+1)*60; time++) { for (var time = -60; time <= (4*24+1)*60; time++) {