/* * Lazy Line Painter * SVG Stroke animation. * * https://github.com/camoconnell/lazy-line-painter * http://www.camoconnell.com * * Licensed under the MIT license. * */ (function(e,t,n){"use strict";var r="lazyLinePainter";var s={init:function(t){return this.each(function(){var n=e(this);var i=n.data(r);n.addClass("lazy-line");if(!i){var s=e.extend({width:null,height:null,strokeWidth:2,strokeColor:"#000",strokeOverColor:null,strokeCap:"round",strokeJoin:"round",strokeOpacity:1,arrowEnd:"none",strokeDash:null,onComplete:null,delay:null,overrideKey:null,drawSequential:true,speedMultiplier:1},t);var o=s.overrideKey?s.overrideKey:n.attr("id").replace("#","");var u=s.svgData[o].dimensions.width;var a=s.svgData[o].dimensions.height;s.svgData=s.svgData[o].strokepath;if(s.width===null){s.width=u}if(s.height===null){s.height=a}var f=c({viewBox:"0 0 "+u+" "+a,preserveAspectRatio:"xMidYMid"});s.svg=e(f);n.append(s.svg);n.data(r,s)}})},paint:function(){return this.each(function(){var t=e(this);var n=t.data(r);var i=function(){t.css({width:n.width,height:n.height});n.paths=[];n.longestDuration=0;n.playhead=0;for(var e=0;en.longestDuration){n.longestDuration=s}n.paths.push({duration:s,drawStartTime:n.playhead,path:r,length:i});n.playhead+=s}n.totalDuration=n.drawSequential?n.playhead:n.longestDuration;n.rAF=requestAnimationFrame(function(e){u(e,n)})};if(n.delay===null){i()}else{setTimeout(i,n.delay)}})},pauseResume:function(){return this.each(function(){var t=e(this).data(r);if(!t.paused){t.paused=true;cancelAnimationFrame(t.rAF)}else{t.paused=false;requestAnimationFrame(function(e){o(e,t)})}})},erase:function(){return this.each(function(){var t=e(this);t.removeData(r);t.find("svg").empty()})},destroy:function(){return this.each(function(){var t=e(this);t.removeData(r);t.remove()})},stamp:function(){return this.each(function(){var t=e(this),n=t.data(r);var s=function(){t.css({width:n.width,height:n.height});for(i=0;i0){var i=r/t.paths[n].duration*t.paths[n].length;t.paths[n].path.style.strokeDashoffset=t.paths[n].length-i}else if(r>t.paths[n].duration){t.paths[n].path.style.strokeDashoffset=0}}if(t.elapsed_time