!function(t,e,i){"use strict";function n(t,e){this.cover=null,this.ctx=null,this.scratchDiv=null,this.cardDiv=null,this.cHeight=0,this.cWidth=0,this.supportTouch=!1,this.events=[],this.startEventHandler=null,this.moveEventHandler=null,this.endEventHandler=null,this.enable=!0,this.opt={coverColor:"#C5C5C5",coverImg:"",ratio:.8,callback:null},this.init(t,e)}function o(t,e,i){var n=t.getImageData(0,0,300,100),o=[];c(n.data,function(t,e){var i=n.data[e+3];0===i&&o.push(i)}),o.length/n.data.length>i&&e&&"function"==typeof e&&e()}function c(t,e){return Array.prototype.forEach.call(t,function(t,i){e(t,i)})}function s(){var t=e.createElement("canvas");return!(!t.getContext||!t.getContext("2d"))}function h(t){this.enable&&(this.cardDiv.style.opacity=1,this.moveEventHandler=r.bind(this),this.cover.addEventListener(this.events[1],this.moveEventHandler,!1),this.endEventHandler=a.bind(this),e.addEventListener(this.events[2],this.endEventHandler,!1),t.preventDefault())}function r(t){if(this.enable){var i=this.supportTouch?t.touches[0]:t,n=this.cover.getBoundingClientRect(),o=e.documentElement.scrollTop||e.body.scrollTop,c=e.documentElement.scrollLeft||e.body.scrollLeft,s=i.pageX-n.left-c,h=i.pageY-n.top-o;this.ctx.beginPath(),this.ctx.fillStyle="#FFFFFF",this.ctx.globalCompositeOperation="destination-out",this.ctx.arc(s,h,12,0,2*Math.PI),this.ctx.fill(),t.preventDefault()}}function a(t){this.enable&&(this.opt.callback&&"function"==typeof this.opt.callback&&o(this.ctx,this.opt.callback,this.opt.ratio),this.cover.removeEventListener(this.events[1],this.moveEventHandler,!1),e.removeEventListener(this.events[2],this.endEventHandler,!1),t.preventDefault())}n.prototype.createCanvas=function(){if(this.cover=e.createElement("canvas"),this.cover.id="cover",this.cover.height=this.cHeight,this.cover.width=this.cWidth,this.ctx=this.cover.getContext("2d"),this.opt.coverImg){var t=this,i=new Image;i.src=this.opt.coverImg,i.onload=function(){t.ctx.drawImage(i,0,0,t.cover.width,t.cover.height)}}else this.ctx.fillStyle=this.opt.coverColor,this.ctx.fillRect(0,0,this.cover.width,this.cover.height);this.scratchDiv.appendChild(this.cover)},n.prototype.eventDetect=function(){"ontouchstart"in t&&(this.supportTouch=!0),this.events=this.supportTouch?["touchstart","touchmove","touchend"]:["mousedown","mousemove","mouseup"],this.addEvent()},n.prototype.addEvent=function(){this.startEventHandler=h.bind(this),this.cover.addEventListener(this.events[0],this.startEventHandler,!1)},n.prototype.setEnable=function(t){this.enable=t},n.prototype.clearCover=function(){this.ctx.clearRect(0,0,this.cover.width,this.cover.height)},n.prototype.init=function(t,i){if(!s())return void alert("对不起，当前浏览器不支持Canvas，无法使用本控件！");var n=this;c(arguments,function(t){if("object"==typeof t)for(var e in t)"callback"===e&&"function"==typeof t[e]?n.opt.callback=t[e].bind(n):e in n.opt&&(n.opt[e]=t[e]);else"function"==typeof t&&(n.opt.callback=t.bind(n))}),this.scratchDiv=e.getElementById("scratch"),this.cardDiv=e.getElementById("card"),this.scratchDiv&&this.cardDiv&&(this.cHeight=this.cardDiv.clientHeight,this.cWidth=this.cardDiv.clientWidth,this.cardDiv.style.opacity=0,this.createCanvas(),this.eventDetect())},n.case=function(t,e){return new n(t,e)},"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return n}):"undefined"!=typeof module&&module.exports?(module.exports=n.case,module.exports.LuckyCard=n):t.LuckyCard=n}(window,document);