Skip to content

Commit

Permalink
transit: working on run method
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom committed Feb 5, 2015
1 parent 5d87f0e commit 805a671
Show file tree
Hide file tree
Showing 17 changed files with 269 additions and 151 deletions.
11 changes: 5 additions & 6 deletions dist/burst.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Burst = (function(_super) {
};

Burst.prototype.run = function(o) {
var i, option, tr, _results;
var i, tr, _results;
Burst.__super__.run.apply(this, arguments);
i = this.transits.length;
_results = [];
Expand All @@ -90,13 +90,12 @@ Burst = (function(_super) {
this.props.randomAngle && tr.setProp({
angleShift: this.generateRandomAngle()
});
this.props.randomRadius && tr.setProp({
_results.push(this.props.randomRadius && tr.setProp({
radiusScale: this.generateRandomRadius()
});
}));
} else {
_results.push(void 0);
}
option = this.getOption(i);
option.ctx = this.ctx;
_results.push(option.isDrawLess = option.isRunLess = option.isTweenLess = true);
}
return _results;
};
Expand Down
120 changes: 65 additions & 55 deletions dist/mojs.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ Burst = (function(_super) {
};

Burst.prototype.run = function(o) {
var i, option, tr, _results;
var i, tr, _results;
Burst.__super__.run.apply(this, arguments);
i = this.transits.length;
_results = [];
Expand All @@ -466,13 +466,12 @@ Burst = (function(_super) {
this.props.randomAngle && tr.setProp({
angleShift: this.generateRandomAngle()
});
this.props.randomRadius && tr.setProp({
_results.push(this.props.randomRadius && tr.setProp({
radiusScale: this.generateRandomRadius()
});
}));
} else {
_results.push(void 0);
}
option = this.getOption(i);
option.ctx = this.ctx;
_results.push(option.isDrawLess = option.isRunLess = option.isTweenLess = true);
}
return _results;
};
Expand Down Expand Up @@ -1557,22 +1556,23 @@ Tween = require('./tween');

Transit = require('./transit');

burst = new Burst({
duration: 4000,
count: 2,
randomAngle: .3,
degree: 20,
burst = new Transit({
type: 'polygon',
duration: 2000,
count: 3,
isIt: true,
radius: {
0: 75
},
points: 5,
type: 'polygon'
points: 5
});

document.body.addEventListener('click', function(e) {
return burst.run({
x: e.x,
y: e.y
y: e.y,
duration: 4000,
type: 'circle'
});
});

Expand Down Expand Up @@ -1931,19 +1931,23 @@ Transit = (function(_super) {
return this.onUpdate = this.props.onUpdate;
};

Transit.prototype.render = function() {
if (!this.isRendered) {
Transit.prototype.render = function(isForce) {
if (!this.isRendered || isForce) {
if (this.o.ctx == null) {
this.ctx = document.createElementNS(this.ns, 'svg');
this.ctx.style.position = 'absolute';
this.ctx.style.width = '100%';
this.ctx.style.height = '100%';
if (this.ctx == null) {
this.ctx = document.createElementNS(this.ns, 'svg');
this.ctx.style.position = 'absolute';
this.ctx.style.width = '100%';
this.ctx.style.height = '100%';
}
this.createBit();
this.calcSize();
this.el = document.createElement('div');
if (this.el == null) {
this.el = document.createElement('div');
this.el.appendChild(this.ctx);
(this.o.parent || document.body).appendChild(this.el);
}
this.setElStyles();
this.el.appendChild(this.ctx);
(this.o.parent || document.body).appendChild(this.el);
} else {
this.ctx = this.o.ctx;
this.createBit();
Expand Down Expand Up @@ -2090,40 +2094,37 @@ Transit = (function(_super) {
};

Transit.prototype.calcCurrentProps = function(progress) {
var a, b, g, i, key, keys, len, num, r, str, units, value, _i, _len, _ref, _results;
var a, b, g, i, key, keys, len, num, r, str, units, value, _results;
keys = Object.keys(this.deltas);
len = keys.length;
_results = [];
while (len--) {
key = keys[len];
value = this.deltas[key];
switch (value.type) {
case 'array':
str = '';
_ref = value.delta;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
num = _ref[i];
str += "" + (value.start[i] + num * this.progress) + " ";
}
_results.push(this.props[key] = str);
break;
case 'number':
_results.push(this.props[key] = value.start + value.delta * progress);
break;
case 'unit':
units = value.end.unit;
_results.push(this.props[key] = "" + (value.start.value + value.delta * progress) + units);
break;
case 'color':
r = parseInt(value.start.r + value.delta.r * progress, 10);
g = parseInt(value.start.g + value.delta.g * progress, 10);
b = parseInt(value.start.b + value.delta.b * progress, 10);
a = parseInt(value.start.a + value.delta.a * progress, 10);
_results.push(this.props[key] = "rgba(" + r + "," + g + "," + b + "," + a + ")");
break;
default:
_results.push(void 0);
}
_results.push(this.props[key] = (function() {
var _i, _len, _ref;
switch (value.type) {
case 'array':
str = '';
_ref = value.delta;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
num = _ref[i];
str += "" + (value.start[i] + num * this.progress) + " ";
}
return str;
case 'number':
return value.start + value.delta * progress;
case 'unit':
units = value.end.unit;
return "" + (value.start.value + value.delta * progress) + units;
case 'color':
r = parseInt(value.start.r + value.delta.r * progress, 10);
g = parseInt(value.start.g + value.delta.g * progress, 10);
b = parseInt(value.start.b + value.delta.b * progress, 10);
a = parseInt(value.start.a + value.delta.a * progress, 10);
return "rgba(" + r + "," + g + "," + b + "," + a + ")";
}
}).call(this));
}
return _results;
};
Expand Down Expand Up @@ -2294,6 +2295,7 @@ Transit = (function(_super) {
this.calcSize();
this.setElStyles();
!this.o.isDrawLess && this.setProgress(0, true);
this.render(true);
return this.startTween();
};

Expand Down Expand Up @@ -2346,8 +2348,6 @@ h = require('./h');
t = require('./tweener');

Tween = (function() {
Tween.prototype.t = t;

function Tween(o) {
this.o = o != null ? o : {};
this.vars();
Expand Down Expand Up @@ -2401,7 +2401,13 @@ Tween = (function() {
while (i--) {
this.timelines[i].start(this.startTime);
}
return this.t.add(this);
t.add(this);
return this;
};

Tween.prototype.stop = function() {
t.remove(this);
return this;
};

Tween.prototype.getDimentions = function() {
Expand All @@ -2422,6 +2428,9 @@ if ((typeof define === "function") && define.amd) {
});
}


/* istanbul ignore next */

if ((typeof module === "object") && (typeof module.exports === "object")) {
module.exports = Tween;
}
Expand Down Expand Up @@ -2534,9 +2543,10 @@ Tweener = (function() {
};

Tweener.prototype.remove = function(tween) {
var index;
var before, index;
index = this.tweens.indexOf(tween);
if (index !== -1) {
before = this.tweens.length;
return this.tweens.splice(index, 1);
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/mojs.min.js

Large diffs are not rendered by default.

76 changes: 39 additions & 37 deletions dist/transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,23 @@ Transit = (function(_super) {
return this.onUpdate = this.props.onUpdate;
};

Transit.prototype.render = function() {
if (!this.isRendered) {
Transit.prototype.render = function(isForce) {
if (!this.isRendered || isForce) {
if (this.o.ctx == null) {
this.ctx = document.createElementNS(this.ns, 'svg');
this.ctx.style.position = 'absolute';
this.ctx.style.width = '100%';
this.ctx.style.height = '100%';
if (this.ctx == null) {
this.ctx = document.createElementNS(this.ns, 'svg');
this.ctx.style.position = 'absolute';
this.ctx.style.width = '100%';
this.ctx.style.height = '100%';
}
this.createBit();
this.calcSize();
this.el = document.createElement('div');
if (this.el == null) {
this.el = document.createElement('div');
this.el.appendChild(this.ctx);
(this.o.parent || document.body).appendChild(this.el);
}
this.setElStyles();
this.el.appendChild(this.ctx);
(this.o.parent || document.body).appendChild(this.el);
} else {
this.ctx = this.o.ctx;
this.createBit();
Expand Down Expand Up @@ -224,40 +228,37 @@ Transit = (function(_super) {
};

Transit.prototype.calcCurrentProps = function(progress) {
var a, b, g, i, key, keys, len, num, r, str, units, value, _i, _len, _ref, _results;
var a, b, g, i, key, keys, len, num, r, str, units, value, _results;
keys = Object.keys(this.deltas);
len = keys.length;
_results = [];
while (len--) {
key = keys[len];
value = this.deltas[key];
switch (value.type) {
case 'array':
str = '';
_ref = value.delta;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
num = _ref[i];
str += "" + (value.start[i] + num * this.progress) + " ";
}
_results.push(this.props[key] = str);
break;
case 'number':
_results.push(this.props[key] = value.start + value.delta * progress);
break;
case 'unit':
units = value.end.unit;
_results.push(this.props[key] = "" + (value.start.value + value.delta * progress) + units);
break;
case 'color':
r = parseInt(value.start.r + value.delta.r * progress, 10);
g = parseInt(value.start.g + value.delta.g * progress, 10);
b = parseInt(value.start.b + value.delta.b * progress, 10);
a = parseInt(value.start.a + value.delta.a * progress, 10);
_results.push(this.props[key] = "rgba(" + r + "," + g + "," + b + "," + a + ")");
break;
default:
_results.push(void 0);
}
_results.push(this.props[key] = (function() {
var _i, _len, _ref;
switch (value.type) {
case 'array':
str = '';
_ref = value.delta;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
num = _ref[i];
str += "" + (value.start[i] + num * this.progress) + " ";
}
return str;
case 'number':
return value.start + value.delta * progress;
case 'unit':
units = value.end.unit;
return "" + (value.start.value + value.delta * progress) + units;
case 'color':
r = parseInt(value.start.r + value.delta.r * progress, 10);
g = parseInt(value.start.g + value.delta.g * progress, 10);
b = parseInt(value.start.b + value.delta.b * progress, 10);
a = parseInt(value.start.a + value.delta.a * progress, 10);
return "rgba(" + r + "," + g + "," + b + "," + a + ")";
}
}).call(this));
}
return _results;
};
Expand Down Expand Up @@ -428,6 +429,7 @@ Transit = (function(_super) {
this.calcSize();
this.setElStyles();
!this.o.isDrawLess && this.setProgress(0, true);
this.render(true);
return this.startTween();
};

Expand Down
13 changes: 10 additions & 3 deletions dist/tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ h = require('./h');
t = require('./tweener');

Tween = (function() {
Tween.prototype.t = t;

function Tween(o) {
this.o = o != null ? o : {};
this.vars();
Expand Down Expand Up @@ -60,7 +58,13 @@ Tween = (function() {
while (i--) {
this.timelines[i].start(this.startTime);
}
return this.t.add(this);
t.add(this);
return this;
};

Tween.prototype.stop = function() {
t.remove(this);
return this;
};

Tween.prototype.getDimentions = function() {
Expand All @@ -81,6 +85,9 @@ if ((typeof define === "function") && define.amd) {
});
}


/* istanbul ignore next */

if ((typeof module === "object") && (typeof module.exports === "object")) {
module.exports = Tween;
}
Expand Down
3 changes: 2 additions & 1 deletion dist/tweener.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ Tweener = (function() {
};

Tweener.prototype.remove = function(tween) {
var index;
var before, index;
index = this.tweens.indexOf(tween);
if (index !== -1) {
before = this.tweens.length;
return this.tweens.splice(index, 1);
}
};
Expand Down

0 comments on commit 805a671

Please sign in to comment.