summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/morph.js45
-rw-r--r--src/runner.js22
2 files changed, 42 insertions, 25 deletions
diff --git a/src/morph.js b/src/morph.js
index 15b227b..c6e2152 100644
--- a/src/morph.js
+++ b/src/morph.js
@@ -2,15 +2,11 @@
SVG.Morphable = SVG.invent({
create: function (stepper) {
// FIXME: the default stepper does not know about easing
- this._stepper = stepper || function (from, to, pos) {
- if(typeof from !== 'number') {
- return pos < 1 ? from : to
- }
- return from + (to - from) * pos
- }
+ this._stepper = stepper || new SVG.Ease('-')
this._from = null
this._to = null
+ this._type = null
this._context = null
this.modifier = function(arr) { return arr }
},
@@ -27,7 +23,7 @@ SVG.Morphable = SVG.invent({
to: function (val, modifier) {
if(val == null)
- return this._from
+ return this._to
this._to = this._set(val)
this.modifier = modifier || this.modifier
@@ -55,20 +51,29 @@ SVG.Morphable = SVG.invent({
_set: function (value) {
if(!this._type) {
- if (typeof value === 'number') {
+ var type = typeof value
+
+ if (type === 'number') {
this.type(SVG.Number)
- } else if (SVG.Color.isColor(value)) {
- this.type(SVG.Color)
+ } else if (type === 'string') {
- } else if (SVG.regex.delimiter.test(value)) {
- this.type(SVG.regex.pathLetters.test(value)
- ? SVG.PathArray
- : SVG.Array
- )
+ if (SVG.Color.isColor(value)) {
+ this.type(SVG.Color)
- } else if (SVG.regex.numberAndUnit.test(value)) {
- this.type(SVG.Number)
+ } else if (SVG.regex.delimiter.test(value)) {
+ this.type(SVG.regex.pathLetters.test(value)
+ ? SVG.PathArray
+ : SVG.Array
+ )
+
+ } else if (SVG.regex.numberAndUnit.test(value)) {
+ this.type(SVG.Number)
+
+ } else {
+ this.type(SVG.Morphable.NonMorphable)
+
+ }
} else if (value in SVG.MorphableTypes) {
this.type(value.constructor)
@@ -76,8 +81,8 @@ SVG.Morphable = SVG.invent({
} else if (Array.isArray(value)) {
this.type(SVG.Array)
- } else if (typeof value === 'object') {
- this.type(SVG.ObjectBag)
+ } else if (type === 'object') {
+ this.type(SVG.Morphable.ObjectBag)
} else {
this.type(SVG.Morphable.NonMorphable)
@@ -198,8 +203,6 @@ SVG.Morphable.ObjectBag = SVG.invent({
this.values.push(keys[i])
this.values.push(objOrArr[keys[i]])
}
-
- console.log(this.values)
},
extend: {
diff --git a/src/runner.js b/src/runner.js
index fa3df5e..9ed5bbb 100644
--- a/src/runner.js
+++ b/src/runner.js
@@ -12,8 +12,14 @@ SVG.Runner = SVG.invent({
create: function (options) {
+ // ensure a default value
options = options || SVG.defaults.timeline.duration
+ // ensure that we get a controller
+ options = typeof options === 'function'
+ ? new SVG.Controller(options) :
+ options
+
// Declare all of the variables
this._element = null
this._functions = []
@@ -95,6 +101,7 @@ SVG.Runner = SVG.invent({
*/
element: function (element) {
+ if(element == null) return this._element
this._element = element
return this
},
@@ -153,6 +160,8 @@ SVG.Runner = SVG.invent({
*/
time: function (time) {
+ if (time == null) return this._time
+
let dt = time - this._time
this.step(dt)
return this
@@ -166,8 +175,8 @@ SVG.Runner = SVG.invent({
// Increment the time and read out the parameters
var duration = this._duration
- var time = this._time
this._time += dt || 16
+ var time = this._time
// Work out if we are in range to run the function
var timeInside = 0 <= time && time <= duration
@@ -178,6 +187,7 @@ SVG.Runner = SVG.invent({
// initialise only what needs to be initialised on the rising edge
var justStarted = this._last <= 0 && time >= 0
var justFinished = this._last <= duration && finished
+
this._initialise(justStarted)
this._last = time
@@ -191,27 +201,31 @@ SVG.Runner = SVG.invent({
: position // If running,
) || finished
+ // FIXME: for the sake of unifirmity this method should return This
+ // we can then add a functon isFinished to see if a runner is finished
// Work out if we are finished
return finished
},
finish: function () {
+ // FIXME: this is wrong as long as step returns a boolean
return this.step(Infinity)
},
+ // TODO
// Sets the time to the end time and makes the time advance backwards
reverse: function () {
-
+ return this
},
// Changes the animation easing function
ease: function (fn) {
- this._stepper = SVG.Ease(fn)
+ this._stepper = new SVG.Ease(fn)
return this
},
active: function (enabled) {
- if(active == null) return this._enabled
+ if(enabled == null) return this._enabled
this._enabled = enabled
return this
},