me.prototype.spinPieStart = function(e){
var event = e.originalEvent;
var touch = event.targetTouches ? event.targetTouches[0] : e;
e.stopPropagation();
// recalibrate pieCenter in case page has been scrolled
var pageTop = this.pieDish.offset().top;
var pageLeft = this.pieDish.offset().left;
this.pieCenter = {x: this.startPieCenter.x - (this.pageLeft - pageLeft) , y:this.startPieCenter.y - (this.pageTop - pageTop)};
// differentiate between move and click
this.moved = false;
this.startPos = {x:touch.pageX, y:touch.pageY};
// figure out where the user touched relative to the pie center
var location = {x:touch.pageX - this.pieCenter.x, y:touch.pageY - this.pieCenter.y}
this.startAngle = Math.atan2(location.y,location.x);
this.manualSpin = true;
}
me.prototype.spinPieMove = function(e){
e.stopPropagation();
e.preventDefault();
if (this.manualSpin){
var event = e.originalEvent;
var touch = event.targetTouches ? event.targetTouches[0] : e;
var location = {x:touch.pageX - this.pieCenter.x, y:touch.pageY - this.pieCenter.y};
this.currentAngle = Math.atan2(location.y,location.x);
this.newAngle = this.finalAngle + (this.currentAngle - this.startAngle);
this.newAngle = this.newAngle % (Math.PI * 2);
this.$canvas.moveRelative({rotateDeg: this.radian2Deg(this.newAngle), speed:0, removeTiming:false});
if (Math.abs(this.startPos.x - location.x) > 5 || Math.abs(this.startPos.x - location.y > 5)) {
this.moved = true;
}
}
}
me.prototype.spinPieStop = function(e){
var ev;
e.stopPropagation();
e.preventDefault();
if (this.manualSpin){
// detect click
if (!this.moved){
ev = document.createEvent('MouseEvents');
ev.initMouseEvent('click', true, true, e.view, 1,
this.startPos.x, this.startPos.y, this.startPos.x, this.startPos.y,
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
0, null);
ev._fake = true;
this.$canvas[0].dispatchEvent(ev);
} else {
// spin stop
this.finalAngle = this.newAngle;
this.setCurrentSegment();
}
}
this.manualSpin = false;
}