Cards: Movement animation
This commit is contained in:
@@ -24,6 +24,8 @@ namespace VAR.Focus.Web.Controls
|
|||||||
|
|
||||||
private int _timeRefreshDisconnected = 5000;
|
private int _timeRefreshDisconnected = 5000;
|
||||||
|
|
||||||
|
private int _timeMoveAnimation = 300;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
@@ -64,6 +66,12 @@ namespace VAR.Focus.Web.Controls
|
|||||||
set { _timeRefreshDisconnected = value; }
|
set { _timeRefreshDisconnected = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int TimeMoveAnimation
|
||||||
|
{
|
||||||
|
get { return _timeMoveAnimation; }
|
||||||
|
set { _timeMoveAnimation = value; }
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Control Life cycle
|
#region Control Life cycle
|
||||||
@@ -100,6 +108,7 @@ namespace VAR.Focus.Web.Controls
|
|||||||
sbCfg.AppendFormat(" TimePoolData: {0},\n", _timePoolData);
|
sbCfg.AppendFormat(" TimePoolData: {0},\n", _timePoolData);
|
||||||
sbCfg.AppendFormat(" TimeRefresh: {0},\n", _timeRefresh);
|
sbCfg.AppendFormat(" TimeRefresh: {0},\n", _timeRefresh);
|
||||||
sbCfg.AppendFormat(" TimeRefreshDisconnected: {0},\n", _timeRefreshDisconnected);
|
sbCfg.AppendFormat(" TimeRefreshDisconnected: {0},\n", _timeRefreshDisconnected);
|
||||||
|
sbCfg.AppendFormat(" TimeMoveAnimation: {0},\n", _timeMoveAnimation);
|
||||||
sbCfg.AppendFormat(" Texts: {{\n");
|
sbCfg.AppendFormat(" Texts: {{\n");
|
||||||
sbCfg.AppendFormat(" Toolbox: \"Toolbox\",\n");
|
sbCfg.AppendFormat(" Toolbox: \"Toolbox\",\n");
|
||||||
sbCfg.AppendFormat(" AddCard: \"+ Add card\",\n");
|
sbCfg.AppendFormat(" AddCard: \"+ Add card\",\n");
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
var Toolbox = function (cfg, container) {
|
|
||||||
|
var CosineInterpolation = function (f) {
|
||||||
|
return 1 - (Math.cos(f * Math.PI) + 1) / 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
var Toolbox = function (cfg, container) {
|
||||||
this.cfg = cfg;
|
this.cfg = cfg;
|
||||||
this.X = 0;
|
this.X = 0;
|
||||||
this.Y = 0;
|
this.Y = 0;
|
||||||
@@ -208,13 +213,39 @@ Card.prototype = {
|
|||||||
RemoveFromContainer: function(){
|
RemoveFromContainer: function(){
|
||||||
this.container.removeChild(this.divCard);
|
this.container.removeChild(this.divCard);
|
||||||
},
|
},
|
||||||
|
MoveFrame: function(){
|
||||||
|
var f = ((+new Date()) - this.animData.startTime) / this.animData.time;
|
||||||
|
if (f < 1.0) {
|
||||||
|
f = CosineInterpolation(f);
|
||||||
|
f = CosineInterpolation(f);
|
||||||
|
var f2 = 1 - f;
|
||||||
|
var x = this.animData.X1 * f + this.animData.X0 * f2;
|
||||||
|
var y = this.animData.Y1 * f + this.animData.Y0 * f2;
|
||||||
|
this.divCard.style.left = x + "px";
|
||||||
|
this.divCard.style.top = y + "px";
|
||||||
|
this.animData.animationID = window.setTimeout(this.bindedMoveFrame, 16);
|
||||||
|
} else {
|
||||||
|
this.divCard.style.left = this.animData.X1 + "px";
|
||||||
|
this.divCard.style.top = this.animData.Y1 + "px";
|
||||||
|
this.animData = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
Move: function (x, y) {
|
Move: function (x, y) {
|
||||||
this.X = x;
|
this.X = x;
|
||||||
this.Y = y;
|
this.Y = y;
|
||||||
this.newX = x;
|
this.newX = x;
|
||||||
this.newY = y;
|
this.newY = y;
|
||||||
this.divCard.style.left = this.X + "px";
|
this.animData = {
|
||||||
this.divCard.style.top = this.Y + "px";
|
X0: parseInt(this.divCard.style.left),
|
||||||
|
Y0: parseInt(this.divCard.style.top),
|
||||||
|
X1: x,
|
||||||
|
Y1: y,
|
||||||
|
time: this.cfg.TimeMoveAnimation,
|
||||||
|
startTime: +new Date(),
|
||||||
|
animationID: 0
|
||||||
|
};
|
||||||
|
this.bindedMoveFrame = Card.prototype.MoveFrame.bind(this);
|
||||||
|
this.animData.animationID = window.setTimeout(this.bindedMoveFrame, 16);
|
||||||
},
|
},
|
||||||
Edit: function (title, body) {
|
Edit: function (title, body) {
|
||||||
if (this.Editing) {
|
if (this.Editing) {
|
||||||
@@ -253,6 +284,12 @@ Card.prototype = {
|
|||||||
Show: function () {
|
Show: function () {
|
||||||
this.divCard.style.display = "";
|
this.divCard.style.display = "";
|
||||||
},
|
},
|
||||||
|
OnMoveStart: function () {
|
||||||
|
if (this.animData) {
|
||||||
|
window.clearTimeout(this.animData.animationID);
|
||||||
|
this.animData = null;
|
||||||
|
}
|
||||||
|
},
|
||||||
OnMove: function () {
|
OnMove: function () {
|
||||||
if (this.X != this.newX || this.Y != this.newY) {
|
if (this.X != this.newX || this.Y != this.newY) {
|
||||||
var card = this;
|
var card = this;
|
||||||
@@ -387,6 +424,10 @@ Card.prototype = {
|
|||||||
return relPos;
|
return relPos;
|
||||||
},
|
},
|
||||||
MouseDown: function (evt) {
|
MouseDown: function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
this.OnMoveStart();
|
||||||
|
|
||||||
var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY });
|
var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY });
|
||||||
this.offsetX = pos.x - this.divCard.offsetLeft;
|
this.offsetX = pos.x - this.divCard.offsetLeft;
|
||||||
this.offsetY = pos.y - this.divCard.offsetTop;
|
this.offsetY = pos.y - this.divCard.offsetTop;
|
||||||
@@ -394,29 +435,34 @@ Card.prototype = {
|
|||||||
document.addEventListener("mouseup", this.bindedMouseUp, false);
|
document.addEventListener("mouseup", this.bindedMouseUp, false);
|
||||||
document.addEventListener("mousemove", this.bindedMouseMove, false);
|
document.addEventListener("mousemove", this.bindedMouseMove, false);
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
MouseMove: function (evt) {
|
MouseMove: function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY });
|
var pos = this.GetRelativePosToContainer({ x: evt.clientX, y: evt.clientY });
|
||||||
this.newX = parseInt(pos.x - this.offsetX);
|
this.newX = parseInt(pos.x - this.offsetX);
|
||||||
this.newY = parseInt(pos.y - this.offsetY);
|
this.newY = parseInt(pos.y - this.offsetY);
|
||||||
this.divCard.style.left = this.newX + "px";
|
this.divCard.style.left = this.newX + "px";
|
||||||
this.divCard.style.top = this.newY + "px";
|
this.divCard.style.top = this.newY + "px";
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
MouseUp: function (evt) {
|
MouseUp: function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
document.removeEventListener("mouseup", this.bindedMouseUp, false);
|
document.removeEventListener("mouseup", this.bindedMouseUp, false);
|
||||||
document.removeEventListener("mousemove", this.bindedMouseMove, false);
|
document.removeEventListener("mousemove", this.bindedMouseMove, false);
|
||||||
|
|
||||||
this.OnMove();
|
this.OnMove();
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
TouchStart: function (evt) {
|
TouchStart: function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
|
this.OnMoveStart();
|
||||||
|
|
||||||
var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
|
var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
|
||||||
this.offsetX = pos.x - this.divCard.offsetLeft;
|
this.offsetX = pos.x - this.divCard.offsetLeft;
|
||||||
this.offsetY = pos.y - this.divCard.offsetTop;
|
this.offsetY = pos.y - this.divCard.offsetTop;
|
||||||
@@ -425,27 +471,28 @@ Card.prototype = {
|
|||||||
document.addEventListener("touchcancel", this.bindedTouchEnd, false);
|
document.addEventListener("touchcancel", this.bindedTouchEnd, false);
|
||||||
document.addEventListener("touchmove", this.bindedTouchMove, false);
|
document.addEventListener("touchmove", this.bindedTouchMove, false);
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
TouchMove: function (evt) {
|
TouchMove: function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
|
var pos = this.GetRelativePosToContainer({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
|
||||||
this.newX = parseInt(pos.x - this.offsetX);
|
this.newX = parseInt(pos.x - this.offsetX);
|
||||||
this.newY = parseInt(pos.y - this.offsetY);
|
this.newY = parseInt(pos.y - this.offsetY);
|
||||||
this.divCard.style.left = this.newX + "px";
|
this.divCard.style.left = this.newX + "px";
|
||||||
this.divCard.style.top = this.newY + "px";
|
this.divCard.style.top = this.newY + "px";
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
TouchEnd: function (evt) {
|
TouchEnd: function (evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
|
||||||
document.removeEventListener("touchend", this.bindedTouchEnd, false);
|
document.removeEventListener("touchend", this.bindedTouchEnd, false);
|
||||||
document.removeEventListener("touchcancel", this.bindedTouchEnd, false);
|
document.removeEventListener("touchcancel", this.bindedTouchEnd, false);
|
||||||
document.removeEventListener("touchmove", this.bindedTouchMove, false);
|
document.removeEventListener("touchmove", this.bindedTouchMove, false);
|
||||||
|
|
||||||
this.OnMove();
|
this.OnMove();
|
||||||
|
|
||||||
evt.preventDefault();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
EnterEditionMode: function(){
|
EnterEditionMode: function(){
|
||||||
|
|||||||
Reference in New Issue
Block a user