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