diff --git a/examples/basic.html b/examples/basic.html index 2af1225..f371978 100644 --- a/examples/basic.html +++ b/examples/basic.html @@ -8,7 +8,11 @@
diff --git a/index.html b/index.html index aafdb17..11162b2 100644 --- a/index.html +++ b/index.html @@ -49,7 +49,7 @@ >

Conclusion

jquery.qrcode.js is available on github here under MIT license. If you hit bugs, fill issues on github. Feel free to fork, modify and have fun with it :)

jquery.qrcode.js is available on github here under MIT license. If you hit bugs, fill issues on github. Feel free to fork, modify and have fun with it :)

diff --git a/jquery.qrcode.min.js b/jquery.qrcode.min.js index aa6e8a8..81c1607 100644 --- a/jquery.qrcode.min.js +++ b/jquery.qrcode.min.js @@ -1,22 +1,29 @@ -(function(v){v.fn.qrcode=function(o){function w(a){this.mode=n.MODE_8BIT_BYTE;this.data=a}function p(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function t(a,c){if(a.length==undefined)throw Error(a.length+"/"+c);for(var d=0;d=7&&this.setupTypeNumber(a);if(this.dataCache==null)this.dataCache=p.createData(this.typeNumber, -this.errorCorrectLevel,this.dataList);this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,c){for(var d=-1;d<=7;d++)if(!(a+d<=-1||this.moduleCount<=a+d))for(var b=-1;b<=7;b++)c+b<=-1||this.moduleCount<=c+b||(this.modules[a+d][c+b]=0<=d&&d<=6&&(b==0||b==6)||0<=b&&b<=6&&(d==0||d==6)||2<=d&&d<=4&&2<=b&&b<=4?true:false)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;d<8;d++){this.makeImpl(true,d);var b=k.getLostPoint(this);if(d==0||a>b){a=b;c=d}}return c},createMovieClip:function(a, -c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c>d&1)==1;this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;d<18;d++){b=!a&&(c>>d&1)==1;this.modules[d%3+this.moduleCount-8-3][Math.floor(d/ -3)]=b}},setupTypeInfo:function(a,c){for(var d=k.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;b<15;b++){var e=!a&&(d>>b&1)==1;if(b<6)this.modules[b][8]=e;else if(b<8)this.modules[b+1][8]=e;else this.modules[this.moduleCount-15+b][8]=e}for(b=0;b<15;b++){e=!a&&(d>>b&1)==1;if(b<8)this.modules[8][this.moduleCount-b-1]=e;else if(b<9)this.modules[8][15-b-1+1]=e;else this.modules[8][15-b-1]=e}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,h=this.moduleCount- -1;h>0;h-=2)for(h==6&&h--;;){for(var g=0;g<2;g++)if(this.modules[b][h-g]==null){var j=false;if(f>>e&1)==1;if(k.getMask(c,b,h-g))j=!j;this.modules[b][h-g]=j;e--;if(e==-1){f++;e=7}}b+=d;if(b<0||this.moduleCount<=b){b-=d;d=-d;break}}}};p.PAD0=236;p.PAD1=17;p.createData=function(a,c,d){c=q.getRSBlocks(a,c);for(var b=new x,e=0;e -a*8)throw Error("code length overflow. ("+b.getLengthInBits()+">"+a*8+")");for(b.getLengthInBits()+4<=a*8&&b.put(0,4);b.getLengthInBits()%8!=0;)b.putBit(false);for(;;){if(b.getLengthInBits()>=a*8)break;b.put(p.PAD0,8);if(b.getLengthInBits()>=a*8)break;b.put(p.PAD1,8)}return p.createBytes(b,c)};p.createBytes=function(a,c){for(var d=0,b=0,e=0,f=Array(c.length),h=Array(c.length),g=0;g=0?j.get(r):0}}for(i=g=0;i=0;)c^=k.G15<=0;)c^=k.G18<>>=1}return c},getPatternPosition:function(a){return k.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case s.PATTERN000:return(c+d)%2==0;case s.PATTERN001:return c%2==0;case s.PATTERN010:return d%3==0;case s.PATTERN011:return(c+d)%3==0;case s.PATTERN100:return(Math.floor(c/2)+Math.floor(d/3))%2==0;case s.PATTERN101:return c*d%2+c*d%3==0;case s.PATTERN110:return(c* -d%2+c*d%3)%2==0;case s.PATTERN111:return(c*d%3+(c+d)%2)%2==0;default:throw Error("bad maskPattern:"+a);}},getErrorCorrectPolynomial:function(a){for(var c=new t([1],0),d=0;d5)d+=3+f-5}for(b=0;b=256;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256),LOG_TABLE:Array(256)},m=0;m<8;m++)l.EXP_TABLE[m]=1<>>7-a%8&1)==1},put:function(a,c){for(var d=0;d>>c-d-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);if(a)this.buffer[c]|=128>>>this.length%8;this.length++}};if(typeof o==="string")o={text:o};o=v.extend({},{width:256,height:256,typeNumber:4,correctLevel:u.H},o);return this.each(function(){var a= -new p(o.typeNumber,o.correctLevel);a.addData(o.text);a.make();var c=document.createElement("canvas");c.width=o.width;c.height=o.height;for(var d=c.getContext("2d"),b=o.width/a.getModuleCount(),e=o.height/a.getModuleCount(),f=0;f=7&&this.setupTypeNumber(a);if(this.dataCache==null)this.dataCache=p.createData(this.typeNumber,this.errorCorrectLevel,this.dataList);this.mapData(this.dataCache,c)},setupPositionProbePattern:function(a,c){for(var d=-1;d<=7;d++)if(!(a+d<=-1||this.moduleCount<= +a+d))for(var b=-1;b<=7;b++)c+b<=-1||this.moduleCount<=c+b||(this.modules[a+d][c+b]=0<=d&&d<=6&&(b==0||b==6)||0<=b&&b<=6&&(d==0||d==6)||2<=d&&d<=4&&2<=b&&b<=4?true:false)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;d<8;d++){this.makeImpl(true,d);var b=j.getLostPoint(this);if(d==0||a>b){a=b;c=d}}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c>d&1)==1;this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;d<18;d++){b=!a&&(c>>d&1)==1;this.modules[d%3+this.moduleCount-8-3][Math.floor(d/3)]=b}},setupTypeInfo:function(a,c){for(var d=j.getBCHTypeInfo(this.errorCorrectLevel<<3|c),b=0;b<15;b++){var e=!a&&(d>>b&1)==1;if(b<6)this.modules[b][8]=e;else if(b< +8)this.modules[b+1][8]=e;else this.modules[this.moduleCount-15+b][8]=e}for(b=0;b<15;b++){e=!a&&(d>>b&1)==1;if(b<8)this.modules[8][this.moduleCount-b-1]=e;else if(b<9)this.modules[8][15-b-1+1]=e;else this.modules[8][15-b-1]=e}this.modules[this.moduleCount-8][8]=!a},mapData:function(a,c){for(var d=-1,b=this.moduleCount-1,e=7,f=0,h=this.moduleCount-1;h>0;h-=2)for(h==6&&h--;;){for(var g=0;g<2;g++)if(this.modules[b][h-g]==null){var k=false;if(f>>e&1)==1;if(j.getMask(c,b,h-g))k=!k;this.modules[b][h- +g]=k;e--;if(e==-1){f++;e=7}}b+=d;if(b<0||this.moduleCount<=b){b-=d;d=-d;break}}}};p.PAD0=236;p.PAD1=17;p.createData=function(a,c,d){c=q.getRSBlocks(a,c);for(var b=new w,e=0;ea*8)throw Error("code length overflow. ("+b.getLengthInBits()+">"+a*8+")");for(b.getLengthInBits()+4<=a*8&&b.put(0,4);b.getLengthInBits()%8!=0;)b.putBit(false); +for(;;){if(b.getLengthInBits()>=a*8)break;b.put(p.PAD0,8);if(b.getLengthInBits()>=a*8)break;b.put(p.PAD1,8)}return p.createBytes(b,c)};p.createBytes=function(a,c){for(var d=0,b=0,e=0,f=Array(c.length),h=Array(c.length),g=0;g=0?k.get(r):0}}for(i=g=0;i=0;)c^=j.G15<=0;)c^=j.G18<>>=1}return c}, +getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case s.PATTERN000:return(c+d)%2==0;case s.PATTERN001:return c%2==0;case s.PATTERN010:return d%3==0;case s.PATTERN011:return(c+d)%3==0;case s.PATTERN100:return(Math.floor(c/2)+Math.floor(d/3))%2==0;case s.PATTERN101:return c*d%2+c*d%3==0;case s.PATTERN110:return(c*d%2+c*d%3)%2==0;case s.PATTERN111:return(c*d%3+(c+d)%2)%2==0;default:throw Error("bad maskPattern:"+a);}},getErrorCorrectPolynomial:function(a){for(var c= +new t([1],0),d=0;d5)d+=3+f-5}for(b=0;b=256;)a-=255;return m.EXP_TABLE[a]},EXP_TABLE:Array(256),LOG_TABLE:Array(256)},n=0;n<8;n++)m.EXP_TABLE[n]=1<>>7-a%8&1)==1},put:function(a,c){for(var d=0;d>>c-d-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(a){var c=Math.floor(this.length/8);this.buffer.length<=c&&this.buffer.push(0);if(a)this.buffer[c]|= +128>>>this.length%8;this.length++}};if(typeof l==="string")l={text:l};l=u.extend({},{render:"canvas",width:256,height:256,typeNumber:-1,correctLevel:v.H},l);return this.each(function(){var a;if(l.render=="canvas"){a=new p(l.typeNumber,l.correctLevel);a.addData(l.text);a.make();var c=document.createElement("canvas");c.width=l.width;c.height=l.height;for(var d=c.getContext("2d"),b=l.width/a.getModuleCount(),e=l.height/a.getModuleCount(),f=0;f").css("width",l.width+"px").css("height",l.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color","#ffffff");d=100/a.getModuleCount();b=100/a.getModuleCount();for(e=0;e").css("height",b+"%").appendTo(c);for(h=0;h").css("width",d+"%").css("background-color", +a.isDark(e,h)?"#000000":"#ffffff").appendTo(f)}a=c}jQuery(a).appendTo(this)})}})(jQuery); diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 441aede..a2f7db6 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -8,6 +8,7 @@ // set default values // typeNumber < 1 for automatic calculation options = $.extend( {}, { + render : "canvas", width : 256, height : 256, typeNumber : -1, @@ -48,31 +49,31 @@ qrcode.addData(options.text); qrcode.make(); - var $table, $row, $col; - var row, col; - var tileS; var border_width = (options.width + options.height) / 20; // 10% of the average(width, height) // create table element - $table = $('
') + var $table = $('
') .css("width", options.width+"px") .css("height", options.height+"px") .css("border", "0px") .css("border-collapse", "collapse") - .css("margin", border_width+"px") + //.css("margin", border_width+"px") .css('background-color', "#ffffff"); // compute tileS percentage - tileS = 100 / qrcode.getModuleCount(); + var tileW = 100 / qrcode.getModuleCount(); + var tileH = 100 / qrcode.getModuleCount(); // draw in the table - for(row = 0; row < qrcode.getModuleCount(); row++ ){ - $row = $('').css('height', tileS+"%").appendTo($table); + for(var row = 0; row < qrcode.getModuleCount(); row++ ){ + var $row = $('').css('height', tileH+"%").appendTo($table); - for(col = 0; col < qrcode.getModuleCount(); col++ ){ - $col = $('').css('width', tileS+"%").appendTo($row); - $col.css('background-color', qrcode.isDark(row, col) ? "#000000" : "#ffffff"); + for(var col = 0; col < qrcode.getModuleCount(); col++ ){ + $('') + .css('width', tileW+"%") + .css('background-color', qrcode.isDark(row, col) ? "#000000" : "#ffffff") + .appendTo($row); } } // return just built canvas @@ -81,8 +82,7 @@ return this.each(function(){ - //var element = createCanvas(); - var element = createTable(); + var element = options.render == "canvas" ? createCanvas() : createTable(); jQuery(element).appendTo(this); }); };