Skip to content

Commit

Permalink
transit: add _overrideUpdateCallbacks method
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom committed Mar 4, 2016
1 parent 8f984c8 commit 459dc09
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,7 +1,7 @@
{
"name": "mojs",
"description": "motion graphics toolbelt for the web",
"version": "0.174.4",
"version": "0.175.0",
"license": "MIT",
"homepage": "https://github.com/legomushroom/mojs",
"authors": [
Expand Down
52 changes: 44 additions & 8 deletions build/mo.js
Expand Up @@ -689,16 +689,13 @@
}, {
key: 'then',
value: function then(o) {
var it, len, opts;
// return if nothing was passed
if (o == null || !(0, _keys2.default)(o)) {
return;
}
// merge then options with the current ones
var merged = this._mergeThenOptions(this.history[this.history.length - 1], o);
// and save to the history
this.history.push(merged);
// set options control callbacks

var it = this,
// save lexical this, uh oh
onUpdate = merged.onUpdate,
Expand All @@ -711,7 +708,13 @@
it._setProgress(pe);
};

merged.onFirstUpdate = function () {
var onFirstUpdate = merged.onFirstUpdate,
isOnFirstUpdate = onFirstUpdate && typeof onFirstUpdate === 'function';
// redefine onFirstUpdate for Transit's _tuneOptions
merged.onFirstUpdate = function (pe) {
// call onFirstUpdate function from options
isOnFirstUpdate && onFirstUpdate.apply(this, arguments);
// calcalate and draw Transit's progress
it._tuneOptions(it.history[this.index]);
};

Expand All @@ -720,6 +723,37 @@
it.timeline.append(new _tween2.default(merged));
return this;
}
/*
Method to override(or define) update callbacks in passed object.
@param {Object} Object to override callbacks in.
*/

}, {
key: '_overrideUpdateCallbacks',
value: function _overrideUpdateCallbacks(object) {
var it = this,
// save lexical this, uh oh
onUpdate = object.onUpdate,
isOnUpdate = onUpdate && typeof onUpdate === 'function';
// redefine onUpdate for Transit's draw calculation in _setProgress
object.onUpdate = function (pe) {
// call onUpdate function from options
isOnUpdate && onUpdate.apply(this, arguments);
// calcalate and draw Transit's progress
it._setProgress(pe);
};

var onFirstUpdate = object.onFirstUpdate,
isOnFirstUpdate = onFirstUpdate && typeof onFirstUpdate === 'function';
// redefine onFirstUpdate for Transit's _tuneOptions
object.onFirstUpdate = function (pe) {
// call onFirstUpdate function from options
isOnFirstUpdate && onFirstUpdate.apply(this, arguments);
// calcalate and draw Transit's progress
// call tune options with index of the tween only if history > 1
it.history.length > 1 && it._tuneOptions(it.history[this.index || 0]);
};
}
// /*
// Method to start the animation with optional new options.
// @public
Expand Down Expand Up @@ -1331,6 +1365,8 @@
o[key] = {};o[key][startKey] = endValue;
}
}
// and save to the history
this.history.push(o);
return o;
}
/*
Expand Down Expand Up @@ -1372,7 +1408,7 @@
// redefine onUpdate for Transit's draw calculation in _setProgress
this._o.onUpdate = function (pe) {
// call onUpdate function from options
isOnUpdate && onUpdate.apply(it.tween, arguments);
isOnUpdate && onUpdate.apply(this, arguments);
// calcalate and draw Transit's progress
it._setProgress(pe);
};
Expand All @@ -1382,7 +1418,7 @@
// redefine onStart to show/hide Transit
this._o.onStart = function (isForward) {
// call onStart function from options
isOnStart && onStart.apply(it.tween, arguments);
isOnStart && onStart.apply(this, arguments);
// show the Transit on start
// hide the Transit on reverse complete if isShowInit is not set
isForward ? it._show() : !it._props.isShowInit && it._hide();
Expand Down Expand Up @@ -6983,7 +7019,7 @@
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

window.mojs = {
revision: '0.174.4', isDebug: true, helpers: _h2.default,
revision: '0.175.0', isDebug: true, helpers: _h2.default,
Transit: _transit2.default, Swirl: _swirl2.default, Burst: _burst2.default, stagger: _stagger2.default, Spriter: _spriter2.default, MotionPath: _motionPath2.default,
Tween: _tween2.default, Timeline: _timeline2.default, Tweenable: _tweenable2.default, tweener: _tweener2.default, easing: _easing2.default, shapesMap: _shapesMap2.default
};
Expand Down
10 changes: 6 additions & 4 deletions build/mo.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/mojs.babel.js
Expand Up @@ -14,7 +14,7 @@ import tweener from './tween/tweener';
import easing from './easing/easing';

window.mojs = {
revision: '0.174.4', isDebug: true, helpers: h,
revision: '0.175.0', isDebug: true, helpers: h,
Transit, Swirl, Burst, stagger, Spriter, MotionPath,
Tween, Timeline, Tweenable, tweener, easing, shapesMap
}
Expand Down
47 changes: 40 additions & 7 deletions js/transit.babel.js
Expand Up @@ -52,14 +52,11 @@ class Transit extends Tweenable {
@returns {Object} this.
*/
then ( o ) {
var it, len, opts;
// return if nothing was passed
if ((o == null) || !Object.keys(o)) { return; }
// merge then options with the current ones
var merged = this._mergeThenOptions(this.history[this.history.length - 1], o);
// and save to the history
this.history.push(merged);
// set options control callbacks

var it = this, // save lexical this, uh oh
onUpdate = merged.onUpdate,
isOnUpdate = (onUpdate && typeof onUpdate === 'function');
Expand All @@ -71,7 +68,13 @@ class Transit extends Tweenable {
it._setProgress(pe);
};

merged.onFirstUpdate = function() {
var onFirstUpdate = merged.onFirstUpdate,
isOnFirstUpdate = (onFirstUpdate && typeof onFirstUpdate === 'function');
// redefine onFirstUpdate for Transit's _tuneOptions
merged.onFirstUpdate = function ( pe ) {
// call onFirstUpdate function from options
isOnFirstUpdate && onFirstUpdate.apply( this, arguments );
// calcalate and draw Transit's progress
it._tuneOptions(it.history[this.index]);
};

Expand All @@ -80,6 +83,34 @@ class Transit extends Tweenable {
it.timeline.append(new Tween(merged));
return this;
}
/*
Method to override(or define) update callbacks in passed object.
@param {Object} Object to override callbacks in.
*/
_overrideUpdateCallbacks (object) {
var it = this, // save lexical this, uh oh
onUpdate = object.onUpdate,
isOnUpdate = (onUpdate && typeof onUpdate === 'function');
// redefine onUpdate for Transit's draw calculation in _setProgress
object.onUpdate = function ( pe ) {
// call onUpdate function from options
isOnUpdate && onUpdate.apply( this, arguments );
// calcalate and draw Transit's progress
it._setProgress(pe);
};

var onFirstUpdate = object.onFirstUpdate,
isOnFirstUpdate = (onFirstUpdate && typeof onFirstUpdate === 'function');
// redefine onFirstUpdate for Transit's _tuneOptions
object.onFirstUpdate = function ( pe ) {
// call onFirstUpdate function from options
isOnFirstUpdate && onFirstUpdate.apply( this, arguments );
// calcalate and draw Transit's progress
// call tune options with index of the tween only if history > 1
it.history.length > 1 && it._tuneOptions(it.history[this.index || 0]);
};

}
// /*
// Method to start the animation with optional new options.
// @public
Expand Down Expand Up @@ -578,6 +609,8 @@ class Transit extends Tweenable {
}
if (endValue != null) { o[key] = {}; o[key][startKey] = endValue; }
}
// and save to the history
this.history.push(o);
return o;
}
/*
Expand Down Expand Up @@ -609,7 +642,7 @@ class Transit extends Tweenable {
// redefine onUpdate for Transit's draw calculation in _setProgress
this._o.onUpdate = function ( pe ) {
// call onUpdate function from options
isOnUpdate && onUpdate.apply( it.tween, arguments );
isOnUpdate && onUpdate.apply( this, arguments );
// calcalate and draw Transit's progress
it._setProgress(pe);
};
Expand All @@ -619,7 +652,7 @@ class Transit extends Tweenable {
// redefine onStart to show/hide Transit
this._o.onStart = function ( isForward ) {
// call onStart function from options
isOnStart && onStart.apply( it.tween, arguments );
isOnStart && onStart.apply( this, arguments );
// show the Transit on start
// hide the Transit on reverse complete if isShowInit is not set
( isForward ) ? it._show() : (!it._props.isShowInit && it._hide());
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "mo-js",
"description": "motion graphics toolbelt for the web",
"version": "0.174.4",
"version": "0.175.0",
"license": "MIT",
"private": false,
"scripts": {
Expand Down

0 comments on commit 459dc09

Please sign in to comment.