diff --git a/dist/vivus.js b/dist/vivus.js index 23505e6..965b873 100644 --- a/dist/vivus.js +++ b/dist/vivus.js @@ -1,13 +1,13 @@ /** * vivus - JavaScript library to make drawing animation on SVG - * @version v0.4.0 + * @version v0.4.1 * @link https://github.com/maxwellito/vivus * @license MIT */ 'use strict'; -(function (window, document) { +(function () { 'use strict'; @@ -268,7 +268,7 @@ Pathformer.prototype.parseAttr = function (element) { 'use strict'; -var requestAnimFrame, cancelAnimFrame, parsePositiveInt; +var setupEnv, requestAnimFrame, cancelAnimFrame, parsePositiveInt; /** * Vivus @@ -320,6 +320,8 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt; */ function Vivus (element, options, callback) { + setupEnv(); + // Setup this.isReady = false; this.setElement(element, options); @@ -953,12 +955,6 @@ Vivus.prototype.isInViewport = function (el, h) { return (elTop + elHeight * h) <= viewed && (elBottom) >= scrolled; }; -/** - * Alias for document element - * - * @type {DOMelement} - */ -Vivus.prototype.docElem = window.document.documentElement; /** * Get the viewport height in pixels @@ -986,41 +982,55 @@ Vivus.prototype.scrollY = function () { return window.pageYOffset || this.docElem.scrollTop; }; -/** - * Alias for `requestAnimationFrame` or - * `setTimeout` function for deprecated browsers. - * - */ -requestAnimFrame = (function () { - return ( - window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function(/* function */ callback){ - return window.setTimeout(callback, 1000 / 60); - } - ); -})(); +setupEnv = function () { -/** - * Alias for `cancelAnimationFrame` or - * `cancelTimeout` function for deprecated browsers. - * - */ -cancelAnimFrame = (function () { - return ( - window.cancelAnimationFrame || - window.webkitCancelAnimationFrame || - window.mozCancelAnimationFrame || - window.oCancelAnimationFrame || - window.msCancelAnimationFrame || - function(id){ - return window.clearTimeout(id); - } - ); -})(); + if (Vivus.prototype.docElem) { + return; + } + + /** + * Alias for document element + * + * @type {DOMelement} + */ + Vivus.prototype.docElem = window.document.documentElement; + + /** + * Alias for `requestAnimationFrame` or + * `setTimeout` function for deprecated browsers. + * + */ + requestAnimFrame = (function () { + return ( + window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function(/* function */ callback){ + return window.setTimeout(callback, 1000 / 60); + } + ); + })(); + + /** + * Alias for `cancelAnimationFrame` or + * `cancelTimeout` function for deprecated browsers. + * + */ + cancelAnimFrame = (function () { + return ( + window.cancelAnimationFrame || + window.webkitCancelAnimationFrame || + window.mozCancelAnimationFrame || + window.oCancelAnimationFrame || + window.msCancelAnimationFrame || + function(id){ + return window.clearTimeout(id); + } + ); + })(); +}; /** * Parse string to integer. @@ -1054,4 +1064,4 @@ parsePositiveInt = function (value, defaultValue) { window.Vivus = Vivus; } -}(window, document)); +}()); diff --git a/dist/vivus.min.js b/dist/vivus.min.js index 57f2b07..b7f3656 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.4.0 + * @version v0.4.1 * @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(",")),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 +"use strict";!function(){function t(t){if("undefined"==typeof t)throw new Error('Pathformer [constructor]: "element" parameter is required');if(t.constructor===String&&(t=document.getElementById(t),!t))throw new Error('Pathformer [constructor]: "element" parameter is not related to an existing ID');if(!(t.constructor instanceof window.SVGElement||/^svg$/i.test(t.nodeName)))throw new Error('Pathformer [constructor]: "element" parameter must be a string or a SVGelement');this.el=t,this.scan(t)}function e(t,e,n){r(),this.isReady=!1,this.setElement(t,e),this.setOptions(e),this.setCallback(n),this.isReady&&this.init()}t.prototype.TYPES=["line","ellipse","circle","polygon","polyline","rect"],t.prototype.ATTR_WATCH=["cx","cy","points","r","rx","ry","x","x1","x2","y","y1","y2"],t.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")},e.prototype.setCallback=function(t){if(t&&t.constructor!==Function)throw new Error('Vivus [constructor]: "callback" parameter must be a function');this.callback=t||function(){}},e.prototype.mapping=function(){var t,e,r,n,i,o,s,h;for(h=o=s=0,e=this.el.querySelectorAll("path"),t=0;t1?e.length-1:1),this.reverseStack&&this.map.reverse(),t=0;t=this.frameLength))return this.trace(),this.handle=n(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)},e.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},e.prototype.getViewportH=function(){var t=this.docElem.clientHeight,e=window.innerHeight;return e>t?e:t},e.prototype.scrollY=function(){return window.pageYOffset||this.docElem.scrollTop},r=function(){e.prototype.docElem||(e.prototype.docElem=window.document.documentElement,n=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,1e3/60)}}(),i=function(){return window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame||window.oCancelAnimationFrame||window.msCancelAnimationFrame||function(t){return window.clearTimeout(t)}}())},a=function(t,e){var r=parseInt(t,10);return r>=0?r:e},"function"==typeof define&&define.amd?define([],function(){return e}):"object"==typeof exports?module.exports=e:window.Vivus=e}(); \ No newline at end of file diff --git a/package.json b/package.json index f614bae..5cd6227 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vivus", - "version": "0.4.0", + "version": "0.4.1", "description": "JavaScript library to make drawing animation on SVG", "main": "dist/vivus.js", "scripts": { diff --git a/src/vivus.js b/src/vivus.js index 6853f7c..ea41b93 100755 --- a/src/vivus.js +++ b/src/vivus.js @@ -1,6 +1,6 @@ 'use strict'; -var requestAnimFrame, cancelAnimFrame, parsePositiveInt; +var setupEnv, requestAnimFrame, cancelAnimFrame, parsePositiveInt; /** * Vivus @@ -714,7 +714,7 @@ Vivus.prototype.scrollY = function () { return window.pageYOffset || this.docElem.scrollTop; }; -var setupEnv = function () { +setupEnv = function () { if (Vivus.prototype.docElem) { return; @@ -762,7 +762,7 @@ var setupEnv = function () { } ); })(); -} +}; /** * Parse string to integer.