diff --git a/dist/vivus.js b/dist/vivus.js index 97ddf80..23505e6 100644 --- a/dist/vivus.js +++ b/dist/vivus.js @@ -1,6 +1,6 @@ /** * vivus - JavaScript library to make drawing animation on SVG - * @version v0.3.2 + * @version v0.4.0 * @link https://github.com/maxwellito/vivus * @license MIT */ @@ -284,7 +284,7 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt; /** * Class constructor * option structure - * type: 'delayed'|'async'|'oneByOne'|'script' (to know if the item must be drawn asynchronously or not, default: delayed) + * type: 'delayed'|'sync'|'oneByOne'|'script' (to know if the items must be drawn synchronously or not, default: delayed) * duration: (in frames) * start: 'inViewport'|'manual'|'autostart' (start automatically the animation, default: inViewport) * delay: (delay between the drawing of first and last path) @@ -298,7 +298,7 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt; * - 'delayed' * all paths are draw at the same time but with a * little delay between them before start - * - 'async' + * - 'sync' * all path are start and finish at the same time * - 'oneByOne' * only one path is draw at the time @@ -440,7 +440,7 @@ Vivus.prototype.setElement = function (element, options) { * @param {object} options Object from the constructor */ Vivus.prototype.setOptions = function (options) { - var allowedTypes = ['delayed', 'async', 'oneByOne', 'scenario', 'scenario-sync']; + var allowedTypes = ['delayed', 'sync', 'async', 'nsync', 'oneByOne', 'scenario', 'scenario-sync']; var allowedStarts = ['inViewport', 'manual', 'autostart']; // Basic check @@ -467,15 +467,16 @@ Vivus.prototype.setOptions = function (options) { this.start = options.start || allowedStarts[0]; } - this.isIE = (window.navigator.userAgent.indexOf('MSIE') !== -1 || window.navigator.userAgent.indexOf('Trident/') !== -1 || window.navigator.userAgent.indexOf('Edge/') !== -1 ); - this.duration = parsePositiveInt(options.duration, 120); - this.delay = parsePositiveInt(options.delay, null); - this.dashGap = parsePositiveInt(options.dashGap, 1); - this.forceRender = options.hasOwnProperty('forceRender') ? !!options.forceRender : this.isIE; - this.selfDestroy = !!options.selfDestroy; - this.onReady = options.onReady; - this.map = new Array(); - this.frameLength = this.currentFrame = this.delayUnit = this.speed = this.handle = null; + this.isIE = (window.navigator.userAgent.indexOf('MSIE') !== -1 || window.navigator.userAgent.indexOf('Trident/') !== -1 || window.navigator.userAgent.indexOf('Edge/') !== -1 ); + this.duration = parsePositiveInt(options.duration, 120); + this.delay = parsePositiveInt(options.delay, null); + this.dashGap = parsePositiveInt(options.dashGap, 1); + this.forceRender = options.hasOwnProperty('forceRender') ? !!options.forceRender : this.isIE; + this.reverseStack = !!options.reverseStack; + this.selfDestroy = !!options.selfDestroy; + this.onReady = options.onReady; + this.map = []; + this.frameLength = this.currentFrame = this.delayUnit = this.speed = this.handle = null; this.ignoreInvisible = options.hasOwnProperty('ignoreInvisible') ? !!options.ignoreInvisible : false; @@ -562,6 +563,11 @@ Vivus.prototype.mapping = function () { this.delay = this.delay === null ? this.duration / 3 : this.delay; this.delayUnit = this.delay / (paths.length > 1 ? paths.length - 1 : 1); + // Reverse stack if asked + if (this.reverseStack) { + this.map.reverse(); + } + for (i = 0; i < this.map.length; i++) { pathObj = this.map[i]; @@ -576,7 +582,9 @@ Vivus.prototype.mapping = function () { pathObj.duration = pathObj.length / totalLength * this.duration; break; + case 'sync': case 'async': + case 'nsync': pathObj.startAt = 0; pathObj.duration = this.duration; break; @@ -624,9 +632,6 @@ Vivus.prototype.drawer = function () { if (this.currentFrame <= 0) { this.stop(); this.reset(); - this.callback(this); - if (this.instance_callback) - this.instance_callback(this) } else if (this.currentFrame >= this.frameLength) { this.stop(); this.currentFrame = this.frameLength; @@ -634,14 +639,18 @@ Vivus.prototype.drawer = function () { if (this.selfDestroy) { this.destroy(); } - this.callback(this); - if (this.instance_callback) - this.instance_callback(this) } else { this.trace(); this.handle = requestAnimFrame(function () { self.drawer(); }); + return; + } + + this.callback(this); + if (this.instanceCallback) { + this.instanceCallback(this); + this.instanceCallback = null; } }; @@ -813,15 +822,20 @@ Vivus.prototype.setFrameProgress = function (progress) { * @param {number} speed Animation speed [optional] */ Vivus.prototype.play = function (speed, callback) { - if (speed && typeof speed === "function") { - this.instance_callback = speed // first parameter is actually the callback function - speed = null - } else if (speed && typeof speed !== 'number') { + this.instanceCallback = null; + + if (speed && typeof speed === 'function') { + this.instanceCallback = speed; // first parameter is actually the callback function + speed = null; + } + else if (speed && typeof speed !== 'number') { throw new Error('Vivus [play]: invalid speed'); } // if the first parameter wasn't the callback, check if the seconds was - if (callback && typeof(callback) === "function" && !this.instance_callback) - this.instance_callback = callback; + if (callback && typeof(callback) === 'function' && !this.instanceCallback) { + this.instanceCallback = callback; + } + this.speed = speed || 1; if (!this.handle) { diff --git a/dist/vivus.min.js b/dist/vivus.min.js index bff4133..57f2b07 100644 --- a/dist/vivus.min.js +++ b/dist/vivus.min.js @@ -1,7 +1,7 @@ /** * vivus - JavaScript library to make drawing animation on SVG - * @version v0.3.2 + * @version v0.4.0 * @link https://github.com/maxwellito/vivus * @license MIT */ -"use strict";!function(t,e){function r(r){if("undefined"==typeof r)throw new Error('Pathformer [constructor]: "element" parameter is required');if(r.constructor===String&&(r=e.getElementById(r),!r))throw new Error('Pathformer [constructor]: "element" parameter is not related to an existing ID');if(!(r.constructor instanceof t.SVGElement||/^svg$/i.test(r.nodeName)))throw new Error('Pathformer [constructor]: "element" parameter must be a string or a SVGelement');this.el=r,this.scan(r)}function n(t,e,r){this.isReady=!1,this.setElement(t,e),this.setOptions(e),this.setCallback(r),this.isReady&&this.init()}r.prototype.TYPES=["line","ellipse","circle","polygon","polyline","rect"],r.prototype.ATTR_WATCH=["cx","cy","points","r","rx","ry","x","x1","x2","y","y1","y2"],r.prototype.scan=function(t){for(var e,r,n,i,a=t.querySelectorAll(this.TYPES.join(",")),o=0;o=this.duration)throw new Error("Vivus [constructor]: delay must be shorter than duration")},n.prototype.setCallback=function(t){if(t&&t.constructor!==Function)throw new Error('Vivus [constructor]: "callback" parameter must be a function');this.callback=t||function(){}},n.prototype.mapping=function(){var e,r,n,i,a,s,h,l;for(l=s=h=0,r=this.el.querySelectorAll("path"),e=0;e1?r.length-1:1),e=0;e=this.frameLength?(this.stop(),this.currentFrame=this.frameLength,this.trace(),this.selfDestroy&&this.destroy(),this.callback(this)):(this.trace(),this.handle=i(function(){t.drawer()}))},n.prototype.trace=function(){var t,e,r,n;for(n=this.animTimingFunction(this.currentFrame/this.frameLength)*this.frameLength,t=0;t=o+a*e&&s>=r},n.prototype.docElem=t.document.documentElement,n.prototype.getViewportH=function(){var e=this.docElem.clientHeight,r=t.innerHeight;return r>e?r:e},n.prototype.scrollY=function(){return t.pageYOffset||this.docElem.scrollTop},i=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){return t.setTimeout(e,1e3/60)}}(),a=function(){return t.cancelAnimationFrame||t.webkitCancelAnimationFrame||t.mozCancelAnimationFrame||t.oCancelAnimationFrame||t.msCancelAnimationFrame||function(e){return t.clearTimeout(e)}}(),o=function(t,e){var r=parseInt(t,10);return r>=0?r:e},"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:t.Vivus=n}(window,document); +"use strict";!function(t,e){function r(r){if("undefined"==typeof r)throw new Error('Pathformer [constructor]: "element" parameter is required');if(r.constructor===String&&(r=e.getElementById(r),!r))throw new Error('Pathformer [constructor]: "element" parameter is not related to an existing ID');if(!(r.constructor instanceof t.SVGElement||/^svg$/i.test(r.nodeName)))throw new Error('Pathformer [constructor]: "element" parameter must be a string or a SVGelement');this.el=r,this.scan(r)}function n(t,e,r){this.isReady=!1,this.setElement(t,e),this.setOptions(e),this.setCallback(r),this.isReady&&this.init()}r.prototype.TYPES=["line","ellipse","circle","polygon","polyline","rect"],r.prototype.ATTR_WATCH=["cx","cy","points","r","rx","ry","x","x1","x2","y","y1","y2"],r.prototype.scan=function(t){for(var e,r,n,i,a=t.querySelectorAll(this.TYPES.join(",")),s=0;s=this.duration)throw new Error("Vivus [constructor]: delay must be shorter than duration")},n.prototype.setCallback=function(t){if(t&&t.constructor!==Function)throw new Error('Vivus [constructor]: "callback" parameter must be a function');this.callback=t||function(){}},n.prototype.mapping=function(){var e,r,n,i,a,o,h,l;for(l=o=h=0,r=this.el.querySelectorAll("path"),e=0;e1?r.length-1:1),this.reverseStack&&this.map.reverse(),e=0;e=this.frameLength))return this.trace(),this.handle=i(function(){t.drawer()}),void 0;this.stop(),this.currentFrame=this.frameLength,this.trace(),this.selfDestroy&&this.destroy()}this.callback(this),this.instanceCallback&&(this.instanceCallback(this),this.instanceCallback=null)},n.prototype.trace=function(){var t,e,r,n;for(n=this.animTimingFunction(this.currentFrame/this.frameLength)*this.frameLength,t=0;t=s+a*e&&o>=r},n.prototype.docElem=t.document.documentElement,n.prototype.getViewportH=function(){var e=this.docElem.clientHeight,r=t.innerHeight;return r>e?r:e},n.prototype.scrollY=function(){return t.pageYOffset||this.docElem.scrollTop},i=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){return t.setTimeout(e,1e3/60)}}(),a=function(){return t.cancelAnimationFrame||t.webkitCancelAnimationFrame||t.mozCancelAnimationFrame||t.oCancelAnimationFrame||t.msCancelAnimationFrame||function(e){return t.clearTimeout(e)}}(),s=function(t,e){var r=parseInt(t,10);return r>=0?r:e},"function"==typeof define&&define.amd?define([],function(){return n}):"object"==typeof exports?module.exports=n:t.Vivus=n}(window,document); \ No newline at end of file diff --git a/package.json b/package.json index dc97d15..f614bae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vivus", - "version": "0.3.2", + "version": "0.4.0", "description": "JavaScript library to make drawing animation on SVG", "main": "dist/vivus.js", "scripts": {