2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
|
(function(L){L.fn.qrcode=function(a){var B;function y(t){this.mode=B,this.data=t}function p(t,e){this.typeNumber=t,this.errorCorrectLevel=e,this.modules=null,this.moduleCount=0,this.dataCache=null,this.dataList=[]}function d(t,e){if(t.length==null)throw Error(t.length+"/"+e);for(var o=0;o<t.length&&t[o]==0;)o++;this.num=Array(t.length-o+e);for(var r=0;r<t.length-o;r++)this.num[r]=t[r+o]}function C(t,e){this.totalCount=t,this.dataCount=e}function c(){this.buffer=[],this.length=0}y.prototype={getLength:function(){return this.data.length},write:function(t){for(var e=0;e<this.data.length;e++)t.put(this.data.charCodeAt(e),8)}},p.prototype={addData:function(t){this.dataList.push(new y(t)),this.dataCache=null},isDark:function(t,e){if(0>t||this.moduleCount<=t||0>e||this.moduleCount<=e)throw Error(t+","+e);return this.modules[t][e]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var t=1,t=1;40>t;t++){for(var e=C.getRSBlocks(t,this.errorCorrectLevel),o=new c,r=0,n=0;n<e.length;n++)r+=e[n].dataCount;for(n=0;n<this.dataList.length;n++)e=this.dataList[n],o.put(e.mode,4),o.put(e.getLength(),g.getLengthInBits(e.mode,t)),e.write(o);if(o.getLengthInBits()<=8*r)break}this.typeNumber=t}this.makeImpl(!1,this.getBestMaskPattern())},makeImpl:function(t,e){this.moduleCount=4*this.typeNumber+17,this.modules=Array(this.moduleCount);for(var o=0;o<this.moduleCount;o++){this.modules[o]=Array(this.moduleCount);for(var r=0;r<this.moduleCount;r++)this.modules[o][r]=null}this.setupPositionProbePattern(0,0),this.setupPositionProbePattern(this.moduleCount-7,0),this.setupPositionProbePattern(0,this.moduleCount-7),this.setupPositionAdjustPattern(),this.setupTimingPattern(),this.setupTypeInfo(t,e),7<=this.typeNumber&&this.setupTypeNumber(t),this.dataCache==null&&(this.dataCache=p.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,e)},setupPositionProbePattern:function(t,e){for(var o=-1;7>=o;o++)if(!(-1>=t+o||this.moduleCount<=t+o))for(var r=-1;7>=r;r++)-1>=e+r||this.moduleCount<=e+r||(this.modules[t+o][e+r]=0<=o&&6>=o&&(r==0||r==6)||0<=r&&6>=r&&(o==0||o==6)||2<=o&&4>=o&&2<=r&&4>=r)},getBestMaskPattern:function(){for(var t=0,e=0,o=0;8>o;o++){this.makeImpl(!0,o);var r=g.getLostPoint(this);(o==0||t>r)&&(t=r,e=o)}return e},createMovieClip:function(t,e,o){for(t=t.createEmptyMovieClip(e,o),this.make(),e=0;e<this.modules.length;e++)for(var o=1*e,r=0;r<this.modules[e].length;r++){var n=1*r;this.modules[e][r]&&(t.beginFill(0,100),t.moveTo(n,o),t.lineTo(n+1,o),t.lineTo(n+1,o+1),t.lineTo(n,o+1),t.endFill())}return t},setupTimingPattern:function(){for(var t=8;t<this.moduleCount-8;t++)this.modules[t][6]==null&&(this.modules[t][6]=t%2==0);for(t=8;t<this.moduleCount-8;t++)this.modules[6][t]==null&&(this.modules[6][t]=t%2==0)},setupPositionAdjustPattern:function(){for(var t=g.getPatternPosition(this.typeNumber),e=0;e<t.length;e++)for(var o=0;o<t.length;o++){var r=t[e],n=t[o];if(this.modules[r][n]==null)for(var i=-2;2>=i;i++)for(var u=-2;2>=u;u++)this.modules[r+i][n+u]=i==-2||i==2||u==-2||u==2||i==0&&u==0}},setupTypeNumber:function(t){for(var e=g.getBCHTypeNumber(this.typeNumber),o=0;18>o;o++){var r=!t&&(e>>o&1)==1;this.modules[Math.floor(o/3)][o%3+this.moduleCount-8-3]=r}for(o=0;18>o;o++)r=!t&&(e>>o&1)==1,this.modules[o%3+this.moduleCount-8-3][Math.floor(o/3)]=r},setupTypeInfo:function(t,e){for(var o=g.getBCHTypeInfo(this.errorCorrectLevel<<3|e),r=0;15>r;r++){var n=!t&&(o>>r&1)==1;6>r?this.modules[r][8]=n:8>r?this.modules[r+1][8]=n:this.modules[this.moduleCount-15+r][8]=n}for(r=0;15>r;r++)n=!t&&(o>>r&1)==1,8>r?this.modules[8][this.moduleCount-r-1]=n:9>r?this.modules[8][15-r-1+1]=n:this.modules[8][15-r-1]=n;this.modules[this.moduleCount-8][8]=!t},mapData:function(t,e){for(var o=-1,r=this.moduleCount-1,n=7,i=0,u=this.moduleCount-1;0<u;u-=2)for(u==6&&u--;;){for(var s=0;2>s;s++)if(this.modules[r][u-s]==null){var l=!1;i<t.length&&(l=(t[i]>>>n&1)==1),g.getMask(e,r,u-s)&&(l=!l),this.modules[r][u-s]=l,n--,n==-1&&(i++,n=7)}if(r+=o,0>r||this.moduleCount<=r){r-=o,o=-o;break}}}},p.PAD0=236,p.PAD1
|