Skip to content

Commit 3260b94

Browse files
committed
added once and during
1 parent f3e1856 commit 3260b94

3 files changed

Lines changed: 105 additions & 27 deletions

File tree

dist/svg.js

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @copyright Wout Fierens <wout@impinc.co.uk>
77
* @license MIT
88
*
9-
* BUILT: Sun Dec 13 2015 00:50:41 GMT+0100 (Mitteleuropäische Zeit)
9+
* BUILT: Sun Dec 13 2015 21:40:33 GMT+0100 (Mitteleuropäische Zeit)
1010
*/;
1111
(function(root, factory) {
1212
if (typeof define === 'function' && define.amd) {
@@ -1260,6 +1260,7 @@ SVG.Situation = SVG.invent({
12601260

12611261
this.easing = SVG.easing[o.easing || '-'] || o.easing // when easing is a function, its not in SVG.easing
12621262
this.pos = 0 // position before easing
1263+
this.lastPos = 0 // needed for once callbacks
12631264
this.paused = false
12641265
this.finished = false
12651266
this.active = false
@@ -1271,6 +1272,11 @@ SVG.Situation = SVG.invent({
12711272
// this way its assured, that the start value is set correctly
12721273
}
12731274

1275+
this._once = {
1276+
// functions to fire at a specific position
1277+
// e.g. "0.5": function foo(){}
1278+
}
1279+
12741280
}
12751281

12761282
, extend: {
@@ -1295,8 +1301,6 @@ SVG.Situation = SVG.invent({
12951301

12961302
, start: function(){
12971303

1298-
1299-
13001304
if(this.fx().current() == this){
13011305
// morph values from the current position to the destination - maybe move this to another place
13021306
for(var i in this.animations){
@@ -1393,20 +1397,31 @@ SVG.Situation = SVG.invent({
13931397
if(this.pos > 1) this.pos = 1
13941398
if(this.pos < 0) this.pos = 0
13951399

1400+
var eased = this.easing(this.pos)
1401+
1402+
for(var i in this._once){
1403+
if(i > this.lastPos && i < eased) this._once[i](this.pos, eased)
1404+
}
1405+
1406+
this.fx().target.fire('during', {pos: this.pos, eased: eased})
1407+
13961408
this.eachAt(function(method, args){
13971409
this.fx().target[method].apply(this.fx().target, args)
13981410
})
13991411

14001412
if(this.pos == 1){
14011413
this.finished = true
14021414
this.active = false
1403-
var next = this.fx().next()
1404-
if(next)next.start()
1415+
this.fx().target.fire('situationfinished')
1416+
this.fx().startNext()
1417+
//var next = this.fx().next()
1418+
//if(next)next.start()
14051419
cancelAnimationFrame(this.animationFrame)
14061420
}else{
14071421
this.startAnimFrame()
14081422
}
14091423

1424+
this.lastPos = eased
14101425
return this
14111426

14121427
}
@@ -1434,6 +1449,17 @@ SVG.Situation = SVG.invent({
14341449

14351450
return this._fx
14361451
}
1452+
1453+
1454+
, once: function(pos, fn, isEased){
1455+
1456+
if(!isEased)pos = this.easing(pos)
1457+
1458+
this._once[pos] = fn
1459+
1460+
return this
1461+
}
1462+
14371463
}
14381464

14391465
})
@@ -1483,7 +1509,7 @@ SVG.FX = SVG.invent({
14831509
if(!attr) continue
14841510

14851511
// if not yet morphed we extract the destination from the array
1486-
if(attr instanceof Array) return attr[1]
1512+
//if(attr instanceof Array) return attr[1]
14871513

14881514
// otherwise from the morphed object
14891515
return attr.destination
@@ -1508,26 +1534,39 @@ SVG.FX = SVG.invent({
15081534
return this._queue[i]
15091535
}
15101536

1537+
, startNext: function() {
1538+
1539+
var next = this.next()
1540+
if(next) next.start()
1541+
else this.finish()
1542+
1543+
return this
1544+
}
1545+
15111546
, pause: function() {
1512-
this.active = false
1547+
this.current().pause()
1548+
return this
15131549
}
15141550

15151551
, play: function() {
1516-
this.reverse = false
1517-
this.active = true
1552+
this.current().play()
1553+
return this
15181554
}
15191555

1556+
/*
15201557
, resume: function() {
15211558
this.active = true
1522-
}
1559+
}*/
15231560

15241561
, finish: function() {
15251562
this.active = false
1526-
return this.progress(1)
1563+
this.target.fire('fxfinished')
1564+
return this
15271565
}
15281566

15291567
, reverse: function() {
15301568
this.reverse = true
1569+
this.current().play()
15311570
return this
15321571
}
15331572

0 commit comments

Comments
 (0)