text: !function(t){var e=Function("return this")()||(42,eval)("this");"function"==typeof define&&define.amd?define(["jquery"],function(n){return e.PatternLock=t(n,e)}):"object"==typeof module&&module.exports?module.exports=e.document?t(require("jquery"),e):function(e){if(!e.document)throw new Error("patternLock requires a window with a document");return t(require("jquery")(e),e)}:e.PatternLock=t(e.jQuery,e)}(function(t,e,n){"use strict";function i(t){for(var e=t.holder,n=t.option,i=n.matrix,o=n.margin,r=n.radius,a=['<ul class="patt-wrap'+t.option.theme+'" style="padding:'+o+'px">'],s=0,l=i[0]*i[1];l>s;s++)a.push('<li class="patt-circ'+t.option.theme+'" style="margin:'+o+"px; width : "+2*r+"px; height : "+2*r+"px; -webkit-border-radius: "+r+"px; -moz-border-radius: "+r+"px; border-radius: "+r+'px; "><div class="patt-dots'+t.option.theme+'"></div></li>');a.push("</ul>"),e.html(a.join("")).css({width:i[1]*(2*r+2*o)+2*o+"px",height:i[0]*(2*r+2*o)+2*o+"px"}),t.pattCircle=t.holder.find(".patt-circ"+t.option.theme)}function o(t,e,n,i){var o=e-t,r=i-n;return{length:Math.ceil(Math.sqrt(o*o+r*r)),angle:Math.round(180*Math.atan2(r,o)/Math.PI)}}function r(){}function a(e,n){var o=this,s=o.token=Math.random(),u=p[s]=new r,d=u.holder=t(e);if(0!=d.length){u.object=o,n=u.option=t.extend({},a.defaults,n),i(u),d.addClass("patt-holder"+n.theme),"static"==d.css("position")&&d.css("position","relative"),d.on("touchstart mousedown",function(t){h.call(this,t,o)}),u.option.onDraw=n.onDraw||l;var c=n.mapper;"object"==typeof c?u.mapperFunc=function(t){return c[t]}:"function"==typeof c?u.mapperFunc=c:u.mapperFunc=l,u.option.mapper=null}}var s=e.document,l=function(){},p={},h=function(e,n){e.preventDefault();var i=p[n.token];if(!i.disabled){i.option.patternVisible||i.holder.addClass("patt-hidden"+i.option.theme);var o="touchstart"==e.type?"touchmove":"mousemove",r="touchstart"==e.type?"touchend":"mouseup";t(this).on(o+".pattern-move",function(t){u.call(this,t,n)}),t(s).one(r,function(){d.call(this,e,n)});var a=i.holder.find(".patt-wrap"+i.option.theme),l=a[0].getBoundingClientRect();i.wrapTop=l.top,i.wrapLeft=l.left,n.reset()}},u=function(e,n){e.preventDefault();var i=e.clientX||e.originalEvent.touches[0].clientX,r=e.clientY||e.originalEvent.touches[0].clientY,a=p[n.token],s=a.pattCircle,l=a.patternAry,h=a.option.lineOnMove,u=a.getIdxFromPoint(i,r),d=u.idx,c=a.mapperFunc(d)||d;if(l.length>0){var f=o(a.lineX1,u.x,a.lineY1,u.y);a.line.css({width:f.length+10+"px",transform:"rotate("+f.angle+"deg)"})}if(d){if(-1==l.indexOf(c)){var m,v=t(s[d-1]);if(a.lastPosObj){for(var g=a.lastPosObj,x=g.i,w=g.j,j=Math.abs(u.i-x),b=Math.abs(u.j-w);(0==j&&b>1||0==b&&j>1||b==j&&b>1)&&(w!=u.j||x!=u.i);){x=j?Math.min(u.i,x)+1:x,w=b?Math.min(u.j,w)+1:w,j=Math.abs(u.i-x),b=Math.abs(u.j-w);var y=(w-1)*a.option.matrix[1]+x,k=a.mapperFunc(y)||y;-1==l.indexOf(k)&&(t(s[y-1]).addClass("hovered"),l.push(k))}m=[],u.j-g.j>0?m.push("s"):u.j-g.j<0?m.push("n"):0,u.i-g.i>0?m.push("e"):u.i-g.i<0?m.push("w"):0,m=m.join("-")}v.addClass("hovered"),l.push(c);var M=a.option.margin,P=a.option.radius,C=(u.i-1)*(2*M+2*P)+2*M+P,F=(u.j-1)*(2*M+2*P)+2*M+P;if(1!=l.length){var O=o(a.lineX1,C,a.lineY1,F);a.line.css({width:O.length+10+"px",transform:"rotate("+O.angle+"deg)"}),h||a.line.show()}m&&(a.lastElm.addClass(m+" dir"),a.line.addClass(m+" dir"));var q=t('<div class="patt-lines'+a.option.theme+'" style="top:'+(F-5)+"px; left:"+(C-5)+'px"></div>');a.line=q,a.lineX1=C,a.lineY1=F,a.holder.append(q),h||a.line.hide(),a.lastElm=v}a.lastPosObj=u}},d=function(t,e){t.preventDefault();var n=p[e.token],i=n.patternAry.join(n.option.delimiter);n.holder.off(".pattern-move").removeClass("patt-hidden"+n.option.theme),i&&(n.option.onDraw(i),n.line.remove(),n.rightPattern&&(i==n.rightPattern?n.onSuccess():(n.onError(),e.error())))};return r.prototype={constructor:r,getIdxFromPoint:function(t,e){var n=this.option,i=n.matrix,o=t-this.wrapLeft,r=e-this.wrapTop,a=null,s=n.margin,l=2*n.radius+2*s,p=Math.ceil(o/l),h=Math.ceil(r/l),u=o%l,d=r%l;return p<=i[1]&&h<=i[0]&&u>2*s&&d>2*s&&(a=(h-1)*i[1]+p),{idx:a,i:p,j:h,x:o,y:r}}},a.prototype={constructor:a,option:function(t,e){var o=p[this.token],r=o.option;return e===n?r[t]:(r[t]=e,void(("margin"==t||"matrix"==t||"radius"==t)&&i(o)))},getPattern:function(){var t=p[this.token];return(t.patternAry||[]).join(t.option.delimiter)},setPattern:function(t){var e=p[this.token],n=e.option,i=n.matrix,o=n.margin,r=n.radius;if(n.enableSetPattern){this.reset(),e.wrapLeft=0,e.wrapTop=0;for(var a=0;a<t.length;a++){var s=t[a]-1,h=s%i[1],d=Math.floor(s/i[1]),c=h*(2*o+2*r)+2*o+r,f=d*(2*o+2*r)+2*o+r;u.call(null,{clientX:c,clientY:f,preventDefault:l},this)}}},enable:function(){var t=p[this.token];t.disabled=!1},disable:function(){var t=p[this.token];t.disabled=!0},reset:function(){var t=p[this.token];t.pattCircle.removeClass("hovered dir s n w e s-w s-e n-w n-e"),t.holder.find(".patt-lines"+t.option.theme).remove(),t.patternAry=[],t.lastPosObj=null,t.holder.removeClass("patt-error"+t.option.theme)},error:function(){var t=p[this.token];p[this.token].holder.addClass("patt-error"+t.option.theme)},checkForPattern:function(t,e,n){var i=p[this.token];i.rightPattern=t,i.onSuccess=e||l,i.onError=n||l}},a.defaults={matrix:[3,3],margin:20,radius:25,patternVisible:!0,lineOnMove:!0,delimiter:";",enableSetPattern:!1,theme:"default"},a});