1
1
/**
2
2
* vivus - JavaScript library to make drawing animation on SVG
3
- * @version v0.3.2
3
+ * @version v0.4.0
4
4
* @link https://github.com/maxwellito/vivus
5
5
* @license MIT
6
6
*/
@@ -284,7 +284,7 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt;
284
284
/**
285
285
* Class constructor
286
286
* option structure
287
- * type: 'delayed'|'async '|'oneByOne'|'script' (to know if the item must be drawn asynchronously or not, default: delayed)
287
+ * type: 'delayed'|'sync '|'oneByOne'|'script' (to know if the items must be drawn synchronously or not, default: delayed)
288
288
* duration: <int> (in frames)
289
289
* start: 'inViewport'|'manual'|'autostart' (start automatically the animation, default: inViewport)
290
290
* delay: <int> (delay between the drawing of first and last path)
@@ -298,7 +298,7 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt;
298
298
* - 'delayed'
299
299
* all paths are draw at the same time but with a
300
300
* little delay between them before start
301
- * - 'async '
301
+ * - 'sync '
302
302
* all path are start and finish at the same time
303
303
* - 'oneByOne'
304
304
* only one path is draw at the time
@@ -440,7 +440,7 @@ Vivus.prototype.setElement = function (element, options) {
440
440
* @param {object } options Object from the constructor
441
441
*/
442
442
Vivus . prototype . setOptions = function ( options ) {
443
- var allowedTypes = [ 'delayed' , 'async' , 'oneByOne' , 'scenario' , 'scenario-sync' ] ;
443
+ var allowedTypes = [ 'delayed' , 'sync' , ' async' , 'nsync ', 'oneByOne' , 'scenario' , 'scenario-sync' ] ;
444
444
var allowedStarts = [ 'inViewport' , 'manual' , 'autostart' ] ;
445
445
446
446
// Basic check
@@ -467,15 +467,16 @@ Vivus.prototype.setOptions = function (options) {
467
467
this . start = options . start || allowedStarts [ 0 ] ;
468
468
}
469
469
470
- this . isIE = ( window . navigator . userAgent . indexOf ( 'MSIE' ) !== - 1 || window . navigator . userAgent . indexOf ( 'Trident/' ) !== - 1 || window . navigator . userAgent . indexOf ( 'Edge/' ) !== - 1 ) ;
471
- this . duration = parsePositiveInt ( options . duration , 120 ) ;
472
- this . delay = parsePositiveInt ( options . delay , null ) ;
473
- this . dashGap = parsePositiveInt ( options . dashGap , 1 ) ;
474
- this . forceRender = options . hasOwnProperty ( 'forceRender' ) ? ! ! options . forceRender : this . isIE ;
475
- this . selfDestroy = ! ! options . selfDestroy ;
476
- this . onReady = options . onReady ;
477
- this . map = new Array ( ) ;
478
- this . frameLength = this . currentFrame = this . delayUnit = this . speed = this . handle = null ;
470
+ this . isIE = ( window . navigator . userAgent . indexOf ( 'MSIE' ) !== - 1 || window . navigator . userAgent . indexOf ( 'Trident/' ) !== - 1 || window . navigator . userAgent . indexOf ( 'Edge/' ) !== - 1 ) ;
471
+ this . duration = parsePositiveInt ( options . duration , 120 ) ;
472
+ this . delay = parsePositiveInt ( options . delay , null ) ;
473
+ this . dashGap = parsePositiveInt ( options . dashGap , 1 ) ;
474
+ this . forceRender = options . hasOwnProperty ( 'forceRender' ) ? ! ! options . forceRender : this . isIE ;
475
+ this . reverseStack = ! ! options . reverseStack ;
476
+ this . selfDestroy = ! ! options . selfDestroy ;
477
+ this . onReady = options . onReady ;
478
+ this . map = [ ] ;
479
+ this . frameLength = this . currentFrame = this . delayUnit = this . speed = this . handle = null ;
479
480
480
481
this . ignoreInvisible = options . hasOwnProperty ( 'ignoreInvisible' ) ? ! ! options . ignoreInvisible : false ;
481
482
@@ -562,6 +563,11 @@ Vivus.prototype.mapping = function () {
562
563
this . delay = this . delay === null ? this . duration / 3 : this . delay ;
563
564
this . delayUnit = this . delay / ( paths . length > 1 ? paths . length - 1 : 1 ) ;
564
565
566
+ // Reverse stack if asked
567
+ if ( this . reverseStack ) {
568
+ this . map . reverse ( ) ;
569
+ }
570
+
565
571
for ( i = 0 ; i < this . map . length ; i ++ ) {
566
572
pathObj = this . map [ i ] ;
567
573
@@ -576,7 +582,9 @@ Vivus.prototype.mapping = function () {
576
582
pathObj . duration = pathObj . length / totalLength * this . duration ;
577
583
break ;
578
584
585
+ case 'sync' :
579
586
case 'async' :
587
+ case 'nsync' :
580
588
pathObj . startAt = 0 ;
581
589
pathObj . duration = this . duration ;
582
590
break ;
@@ -624,24 +632,25 @@ Vivus.prototype.drawer = function () {
624
632
if ( this . currentFrame <= 0 ) {
625
633
this . stop ( ) ;
626
634
this . reset ( ) ;
627
- this . callback ( this ) ;
628
- if ( this . instance_callback )
629
- this . instance_callback ( this )
630
635
} else if ( this . currentFrame >= this . frameLength ) {
631
636
this . stop ( ) ;
632
637
this . currentFrame = this . frameLength ;
633
638
this . trace ( ) ;
634
639
if ( this . selfDestroy ) {
635
640
this . destroy ( ) ;
636
641
}
637
- this . callback ( this ) ;
638
- if ( this . instance_callback )
639
- this . instance_callback ( this )
640
642
} else {
641
643
this . trace ( ) ;
642
644
this . handle = requestAnimFrame ( function ( ) {
643
645
self . drawer ( ) ;
644
646
} ) ;
647
+ return ;
648
+ }
649
+
650
+ this . callback ( this ) ;
651
+ if ( this . instanceCallback ) {
652
+ this . instanceCallback ( this ) ;
653
+ this . instanceCallback = null ;
645
654
}
646
655
} ;
647
656
@@ -813,15 +822,20 @@ Vivus.prototype.setFrameProgress = function (progress) {
813
822
* @param {number } speed Animation speed [optional]
814
823
*/
815
824
Vivus . prototype . play = function ( speed , callback ) {
816
- if ( speed && typeof speed === "function" ) {
817
- this . instance_callback = speed // first parameter is actually the callback function
818
- speed = null
819
- } else if ( speed && typeof speed !== 'number' ) {
825
+ this . instanceCallback = null ;
826
+
827
+ if ( speed && typeof speed === 'function' ) {
828
+ this . instanceCallback = speed ; // first parameter is actually the callback function
829
+ speed = null ;
830
+ }
831
+ else if ( speed && typeof speed !== 'number' ) {
820
832
throw new Error ( 'Vivus [play]: invalid speed' ) ;
821
833
}
822
834
// if the first parameter wasn't the callback, check if the seconds was
823
- if ( callback && typeof ( callback ) === "function" && ! this . instance_callback )
824
- this . instance_callback = callback ;
835
+ if ( callback && typeof ( callback ) === 'function' && ! this . instanceCallback ) {
836
+ this . instanceCallback = callback ;
837
+ }
838
+
825
839
826
840
this . speed = speed || 1 ;
827
841
if ( ! this . handle ) {
0 commit comments