diff --git a/dist/jquery.sketchable.full.min.js b/dist/jquery.sketchable.full.min.js index 60684b4..e145f3c 100644 --- a/dist/jquery.sketchable.full.min.js +++ b/dist/jquery.sketchable.full.min.js @@ -1,2 +1,2 @@ /*! jSketch drawing lib (all in one) | v1.8.0 | 2016-11-27 */ -!function(a){var b=function(a,b){return new c(a,b)},c=function(a,b){return a?(this.context(a),this.stageWidth=a.width,this.stageHeight=a.height,this.data={},this.drawingDefaults(b),this):void 0};b.fn=c.prototype={context:function(a){if(null===a)throw"No canvas element specified.";return this.canvas=a,this.graphics=a.getContext("2d"),this},drawingDefaults:function(a){return"undefined"==typeof a&&(a={}),"undefined"==typeof a.fillStyle&&(a.fillStyle="#F00"),"undefined"==typeof a.strokeStyle&&(a.strokeStyle="#F0F"),"undefined"==typeof a.lineWidth&&(a.lineWidth=2),"undefined"==typeof a.lineCap&&(a.lineCap="round"),"undefined"==typeof a.lineJoin&&(a.lineJoin="round"),"undefined"==typeof a.miterLimit&&(a.miterLimit=10),this.saveGraphics(a),this.restoreGraphics(a),this},size:function(a,b){return this.stageWidth=a,this.stageHeight=b,this.canvas.width=a,this.canvas.height=b,this.restoreGraphics(),this},background:function(a){return this.beginFill(a),this.graphics.fillRect(0,0,this.stageWidth,this.stageHeight),this.endFill(),this},stage:function(a,b,c){return this.size(a,b).background(c),this},beginFill:function(a){return this.saveGraphics(),this.graphics.fillStyle=a,this},endFill:function(){return this.restoreGraphics(),this},lineStyle:function(a,b,c,d,e){var f={strokeStyle:a||this.graphics.strokeStyle,lineWidth:b||this.graphics.lineWidth,lineCap:c||this.graphics.lineCap,lineJoin:d||this.graphics.lineJoin,miterLimit:e||this.graphics.miterLimit};return this.saveGraphics(f),this.restoreGraphics(f),this},moveTo:function(a,b){return this.graphics.moveTo(a,b),this},lineTo:function(a,b){return this.graphics.lineTo(a,b),this},line:function(a,b,c,d){return this.graphics.moveTo(a,b),this.lineTo(c,d),this},curveTo:function(a,b,c,d){return this.graphics.quadraticCurveTo(c,d,a,b),this},curve:function(a,b,c,d,e,f){return this.graphics.moveTo(a,b),this.curveTo(c,d,e,f),this},stroke:function(){return this.graphics.stroke(),this},strokeRect:function(a,b,c,d){return this.graphics.beginPath(),this.graphics.strokeRect(a,b,c,d),this.graphics.closePath(),this},fillRect:function(a,b,c,d){return this.graphics.beginPath(),this.graphics.fillRect(a,b,c,d),this.graphics.closePath(),this},strokeCircle:function(a,b,c){return this.graphics.beginPath(),this.graphics.arc(a,b,c,0,2*Math.PI,!1),this.graphics.stroke(),this.graphics.closePath(),this},fillCircle:function(a,b,c){return this.graphics.beginPath(),this.graphics.arc(a,b,c,0,2*Math.PI,!1),this.graphics.fill(),this.graphics.closePath(),this},radialCircle:function(a,b,c,d,e){var f=this.graphics.createRadialGradient(a,b,c,a,b,e);return f.addColorStop(0,d),f.addColorStop(1,"rgba(0,0,0,0)"),this.graphics.fillStyle=f,this.fillCircle(a,b,c),this},beginPath:function(){return this.saveGraphics(),this.graphics.beginPath(),this},closePath:function(){return this.graphics.closePath(),this.restoreGraphics(),this},eraser:function(a){return"undefined"==typeof a&&(a=15),this.graphics.globalCompositeOperation="destination-out",this.lineStyle(null,a),this},pencil:function(a){return"undefined"==typeof a&&(a=2),this.graphics.globalCompositeOperation="source-over",this.lineStyle(null,a),this},clear:function(){return this.graphics.clearRect(0,0,this.stageWidth,this.stageHeight),this},save:function(){return this.graphics.save(),this},restore:function(){return this.graphics.restore(),this},saveGraphics:function(a){return"undefined"==typeof a&&(a=this.data.options),this.data.options=a,this},restoreGraphics:function(a){"undefined"==typeof a&&(a=this.data.options);for(var b in a)this.graphics[b]=a[b];return this},drawImage:function(a,b,c){"undefined"==typeof b&&(b=0),"undefined"==typeof c&&(c=0);var d=this,e=new Image;return e.src=a,e.onload=function(){d.graphics.drawImage(e,b,c)},this}},a.jSketch=b}(this),function(a){function b(b){var c=a(b.target),d=c.offset();return{x:Math.round(b.pageX-d.left),y:Math.round(b.pageY-d.top)}}function c(a,b,c){b.coords[a]||(b.coords[a]=[]);var d=(new Date).getTime();b.options.relTimestamps&&(0===b.strokes.length&&0===b.coords[a].length&&(b.timestamp=d),d-=b.timestamp),b.coords[a].push([c.x,c.y,d,+b.sketch.isDrawing])}function d(a){return a.originalEvent.touches?!1:void k(a)}function e(a){return a.originalEvent.touches?!1:void l(a)}function f(a){return a.originalEvent.touches?!1:void m(a)}function g(b,c){var d=a(b.target),e=d.data(n),f=e.options,g=b.originalEvent.changedTouches;if(f.multitouch)for(var h=0;h0&&g.sketch.fillCircle(i.x,i.y,h.graphics.firstPointSize),g.coords[e]||(g.coords[e]=[]),g.coords[e].length>0&&(g.strokes.push(g.coords[e]),g.coords[e]=[]),c(e,g,i),"function"==typeof h.events.mousedown&&h.events.mousedown(f,g,d)}}function l(d){var e=d.identifier||0,f=a(d.target),g=f.data(n),h=g.options;if(h.interactive&&(h.mouseupMovements&&0!==g.strokes.length||g.sketch.isDrawing)){var i=b(d);if(g.sketch.isDrawing){var j=g.coords[e][g.coords[e].length-1];g.sketch.beginPath().line(j[0],j[1],i.x,i.y).stroke().closePath()}c(e,g,i),"function"==typeof h.events.mousemove&&h.events.mousemove(f,g,d)}}function m(b){var c=b.identifier||0,d=a(b.target),e=d.data(n),f=e.options;f.interactive&&(e.sketch.isDrawing=!1,e.strokes.push(e.coords[c]),e.coords[c]=[],"function"==typeof f.events.mouseup&&f.events.mouseup(d,e,b))}var n="sketchable",o={init:function(b){var c=a.extend(!0,{},a.fn.sketchable.defaults,b||{});return this.each(function(){var b=a(this),g=b.data(n);g||(c.interactive&&(b.bind("mousedown",d),b.bind("mousemove",e),b.bind("mouseup",f),b.bind("touchstart",h),b.bind("touchmove",i),b.bind("touchend",j),this.onselectstart=function(){return!1}),c.cssCursors&&(b[0].style.cursor=c.interactive?"pointer":"not-allowed"));var k=new jSketch(this,c.graphics);b.data(n,{strokes:[],coords:{},timestamp:(new Date).getTime(),sketch:k,options:c}),"function"==typeof c.events.init&&c.events.init(b,b.data(n))})},config:function(b){return this.each(function(){var c=a(this),d=c.data(n);d.options=a.extend(!0,{},a.fn.sketchable.defaults,b||{})})},strokes:function(b){if(b)return this.each(function(){var c=a(this),d=c.data(n);d.strokes=b});var c=a(this).data(n);return c.strokes},handler:function(b){return this.each(function(){var c=a(this),d=c.data(n);b(c,d)})},clear:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},d=c.options;c.sketch&&(c.sketch.clear(),c.strokes=[],c.coords={}),d&&"function"==typeof d.events.clear&&d.events.clear(b,c)})},reset:function(b){return this.each(function(){var c=a(this),d=c.data(n)||{},e=d.options;c.sketchable("destroy").sketchable(b),e&&"function"==typeof e.events.reset&&e.events.reset(c,d)})},destroy:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},g=c.options;g.interactive&&(b.unbind("mouseup",f),b.unbind("mousemove",e),b.unbind("mousedown",d),b.unbind("touchstart",h),b.unbind("touchmove",i),b.unbind("touchend",j)),b.removeData(n),g&&"function"==typeof g.events.destroy&&g.events.destroy(b,c)})}};a.fn.sketchable=function(b){return"methods functions hooks".split(" ").indexOf(b)>-1?o:o[b]?o[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error("Method "+b+' does not exist. See jQuery.sketchable("methods").'),this):o.init.apply(this,arguments)},a.fn.sketchable.defaults={interactive:!0,mouseupMovements:!1,relTimestamps:!1,multitouch:!0,cssCursors:!0,events:{},graphics:{firstPointSize:3,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F",lineCap:"round",lineJoin:"round",miterLimit:10}}}(jQuery),function(a){function b(b,g){function h(a){if(i&&i.events&&"function"==typeof i.events[a]){var c=i.events[a];i.events[a]=function(){var d=Array.prototype.slice.call(arguments,0);c.apply(b,d),j[a].apply(b,d)}}else i.events[a]=j[a]}var i=a.extend(!0,{},e.defaults,g);if(!i.interactive)return g;var j={init:function(a,b){b.memento=new c(a),b.memento.save(),b.memento.init()},clear:function(a,b){b.memento.save()},mouseup:function(a,b,c){b.memento.save()},destroy:function(a,b){b.memento.destroy()}};if(!e.isMementoReady){for(var k="init mouseup clear destroy".split(" "),l=0;l0){h--;var a=new Image;a.src=g[h].image,a.onload=function(){e(this)}}}function d(){if(h0&&g.sketch.fillCircle(i.x,i.y,h.graphics.firstPointSize),g.coords[e]||(g.coords[e]=[]),g.coords[e].length>0&&(g.strokes.push(g.coords[e]),g.coords[e]=[]),c(e,g,i),"function"==typeof h.events.mousedown&&h.events.mousedown(f,g,d)}}function l(d){var e=d.identifier||0,f=a(d.target),g=f.data(n),h=g.options;if(h.interactive&&(h.mouseupMovements&&0!==g.strokes.length||g.sketch.isDrawing)){var i=b(d);if(g.sketch.isDrawing){var j=g.coords[e][g.coords[e].length-1];g.sketch.beginPath().line(j[0],j[1],i.x,i.y).stroke().closePath()}c(e,g,i),"function"==typeof h.events.mousemove&&h.events.mousemove(f,g,d)}}function m(b){var c=b.identifier||0,d=a(b.target),e=d.data(n),f=e.options;f.interactive&&(e.sketch.isDrawing=!1,e.strokes.push(e.coords[c]),e.coords[c]=[],"function"==typeof f.events.mouseup&&f.events.mouseup(d,e,b))}var n="sketchable",o={init:function(b){var c=a.extend(!0,{},a.fn.sketchable.defaults,b||{});return this.each(function(){var b=a(this),g=b.data(n);g||(c.interactive&&(b.bind("mousedown",d),b.bind("mousemove",e),b.bind("mouseup",f),b.bind("touchstart",h),b.bind("touchmove",i),b.bind("touchend",j),this.onselectstart=function(){return!1}),c.cssCursors&&(b[0].style.cursor=c.interactive?"pointer":"not-allowed"));var k=new jSketch(this,c.graphics);b.data(n,{strokes:[],coords:{},timestamp:(new Date).getTime(),sketch:k,options:c}),"function"==typeof c.events.init&&c.events.init(b,b.data(n))})},config:function(b){return this.each(function(){var c=a(this),d=c.data(n);d.options=a.extend(!0,b||{},a.fn.sketchable.defaults,d.options)})},strokes:function(b){if(b)return this.each(function(){var c=a(this),d=c.data(n);d.strokes=b});var c=a(this).data(n);return c.strokes},handler:function(b){return this.each(function(){var c=a(this),d=c.data(n);b(c,d)})},clear:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},d=c.options;c.sketch&&(c.sketch.clear(),c.strokes=[],c.coords={}),d&&"function"==typeof d.events.clear&&d.events.clear(b,c)})},reset:function(b){return this.each(function(){var c=a(this),d=c.data(n)||{},e=d.options;c.sketchable("destroy").sketchable(b),e&&"function"==typeof e.events.reset&&e.events.reset(c,d)})},destroy:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},g=c.options;g.interactive&&(b.unbind("mouseup",f),b.unbind("mousemove",e),b.unbind("mousedown",d),b.unbind("touchstart",h),b.unbind("touchmove",i),b.unbind("touchend",j)),b.removeData(n),g&&"function"==typeof g.events.destroy&&g.events.destroy(b,c)})}};a.fn.sketchable=function(b){return"methods functions hooks".split(" ").indexOf(b)>-1?o:o[b]?o[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error("Method "+b+' does not exist. See jQuery.sketchable("methods").'),this):o.init.apply(this,arguments)},a.fn.sketchable.defaults={interactive:!0,mouseupMovements:!1,relTimestamps:!1,multitouch:!0,cssCursors:!0,events:{},graphics:{firstPointSize:3,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F",lineCap:"round",lineJoin:"round",miterLimit:10}}}(jQuery),function(a){function b(b,g){function h(a){if(i&&i.events&&"function"==typeof i.events[a]){var c=i.events[a];i.events[a]=function(){var d=Array.prototype.slice.call(arguments,0);c.apply(b,d),j[a].apply(b,d)}}else i.events[a]=j[a]}var i=a.extend(!0,{},e.defaults,g);if(!i.interactive)return g;var j={init:function(a,b){b.memento=new c(a),b.memento.save(),b.memento.init()},clear:function(a,b){b.memento.save()},mouseup:function(a,b,c){b.memento.save()},destroy:function(a,b){b.memento.destroy()}};if(!e.isMementoReady){for(var k="init mouseup clear destroy".split(" "),l=0;l0){h--;var a=new Image;a.src=g[h].image,a.onload=function(){e(this)}}}function d(){if(h0&&g.sketch.fillCircle(i.x,i.y,h.graphics.firstPointSize),g.coords[e]||(g.coords[e]=[]),g.coords[e].length>0&&(g.strokes.push(g.coords[e]),g.coords[e]=[]),c(e,g,i),"function"==typeof h.events.mousedown&&h.events.mousedown(f,g,d)}}function l(d){var e=d.identifier||0,f=a(d.target),g=f.data(n),h=g.options;if(h.interactive&&(h.mouseupMovements&&0!==g.strokes.length||g.sketch.isDrawing)){var i=b(d);if(g.sketch.isDrawing){var j=g.coords[e][g.coords[e].length-1];g.sketch.beginPath().line(j[0],j[1],i.x,i.y).stroke().closePath()}c(e,g,i),"function"==typeof h.events.mousemove&&h.events.mousemove(f,g,d)}}function m(b){var c=b.identifier||0,d=a(b.target),e=d.data(n),f=e.options;f.interactive&&(e.sketch.isDrawing=!1,e.strokes.push(e.coords[c]),e.coords[c]=[],"function"==typeof f.events.mouseup&&f.events.mouseup(d,e,b))}var n="sketchable",o={init:function(b){var c=a.extend(!0,{},a.fn.sketchable.defaults,b||{});return this.each(function(){var b=a(this),g=b.data(n);g||(c.interactive&&(b.bind("mousedown",d),b.bind("mousemove",e),b.bind("mouseup",f),b.bind("touchstart",h),b.bind("touchmove",i),b.bind("touchend",j),this.onselectstart=function(){return!1}),c.cssCursors&&(b[0].style.cursor=c.interactive?"pointer":"not-allowed"));var k=new jSketch(this,c.graphics);b.data(n,{strokes:[],coords:{},timestamp:(new Date).getTime(),sketch:k,options:c}),"function"==typeof c.events.init&&c.events.init(b,b.data(n))})},config:function(b){return this.each(function(){var c=a(this),d=c.data(n);d.options=a.extend(!0,{},a.fn.sketchable.defaults,b||{})})},strokes:function(b){if(b)return this.each(function(){var c=a(this),d=c.data(n);d.strokes=b});var c=a(this).data(n);return c.strokes},handler:function(b){return this.each(function(){var c=a(this),d=c.data(n);b(c,d)})},clear:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},d=c.options;c.sketch&&(c.sketch.clear(),c.strokes=[],c.coords={}),d&&"function"==typeof d.events.clear&&d.events.clear(b,c)})},reset:function(b){return this.each(function(){var c=a(this),d=c.data(n)||{},e=d.options;c.sketchable("destroy").sketchable(b),e&&"function"==typeof e.events.reset&&e.events.reset(c,d)})},destroy:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},g=c.options;g.interactive&&(b.unbind("mouseup",f),b.unbind("mousemove",e),b.unbind("mousedown",d),b.unbind("touchstart",h),b.unbind("touchmove",i),b.unbind("touchend",j)),b.removeData(n),g&&"function"==typeof g.events.destroy&&g.events.destroy(b,c)})}};a.fn.sketchable=function(b){return"methods functions hooks".split(" ").indexOf(b)>-1?o:o[b]?o[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error("Method "+b+' does not exist. See jQuery.sketchable("methods").'),this):o.init.apply(this,arguments)},a.fn.sketchable.defaults={interactive:!0,mouseupMovements:!1,relTimestamps:!1,multitouch:!0,cssCursors:!0,events:{},graphics:{firstPointSize:3,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F",lineCap:"round",lineJoin:"round",miterLimit:10}}}(jQuery); \ No newline at end of file +!function(a){function b(b){var c=a(b.target),d=c.offset();return{x:Math.round(b.pageX-d.left),y:Math.round(b.pageY-d.top)}}function c(a,b,c){b.coords[a]||(b.coords[a]=[]);var d=(new Date).getTime();b.options.relTimestamps&&(0===b.strokes.length&&0===b.coords[a].length&&(b.timestamp=d),d-=b.timestamp),b.coords[a].push([c.x,c.y,d,+b.sketch.isDrawing])}function d(a){return a.originalEvent.touches?!1:void k(a)}function e(a){return a.originalEvent.touches?!1:void l(a)}function f(a){return a.originalEvent.touches?!1:void m(a)}function g(b,c){var d=a(b.target),e=d.data(n),f=e.options,g=b.originalEvent.changedTouches;if(f.multitouch)for(var h=0;h0&&g.sketch.fillCircle(i.x,i.y,h.graphics.firstPointSize),g.coords[e]||(g.coords[e]=[]),g.coords[e].length>0&&(g.strokes.push(g.coords[e]),g.coords[e]=[]),c(e,g,i),"function"==typeof h.events.mousedown&&h.events.mousedown(f,g,d)}}function l(d){var e=d.identifier||0,f=a(d.target),g=f.data(n),h=g.options;if(h.interactive&&(h.mouseupMovements&&0!==g.strokes.length||g.sketch.isDrawing)){var i=b(d);if(g.sketch.isDrawing){var j=g.coords[e][g.coords[e].length-1];g.sketch.beginPath().line(j[0],j[1],i.x,i.y).stroke().closePath()}c(e,g,i),"function"==typeof h.events.mousemove&&h.events.mousemove(f,g,d)}}function m(b){var c=b.identifier||0,d=a(b.target),e=d.data(n),f=e.options;f.interactive&&(e.sketch.isDrawing=!1,e.strokes.push(e.coords[c]),e.coords[c]=[],"function"==typeof f.events.mouseup&&f.events.mouseup(d,e,b))}var n="sketchable",o={init:function(b){var c=a.extend(!0,{},a.fn.sketchable.defaults,b||{});return this.each(function(){var b=a(this),g=b.data(n);g||(c.interactive&&(b.bind("mousedown",d),b.bind("mousemove",e),b.bind("mouseup",f),b.bind("touchstart",h),b.bind("touchmove",i),b.bind("touchend",j),this.onselectstart=function(){return!1}),c.cssCursors&&(b[0].style.cursor=c.interactive?"pointer":"not-allowed"));var k=new jSketch(this,c.graphics);b.data(n,{strokes:[],coords:{},timestamp:(new Date).getTime(),sketch:k,options:c}),"function"==typeof c.events.init&&c.events.init(b,b.data(n))})},config:function(b){return this.each(function(){var c=a(this),d=c.data(n);d.options=a.extend(!0,b||{},a.fn.sketchable.defaults,d.options)})},strokes:function(b){if(b)return this.each(function(){var c=a(this),d=c.data(n);d.strokes=b});var c=a(this).data(n);return c.strokes},handler:function(b){return this.each(function(){var c=a(this),d=c.data(n);b(c,d)})},clear:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},d=c.options;c.sketch&&(c.sketch.clear(),c.strokes=[],c.coords={}),d&&"function"==typeof d.events.clear&&d.events.clear(b,c)})},reset:function(b){return this.each(function(){var c=a(this),d=c.data(n)||{},e=d.options;c.sketchable("destroy").sketchable(b),e&&"function"==typeof e.events.reset&&e.events.reset(c,d)})},destroy:function(){return this.each(function(){var b=a(this),c=b.data(n)||{},g=c.options;g.interactive&&(b.unbind("mouseup",f),b.unbind("mousemove",e),b.unbind("mousedown",d),b.unbind("touchstart",h),b.unbind("touchmove",i),b.unbind("touchend",j)),b.removeData(n),g&&"function"==typeof g.events.destroy&&g.events.destroy(b,c)})}};a.fn.sketchable=function(b){return"methods functions hooks".split(" ").indexOf(b)>-1?o:o[b]?o[b].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof b&&b?(a.error("Method "+b+' does not exist. See jQuery.sketchable("methods").'),this):o.init.apply(this,arguments)},a.fn.sketchable.defaults={interactive:!0,mouseupMovements:!1,relTimestamps:!1,multitouch:!0,cssCursors:!0,events:{},graphics:{firstPointSize:3,lineWidth:3,strokeStyle:"#F0F",fillStyle:"#F0F",lineCap:"round",lineJoin:"round",miterLimit:10}}}(jQuery); \ No newline at end of file