mirror of https://github.com/luileito/jsketch.git
Use the new trigger API
This commit is contained in:
parent
af54d8f53f
commit
d0442c4220
|
|
@ -1 +1 @@
|
|||
!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);
|
||||
!function(a){function b(a){function b(b,c,d){var e=c[d],f=c[d+1];if(0===d||e.strokeId!==f.strokeId){if(b.data.firstPointSize){var g=d>0?f:e;b.beginFill(b.data.strokeStyle).fillCircle(g.x,g.y,b.data.firstPointSize).endFill()}d>0&&a.sketchable("trigger","animationstep"),b.closePath().beginPath()}e.strokeId===f.strokeId&&b.line(e.x,e.y,f.x,f.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,e.options.graphics),i=[],j=0;j<g.length;j++)for(var k=g[j],l=0;l<k.length;l++){var m=d(k[l]);m.strokeId||(m.strokeId=j),i.push(m)}a.sketchable("trigger","animationstart");var n,o=0;f.lineStyle(h.strokeStyle,h.lineWidth),function p(){n=requestAnimationFrame(p);try{b(f,i,o,h)}catch(c){console.error(c),cancelAnimationFrame(n)}++o===i.length-1&&(cancelAnimationFrame(n),a.sketchable("trigger","animationend"))}(),this.cancel=function(){return cancelAnimationFrame(n),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);
|
||||
|
|
@ -1 +1 @@
|
|||
!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=dataBind(a.elem)[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";Sketchable.prototype.plugins.animate=function(a){for(var d={clear:function(a,b){b.animate&&b.animate.cancel()},destroy:function(a,b){b.animate&&b.animate.cancel()}},e="clear destroy".split(" "),f=0;f<e.length;f++){var g=e[f];a.decorate(g,d[g],"animate")}deepExtend(a,{animate:{strokes:function(){var d=dataBind(a.elem)[c];return d.animate=new b(a),a}}})}}(this);
|
||||
!function(a){function b(a){function b(b,c,d){var e=c[d],f=c[d+1];if(0===d||e.strokeId!==f.strokeId){if(b.data.firstPointSize){var g=d>0?f:e;b.beginFill(b.data.strokeStyle).fillCircle(g.x,g.y,b.data.firstPointSize).endFill()}d>0&&a.trigger("animationstep"),b.closePath().beginPath()}e.strokeId===f.strokeId&&b.line(e.x,e.y,f.x,f.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=dataBind(a.elem)[c],f=e.sketch,g=e.strokes,h=(e.options.events,e.options.graphics),i=[],j=0;j<g.length;j++)for(var k=g[j],l=0;l<k.length;l++){var m=d(k[l]);m.strokeId||(m.strokeId=j),i.push(m)}a.trigger("animationstart");var n,o=0;f.lineStyle(h.strokeStyle,h.lineWidth),function p(){n=requestAnimationFrame(p);try{b(f,i,o,h)}catch(c){console.error(c),cancelAnimationFrame(n)}++o===i.length-1&&(cancelAnimationFrame(n),a.trigger("animationend"))}(),this.cancel=function(){return cancelAnimationFrame(n),this}}var c="sketchable";Sketchable.prototype.plugins.animate=function(a){for(var d={clear:function(a,b){b.animate&&b.animate.cancel()},destroy:function(a,b){b.animate&&b.animate.cancel()}},e="clear destroy".split(" "),f=0;f<e.length;f++){var g=e[f];a.decorate(g,d[g],"animate")}deepExtend(a,{animate:{strokes:function(){var d=dataBind(a.elem)[c];return d.animate=new b(a),a}}})}}(this);
|
||||
|
|
@ -37,8 +37,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (typeof events.animationstart === 'function')
|
||||
events.animationstart($instance, data);
|
||||
$instance.sketchable('trigger', 'animationstart');
|
||||
|
||||
var raf;
|
||||
var frame = 0;
|
||||
|
|
@ -57,8 +56,8 @@
|
|||
// Advance local count and check if current animation should end.
|
||||
if (++frame === fmtStrokes.length - 1) {
|
||||
cancelAnimationFrame(raf);
|
||||
if (typeof events.animationend === 'function')
|
||||
events.animationend($instance, data);
|
||||
|
||||
$instance.sketchable('trigger', 'animationend');
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
@ -91,8 +90,8 @@
|
|||
.endFill();
|
||||
}
|
||||
// Trigger step event for subsequent strokes.
|
||||
if (t > 0 && typeof events.animationstep === 'function')
|
||||
events.animationstep($instance, data);
|
||||
if (t > 0) $instance.sketchable('trigger', 'animationstep');
|
||||
|
||||
// Flag stroke change.
|
||||
sketch.closePath().beginPath();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (typeof events.animationstart === 'function')
|
||||
events.animationstart(instance, data);
|
||||
instance.trigger('animationstart');
|
||||
|
||||
var raf;
|
||||
var frame = 0;
|
||||
|
|
@ -59,8 +58,8 @@
|
|||
// Advance local count and check if current animation should end.
|
||||
if (++frame === fmtStrokes.length - 1) {
|
||||
cancelAnimationFrame(raf);
|
||||
if (typeof events.animationend === 'function')
|
||||
events.animationend(instance, data);
|
||||
|
||||
instance.trigger('animationend');
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
@ -93,8 +92,7 @@
|
|||
.endFill();
|
||||
}
|
||||
// Trigger step event for subsequent strokes.
|
||||
if (t > 0 && typeof events.animationstep === 'function')
|
||||
events.animationstep(instance, data);
|
||||
if (t > 0) instance.trigger('animationstep');
|
||||
// Flag stroke change.
|
||||
sketch.closePath().beginPath();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue