From 56a39b44ddfea3f97044d3ca0c06787430796c01 Mon Sep 17 00:00:00 2001 From: maxwellito Date: Mon, 21 Sep 2015 01:10:41 +0100 Subject: [PATCH] v0.2.3 --- dist/vivus.js | 60 ++++++++++++++++++++++++++++++++++++----------- dist/vivus.min.js | 4 ++-- package.json | 2 +- readme.md | 2 +- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/dist/vivus.js b/dist/vivus.js index fc0c9aa..a8407a2 100644 --- a/dist/vivus.js +++ b/dist/vivus.js @@ -1,6 +1,6 @@ /** * vivus - JavaScript library to make drawing animation on SVG - * @version v0.2.2 + * @version v0.2.3 * @link https://github.com/maxwellito/vivus * @license MIT */ @@ -56,7 +56,7 @@ function Pathformer(element) { * * @type {Array} */ -Pathformer.prototype.TYPES = ['line', 'elipse', 'circle', 'polygon', 'polyline', 'rect']; +Pathformer.prototype.TYPES = ['line', 'ellipse', 'circle', 'polygon', 'polyline', 'rect']; /** * List of attribute names which contain @@ -131,7 +131,7 @@ Pathformer.prototype.rectToPath = function (element) { Pathformer.prototype.polylineToPath = function (element) { var i, path; var newElement = {}; - var points = element.points.split(' '); + var points = element.points.trim().split(' '); // Reformatting if points are defined without commas if (element.points.indexOf(',') === -1) { @@ -170,13 +170,13 @@ Pathformer.prototype.polygonToPath = function (element) { }; /** - * Read `elipse` element to extract and transform + * Read `ellipse` element to extract and transform * data, to make it ready for a `path` object. * - * @param {DOMelement} element Elipse element to transform + * @param {DOMelement} element ellipse element to transform * @return {object} Data for a `path` element */ -Pathformer.prototype.elipseToPath = function (element) { +Pathformer.prototype.ellipseToPath = function (element) { var startX = element.cx - element.rx, startY = element.cy; var endX = parseFloat(element.cx) + parseFloat(element.rx), @@ -368,6 +368,8 @@ Vivus.prototype.setElement = function (element, options) { var objElm = document.createElement('object'); objElm.setAttribute('type', 'image/svg+xml'); objElm.setAttribute('data', options.file); + objElm.setAttribute('width', '100%'); + objElm.setAttribute('height', '100%'); element.appendChild(objElm); element = objElm; } @@ -441,7 +443,7 @@ Vivus.prototype.setOptions = function (options) { this.start = options.start || allowedStarts[0]; } - this.isIE = (window.navigator.userAgent.indexOf('MSIE') !== -1); + 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, 2); @@ -449,6 +451,8 @@ Vivus.prototype.setOptions = function (options) { this.selfDestroy = !!options.selfDestroy; this.onReady = options.onReady; + this.ignoreInvisible = options.hasOwnProperty('ignoreInvisible') ? !!options.ignoreInvisible : false; + this.animTimingFunction = options.animTimingFunction || Vivus.LINEAR; this.pathTimingFunction = options.pathTimingFunction || Vivus.LINEAR; @@ -505,6 +509,9 @@ Vivus.prototype.mapping = function () { for (i = 0; i < paths.length; i++) { path = paths[i]; + if (this.isInvisible(path)) { + continue; + } pathObj = { el: path, length: Math.ceil(path.getTotalLength()) @@ -732,12 +739,6 @@ Vivus.prototype.getStatus = function () { return this.currentFrame === 0 ? 'start' : this.currentFrame === this.frameLength ? 'end' : 'progress'; }; - -/** - * Controls - ************************************** - */ - /** * Reset the instance to the initial state : undraw * Be careful, it just reset the animation, if you're @@ -827,10 +828,41 @@ Vivus.prototype.destroy = function () { /** * Utils methods - * from Codrops + * include methods from Codrops ************************************** */ +/** + * Method to best guess if a path should added into + * the animation or not. + * + * 1. Use the `data-vivus-ignore` attribute if set + * 2. Check if the instance must ignore invisible paths + * 3. Check if the path is visible + * + * For now the visibility checking is unstable. + * It will be used for a beta phase. + * + * Other improvments are planned. Like detecting + * is the path got a stroke or a valid opacity. + */ +Vivus.prototype.isInvisible = function (el) { + var rect, + ignoreAttr = el.getAttribute('data-ignore'); + + if (ignoreAttr !== null) { + return ignoreAttr !== 'false'; + } + + if (this.ignoreInvisible) { + rect = el.getBoundingClientRect(); + return !rect.width && !rect.height; + } + else { + return false; + } +}; + /** * Parse attributes of a DOM element to * get an object of {attributeName => attributeValue} diff --git a/dist/vivus.min.js b/dist/vivus.min.js index 85ec47c..977ac64 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.2.2 + * @version v0.2.3 * @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","elipse","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,c;for(c=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); \ No newline at end of file +"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,u;for(u=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); \ No newline at end of file diff --git a/package.json b/package.json index 66067fa..1ef94e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vivus", - "version": "0.2.2", + "version": "0.2.3", "description": "JavaScript library to make drawing animation on SVG", "main": "dist/vivus.js", "scripts": { diff --git a/readme.md b/readme.md index e77baa0..3d14b41 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ Available via: - [Bower](http://bower.io/): `bower install vivus` - [NPM](https://www.npmjs.com/package/vivus): `npm install vivus` - [SPM](http://spmjs.io/package/vivus): `spm install vivus` - - [jsDelivr CDN](http://www.jsdelivr.com/#!vivus): `//cdn.jsdelivr.net/vivus/0.2.2/vivus.min.js` + - [jsDelivr CDN](http://www.jsdelivr.com/#!vivus): `//cdn.jsdelivr.net/vivus/latest/vivus.min.js` - [WebJars](http://www.webjars.org/) Join the conversation on [Gitter](https://gitter.im/maxwellito/vivus)