mirror of https://github.com/luileito/jsketch.git
1 line
1.4 KiB
JavaScript
1 line
1.4 KiB
JavaScript
!function(a){function b(a){function b(b,c,d){var f=c[d],g=c[d+1];if(0===d||f.strokeId!==g.strokeId){if(b.data.firstPointSize){var i=d>0?g:f;b.beginFill(b.data.strokeStyle).fillCircle(i.x,i.y,b.data.firstPointSize).endFill()}d>0&&"function"==typeof h.animationstep&&h.animationstep(a,e),b.closePath().beginPath()}f.strokeId===g.strokeId&&b.line(f.x,f.y,g.x,g.y).stroke()}function d(a){return a instanceof Array?{x:a[0],y:a[1],time:a[2],strokeId:a[4]}:a}for(var e=a.data(c),f=e.sketch,g=e.strokes,h=e.options.events,i=e.options.graphics,j=[],k=0;k<g.length;k++)for(var l=g[k],m=0;m<l.length;m++){var n=d(l[m]);n.strokeId||(n.strokeId=k),j.push(n)}"function"==typeof h.animationstart&&h.animationstart(a,e);var o,p=0;f.lineStyle(i.strokeStyle,i.lineWidth),function q(){o=requestAnimationFrame(q);try{b(f,j,p,i)}catch(c){console.error(c),cancelAnimationFrame(o)}++p===j.length-1&&(cancelAnimationFrame(o),"function"==typeof h.animationend&&h.animationend(a,e))}(),this.cancel=function(){return cancelAnimationFrame(o),this}}var c="sketchable";a.fn.sketchable.plugins.animate=function(d){for(var e={clear:function(a,b){b.animate&&b.animate.cancel()},destroy:function(a,b){b.animate&&b.animate.cancel()}},f="clear destroy".split(" "),g=0;g<f.length;g++){var h=f[g];d.sketchable("decorate",h,e[h],"animate")}a.extend(a.fn.sketchable.api,{animate:{strokes:function(){var e=a(this).data(c);return e.animate=new b(d),d}}})}}(jQuery); |