Skip to content

Commit d25190b

Browse files
committed
v0.4.0
1 parent 04e182f commit d25190b

File tree

3 files changed

+42
-28
lines changed

3 files changed

+42
-28
lines changed

dist/vivus.js

+39-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* vivus - JavaScript library to make drawing animation on SVG
3-
* @version v0.3.2
3+
* @version v0.4.0
44
* @link https://github.com/maxwellito/vivus
55
* @license MIT
66
*/
@@ -284,7 +284,7 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt;
284284
/**
285285
* Class constructor
286286
* 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)
288288
* duration: <int> (in frames)
289289
* start: 'inViewport'|'manual'|'autostart' (start automatically the animation, default: inViewport)
290290
* delay: <int> (delay between the drawing of first and last path)
@@ -298,7 +298,7 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt;
298298
* - 'delayed'
299299
* all paths are draw at the same time but with a
300300
* little delay between them before start
301-
* - 'async'
301+
* - 'sync'
302302
* all path are start and finish at the same time
303303
* - 'oneByOne'
304304
* only one path is draw at the time
@@ -440,7 +440,7 @@ Vivus.prototype.setElement = function (element, options) {
440440
* @param {object} options Object from the constructor
441441
*/
442442
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'];
444444
var allowedStarts = ['inViewport', 'manual', 'autostart'];
445445

446446
// Basic check
@@ -467,15 +467,16 @@ Vivus.prototype.setOptions = function (options) {
467467
this.start = options.start || allowedStarts[0];
468468
}
469469

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;
479480

480481
this.ignoreInvisible = options.hasOwnProperty('ignoreInvisible') ? !!options.ignoreInvisible : false;
481482

@@ -562,6 +563,11 @@ Vivus.prototype.mapping = function () {
562563
this.delay = this.delay === null ? this.duration / 3 : this.delay;
563564
this.delayUnit = this.delay / (paths.length > 1 ? paths.length - 1 : 1);
564565

566+
// Reverse stack if asked
567+
if (this.reverseStack) {
568+
this.map.reverse();
569+
}
570+
565571
for (i = 0; i < this.map.length; i++) {
566572
pathObj = this.map[i];
567573

@@ -576,7 +582,9 @@ Vivus.prototype.mapping = function () {
576582
pathObj.duration = pathObj.length / totalLength * this.duration;
577583
break;
578584

585+
case 'sync':
579586
case 'async':
587+
case 'nsync':
580588
pathObj.startAt = 0;
581589
pathObj.duration = this.duration;
582590
break;
@@ -624,24 +632,25 @@ Vivus.prototype.drawer = function () {
624632
if (this.currentFrame <= 0) {
625633
this.stop();
626634
this.reset();
627-
this.callback(this);
628-
if (this.instance_callback)
629-
this.instance_callback(this)
630635
} else if (this.currentFrame >= this.frameLength) {
631636
this.stop();
632637
this.currentFrame = this.frameLength;
633638
this.trace();
634639
if (this.selfDestroy) {
635640
this.destroy();
636641
}
637-
this.callback(this);
638-
if (this.instance_callback)
639-
this.instance_callback(this)
640642
} else {
641643
this.trace();
642644
this.handle = requestAnimFrame(function () {
643645
self.drawer();
644646
});
647+
return;
648+
}
649+
650+
this.callback(this);
651+
if (this.instanceCallback) {
652+
this.instanceCallback(this);
653+
this.instanceCallback = null;
645654
}
646655
};
647656

@@ -813,15 +822,20 @@ Vivus.prototype.setFrameProgress = function (progress) {
813822
* @param {number} speed Animation speed [optional]
814823
*/
815824
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') {
820832
throw new Error('Vivus [play]: invalid speed');
821833
}
822834
// 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+
825839

826840
this.speed = speed || 1;
827841
if (!this.handle) {

0 commit comments

Comments
 (0)