From cf52f2ea3cb06de16a3025731fa15e680f6cc23a Mon Sep 17 00:00:00 2001 From: x Date: Thu, 12 Jun 2014 21:47:34 -0400 Subject: [PATCH 1/8] Added SVG and formats, border option; optimized the code --- examples/basic.html | 23 ++- jquery.qrcode.min.js | 28 ---- src/jquery.qrcode.js | 380 +++++++++++++++++++++++++++++++++---------- 3 files changed, 308 insertions(+), 123 deletions(-) delete mode 100644 jquery.qrcode.min.js diff --git a/examples/basic.html b/examples/basic.html index 5213bc3..a379145 100644 --- a/examples/basic.html +++ b/examples/basic.html @@ -4,25 +4,36 @@ basic example - + - - + +

Render in table

Render in canvas

+

Render in SVG

+
+

Render in image

+
diff --git a/jquery.qrcode.min.js b/jquery.qrcode.min.js deleted file mode 100644 index fe9680e..0000000 --- a/jquery.qrcode.min.js +++ /dev/null @@ -1,28 +0,0 @@ -(function(r){r.fn.qrcode=function(h){var s;function u(a){this.mode=s;this.data=a}function o(a,c){this.typeNumber=a;this.errorCorrectLevel=c;this.modules=null;this.moduleCount=0;this.dataCache=null;this.dataList=[]}function q(a,c){if(void 0==a.length)throw Error(a.length+"/"+c);for(var d=0;da||this.moduleCount<=a||0>c||this.moduleCount<=c)throw Error(a+","+c);return this.modules[a][c]},getModuleCount:function(){return this.moduleCount},make:function(){if(1>this.typeNumber){for(var a=1,a=1;40>a;a++){for(var c=p.getRSBlocks(a,this.errorCorrectLevel),d=new t,b=0,e=0;e=d;d++)if(!(-1>=a+d||this.moduleCount<=a+d))for(var b=-1;7>=b;b++)-1>=c+b||this.moduleCount<=c+b||(this.modules[a+d][c+b]= -0<=d&&6>=d&&(0==b||6==b)||0<=b&&6>=b&&(0==d||6==d)||2<=d&&4>=d&&2<=b&&4>=b?!0:!1)},getBestMaskPattern:function(){for(var a=0,c=0,d=0;8>d;d++){this.makeImpl(!0,d);var b=j.getLostPoint(this);if(0==d||a>b)a=b,c=d}return c},createMovieClip:function(a,c,d){a=a.createEmptyMovieClip(c,d);this.make();for(c=0;c=f;f++)for(var i=-2;2>=i;i++)this.modules[b+f][e+i]=-2==f||2==f||-2==i||2==i||0==f&&0==i?!0:!1}},setupTypeNumber:function(a){for(var c= -j.getBCHTypeNumber(this.typeNumber),d=0;18>d;d++){var b=!a&&1==(c>>d&1);this.modules[Math.floor(d/3)][d%3+this.moduleCount-8-3]=b}for(d=0;18>d;d++)b=!a&&1==(c>>d&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;15>b;b++){var e=!a&&1==(d>>b&1);6>b?this.modules[b][8]=e:8>b?this.modules[b+1][8]=e:this.modules[this.moduleCount-15+b][8]=e}for(b=0;15>b;b++)e=!a&&1==(d>>b&1),8>b?this.modules[8][this.moduleCount- -b-1]=e:9>b?this.modules[8][15-b-1+1]=e: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,i=this.moduleCount-1;0g;g++)if(null==this.modules[b][i-g]){var n=!1;f>>e&1));j.getMask(c,b,i-g)&&(n=!n);this.modules[b][i-g]=n;e--; -1==e&&(f++,e=7)}b+=d;if(0>b||this.moduleCount<=b){b-=d;d=-d;break}}}};o.PAD0=236;o.PAD1=17;o.createData=function(a,c,d){for(var c=p.getRSBlocks(a, -c),b=new t,e=0;e8*a)throw Error("code length overflow. ("+b.getLengthInBits()+">"+8*a+")");for(b.getLengthInBits()+4<=8*a&&b.put(0,4);0!=b.getLengthInBits()%8;)b.putBit(!1);for(;!(b.getLengthInBits()>=8*a);){b.put(o.PAD0,8);if(b.getLengthInBits()>=8*a)break;b.put(o.PAD1,8)}return o.createBytes(b,c)};o.createBytes=function(a,c){for(var d= -0,b=0,e=0,f=Array(c.length),i=Array(c.length),g=0;g>>=1;return c},getPatternPosition:function(a){return j.PATTERN_POSITION_TABLE[a-1]},getMask:function(a,c,d){switch(a){case 0:return 0==(c+d)%2;case 1:return 0==c%2;case 2:return 0==d%3;case 3:return 0==(c+d)%3;case 4:return 0==(Math.floor(c/2)+Math.floor(d/3))%2;case 5:return 0==c*d%2+c*d%3;case 6:return 0==(c*d%2+c*d%3)%2;case 7:return 0==(c*d%3+(c+d)%2)%2;default:throw Error("bad maskPattern:"+ -a);}},getErrorCorrectPolynomial:function(a){for(var c=new q([1],0),d=0;dc)switch(a){case 1:return 10;case 2:return 9;case s:return 8;case 8:return 8;default:throw Error("mode:"+a);}else if(27>c)switch(a){case 1:return 12;case 2:return 11;case s:return 16;case 8:return 10;default:throw Error("mode:"+a);}else if(41>c)switch(a){case 1:return 14;case 2:return 13;case s:return 16;case 8:return 12;default:throw Error("mode:"+ -a);}else throw Error("type:"+c);},getLostPoint:function(a){for(var c=a.getModuleCount(),d=0,b=0;b=g;g++)if(!(0>b+g||c<=b+g))for(var h=-1;1>=h;h++)0>e+h||c<=e+h||0==g&&0==h||i==a.isDark(b+g,e+h)&&f++;5a)throw Error("glog("+a+")");return l.LOG_TABLE[a]},gexp:function(a){for(;0>a;)a+=255;for(;256<=a;)a-=255;return l.EXP_TABLE[a]},EXP_TABLE:Array(256), -LOG_TABLE:Array(256)},m=0;8>m;m++)l.EXP_TABLE[m]=1<m;m++)l.EXP_TABLE[m]=l.EXP_TABLE[m-4]^l.EXP_TABLE[m-5]^l.EXP_TABLE[m-6]^l.EXP_TABLE[m-8];for(m=0;255>m;m++)l.LOG_TABLE[l.EXP_TABLE[m]]=m;q.prototype={get:function(a){return this.num[a]},getLength:function(){return this.num.length},multiply:function(a){for(var c=Array(this.getLength()+a.getLength()-1),d=0;d -this.getLength()-a.getLength())return this;for(var c=l.glog(this.get(0))-l.glog(a.get(0)),d=Array(this.getLength()),b=0;b>>7-a%8&1)},put:function(a,c){for(var d=0;d>>c-d-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);a&&(this.buffer[c]|=128>>>this.length%8);this.length++}};"string"===typeof h&&(h={text:h});h=r.extend({},{render:"canvas",width:256,height:256,typeNumber:-1, -correctLevel:2,background:"#ffffff",foreground:"#000000"},h);return this.each(function(){var a;if("canvas"==h.render){a=new o(h.typeNumber,h.correctLevel);a.addData(h.text);a.make();var c=document.createElement("canvas");c.width=h.width;c.height=h.height;for(var d=c.getContext("2d"),b=h.width/a.getModuleCount(),e=h.height/a.getModuleCount(),f=0;f").css("width",h.width+"px").css("height",h.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",h.background);d=h.width/a.getModuleCount();b=h.height/a.getModuleCount();for(e=0;e").css("height",b+"px").appendTo(c);for(i=0;i").css("width", -d+"px").css("background-color",a.isDark(e,i)?h.foreground:h.background).appendTo(f)}}a=c;jQuery(a).appendTo(this)})}})(jQuery); diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index da44e0e..d414ea9 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -1,89 +1,291 @@ -(function( $ ){ - $.fn.qrcode = function(options) { - // if options is string, - if( typeof options === 'string' ){ - options = { text: options }; - } - - // set default values - // typeNumber < 1 for automatic calculation - options = $.extend( {}, { - render : "canvas", - width : 256, - height : 256, - typeNumber : -1, - correctLevel : QRErrorCorrectLevel.H, - background : "#ffffff", - foreground : "#000000" - }, options); - - var createCanvas = function(){ - // create the qrcode itself - var qrcode = new QRCode(options.typeNumber, options.correctLevel); - qrcode.addData(options.text); - qrcode.make(); - - // create canvas element - var canvas = document.createElement('canvas'); - canvas.width = options.width; - canvas.height = options.height; - var ctx = canvas.getContext('2d'); - - // compute tileW/tileH based on options.width/options.height - var tileW = options.width / qrcode.getModuleCount(); - var tileH = options.height / qrcode.getModuleCount(); - - // draw in the canvas - for( var row = 0; row < qrcode.getModuleCount(); row++ ){ - for( var col = 0; col < qrcode.getModuleCount(); col++ ){ - ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background; - var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW)); - var h = (Math.ceil((row+1)*tileW) - Math.floor(row*tileW)); - ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h); - } - } - // return just built canvas - return canvas; - } - - // from Jon-Carlos Rivera (https://github.com/imbcmdth) - var createTable = function(){ - // create the qrcode itself - var qrcode = new QRCode(options.typeNumber, options.correctLevel); - qrcode.addData(options.text); - qrcode.make(); - - // create table element - var $table = $('
') - .css("width", options.width+"px") - .css("height", options.height+"px") - .css("border", "0px") - .css("border-collapse", "collapse") - .css('background-color', options.background); - - // compute tileS percentage - var tileW = options.width / qrcode.getModuleCount(); - var tileH = options.height / qrcode.getModuleCount(); - - // draw in the table - for(var row = 0; row < qrcode.getModuleCount(); row++ ){ - var $row = $('').css('height', tileH+"px").appendTo($table); - - for(var col = 0; col < qrcode.getModuleCount(); col++ ){ - $('') - .css('width', tileW+"px") - .css('background-color', qrcode.isDark(row, col) ? options.foreground : options.background) - .appendTo($row); - } - } - // return just built canvas - return $table; - } - - - return this.each(function(){ - var element = options.render == "canvas" ? createCanvas() : createTable(); - $(element).appendTo(this); - }); - }; -})( jQuery ); +(function($){ + + // Function taken from Alexey Ten (https://github.com/alexeyten/qr-image) + function matrix2path(matrix) { + var N = matrix.length + var filled = [] + for( var row = -1; row <= N; row++ ) + filled[row] = [] + + var path = [] + for( var row = 0; row < N; row++ ) { + for( var col = 0; col < N; col++ ) { + if( filled[row][col] ) continue + filled[row][col] = 1 + if( isDark(row, col) ) { + if( !isDark(row-1, col) ) { + path.push(plot(row, col, 'right')) + } + } else { + if( isDark(row, col-1) ) { + path.push(plot(row, col, 'down')) + } + } + } + } + return path + + function isDark(row, col) { + if( row < 0 || col < 0 || row >= N || col >= N ) return false + return !!matrix[row][col] + } + + function plot(row0, col0, dir) { + filled[row0][col0] = 1 + var res = [] + res.push(['M', col0, row0 ]) + var row = row0 + var col = col0 + var len = 0 + do { + switch( dir ) { + case 'right': + filled[row][col] = 1 + if( isDark(row, col) ) { + filled[row-1][col] = 1 + if( isDark(row-1, col) ) { + res.push(['h', len]) + len = 0 + dir = 'up' + } else { + len++ + col++ + } + } else { + res.push(['h', len]) + len = 0 + dir = 'down' + } + break + + case 'left': + filled[row-1][col-1] = 1 + if( isDark(row-1, col-1) ) { + filled[row][col-1] = 1 + if( isDark(row, col-1) ) { + res.push(['h', -len]) + len = 0 + dir = 'down' + } else { + len++ + col-- + } + } else { + res.push(['h', -len]) + len = 0 + dir = 'up' + } + break + + case 'down': + filled[row][col-1] = 1 + if( isDark(row, col-1) ) { + filled[row][col] = 1 + if( isDark(row, col) ) { + res.push(['v', len]) + len = 0 + dir = 'right' + } else { + len++ + row++ + } + } else { + res.push(['v', len]) + len = 0 + dir = 'left' + } + break + + case 'up': + filled[row-1][col] = 1 + if( isDark(row-1, col) ) { + filled[row-1][col-1] = 1 + if( isDark(row-1, col-1) ) { + res.push(['v', -len]) + len = 0 + dir = 'left' + } else { + len++ + row-- + } + } else { + res.push(['v', -len]) + len = 0 + dir = 'right' + } + break + } + } while( row != row0 || col != col0 ) + return res + } + } // matrix2path ends + + $.fn.qrcode = function(options){ + // if options is a string... + if( typeof options === 'string' ) + options = { text: options } + + // set default values + // typeNumber < 1 for automatic calculation + options = $.extend({}, { + width: 256, + height: 256, + render: "svg", + typeNumber: -1, + correctLevel: QRErrorCorrectLevel.H, + foreground: "#000", + background: "#FFF", + border: 1 + }, options) + + var createSVG = function(){ + // generate the matrix + var qrcode = new QRCode(options.typeNumber, options.correctLevel) + qrcode.addData(options.text) + qrcode.make() + + var x = qrcode.moduleCount + options.border * 2 + + var svg = '' + svg += '' + svg += '' + svg += '' + + return svg + } + + // based on code from Jon-Carlos Rivera (https://github.com/imbcmdth) + var createCanvas = function(){ + // generate the matrix + var qrcode = new QRCode(options.typeNumber, options.correctLevel) + qrcode.addData(options.text) + qrcode.make() + + // create the canvas element + var canvas = document.createElement('canvas') + $(canvas).css('background', options.background) + canvas.width = options.width + canvas.height = options.height + var ctx = canvas.getContext('2d') + ctx.fillStyle = options.foreground + + // compute tileW/tileH based on options.width/options.height + var total = (qrcode.moduleCount + options.border * 2) + var tileW = options.width / total + var tileH = options.height / total + + var w = Math.ceil(tileW) + var h = Math.ceil(tileW) + + // fill the canvas with dark rectangles + for( var row = 0; row < qrcode.moduleCount; row++ ) { + for( var col = 0; col < qrcode.moduleCount; col++ ) { + if( qrcode.isDark(row, col) ) { + var s_col = col + options.border, + s_row = row + options.border + + ctx.fillRect(Math.round(s_col*tileW), Math.round(s_row*tileH), w, h) + } + } + } + + // return the canvas code + return canvas + } + + var createTable = function(){ + // generate the matrix + var qrcode = new QRCode(options.typeNumber, options.correctLevel) + qrcode.addData(options.text) + qrcode.make() + + // create table element + var $table = $('
') + .css({ + "width": options.width+"px", + "height": options.height+"px", + "border": 0, + "border-collapse": "collapse", + "background-color": options.background + }) + + var x = qrcode.moduleCount + options.border * 2 + var tileW = options.width / x + 'px' + var tileH = options.height / x + 'px' + + // top border line(s) /////////////////// + for( var t = 0; t < options.border; t++ ) + $('').css('height', tileH).css('background-color', options.background).appendTo($table) + + // draw the table + for( var row = 0; row < qrcode.moduleCount; row++ ) + { + var $row = $('').css('height', tileH).appendTo($table) + + // left border module(s) + for( var l = 0; l < options.border; l++ ) + $('').css('width', tileW).css('background-color', options.background).appendTo($row) + + // modules + for( var col = 0; col < qrcode.moduleCount; col++ ) + { + $('').css('width', tileW) + .css('background-color', options[ (qrcode.isDark(row, col)) ? 'foreground' : 'background' ]) + .appendTo($row) + } + + // right border module(s) + for( var r = 0; r < options.border; r++ ) + $('').css('width', tileW).css('background-color', options.background).appendTo($row) + } + + // bottom border line(s) //////////////// + for( var b = 0; b < options.border; b++ ) + $('').css('height', tileH).css('background-color', options.background).appendTo($table) + + // return the table code + return $table + } + + // Returns an DOM element with a dataURI generated from createSVG + var createImage = function() { + return $('').attr('src', 'data:image/svg+xml;base64,'+btoa(createSVG())) + } + + return this.each(function(){ + switch( options.render ) { + default: + case 'svg': + var element = createSVG() + break + + case 'image': + var element = createImage() + break + + case 'canvas': + var element = createCanvas() + break + + case 'table': + var element = createTable() + } + + $(element).appendTo(this) + }) + } +})( jQuery ) + From 1058de47c9d7320ac0bc64a6c7c14bd8844bb5fc Mon Sep 17 00:00:00 2001 From: x Date: Thu, 12 Jun 2014 22:01:55 -0400 Subject: [PATCH 2/8] small fixes --- MIT-LICENSE.txt => LICENSE | 0 README.md | 6 +++--- src/jquery.qrcode.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename MIT-LICENSE.txt => LICENSE (100%) diff --git a/MIT-LICENSE.txt b/LICENSE similarity index 100% rename from MIT-LICENSE.txt rename to LICENSE diff --git a/README.md b/README.md index 28b7212..dd430b7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Show, dont tell, here is a live. You can set the height and width of the generated qrcode: - jquery('#qrcode').qrcode({width: 64,height: 64,text: "size doesn't matter"}); + $('#qrcode').qrcode({width: 64, height: 64, text: "size doesn't matter"}); ## Conclusion diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index d414ea9..53a0f08 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -188,9 +188,9 @@ var tileH = options.height / total var w = Math.ceil(tileW) - var h = Math.ceil(tileW) + var h = Math.ceil(tileH) - // fill the canvas with dark rectangles + fill the canvas with dark rectangles for( var row = 0; row < qrcode.moduleCount; row++ ) { for( var col = 0; col < qrcode.moduleCount; col++ ) { if( qrcode.isDark(row, col) ) { From 16ebf96d5df1af79b705352873fd9a5303a3b8a7 Mon Sep 17 00:00:00 2001 From: x Date: Thu, 12 Jun 2014 22:18:02 -0400 Subject: [PATCH 3/8] Table scaling fixed --- src/jquery.qrcode.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 53a0f08..a344bcb 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -190,7 +190,7 @@ var w = Math.ceil(tileW) var h = Math.ceil(tileH) - fill the canvas with dark rectangles + // fill the canvas with dark rectangles for( var row = 0; row < qrcode.moduleCount; row++ ) { for( var col = 0; col < qrcode.moduleCount; col++ ) { if( qrcode.isDark(row, col) ) { @@ -212,6 +212,14 @@ qrcode.addData(options.text) qrcode.make() + var x = qrcode.moduleCount + options.border * 2 + + // Squeezing fix from Paul Marbach (@fastfrwrd) + if( options.width % x ) + options.width = Math.floor(options.width / x) * x + if( options.height % x ) + options.height = Math.floor(options.height / x) * x + // create table element var $table = $('
') .css({ @@ -221,10 +229,10 @@ "border-collapse": "collapse", "background-color": options.background }) - - var x = qrcode.moduleCount + options.border * 2 - var tileW = options.width / x + 'px' - var tileH = options.height / x + 'px' + // compute tiles percentage + // these should NOT be decimal values as this can get really hairy + var tileW = Math.floor(options.width / x) + var tileH = Math.floor(options.height / x) // top border line(s) /////////////////// for( var t = 0; t < options.border; t++ ) From 8efc1043138a5dc3d149eab5c942304869648f26 Mon Sep 17 00:00:00 2001 From: x Date: Wed, 18 Jun 2014 10:10:00 -0400 Subject: [PATCH 4/8] allow the element to be returned instead of appended --- src/jquery.qrcode.js | 14 ++++++++++---- src/qrcode.js | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index a344bcb..325f0cb 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -128,6 +128,7 @@ // set default values // typeNumber < 1 for automatic calculation options = $.extend({}, { + append: true, width: 256, height: 256, render: "svg", @@ -187,9 +188,6 @@ var tileW = options.width / total var tileH = options.height / total - var w = Math.ceil(tileW) - var h = Math.ceil(tileH) - // fill the canvas with dark rectangles for( var row = 0; row < qrcode.moduleCount; row++ ) { for( var col = 0; col < qrcode.moduleCount; col++ ) { @@ -197,6 +195,8 @@ var s_col = col + options.border, s_row = row + options.border + var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW)); + var h = (Math.ceil((row+1)*tileW) - Math.floor(row*tileW)); ctx.fillRect(Math.round(s_col*tileW), Math.round(s_row*tileH), w, h) } } @@ -292,7 +292,13 @@ var element = createTable() } - $(element).appendTo(this) + if( options.append ) { + return this.each(function(){ + $(element).appendTo(this) + }) + } else { + return $(element) + } }) } })( jQuery ) diff --git a/src/qrcode.js b/src/qrcode.js index 7775c90..c6e9c59 100644 --- a/src/qrcode.js +++ b/src/qrcode.js @@ -26,7 +26,7 @@ function QR8bitByte(data) { QR8bitByte.prototype = { getLength : function(buffer) { - return this.data.length; + return (this.data) ? this.data.length : 0; }, write : function(buffer) { @@ -41,7 +41,7 @@ QR8bitByte.prototype = { // QRCode //--------------------------------------------------------------------- -function QRCode(typeNumber, errorCorrectLevel) { +QRCode = function(typeNumber, errorCorrectLevel) { this.typeNumber = typeNumber; this.errorCorrectLevel = errorCorrectLevel; this.modules = null; @@ -490,7 +490,7 @@ var QRMode = { // QRErrorCorrectLevel //--------------------------------------------------------------------- -var QRErrorCorrectLevel = { +QRErrorCorrectLevel = { L : 1, M : 0, Q : 3, @@ -1235,3 +1235,4 @@ QRBitBuffer.prototype = { this.length++; } }; + From f0b0b91ca7d833a33d102ab4a527d9b9135072ab Mon Sep 17 00:00:00 2001 From: x Date: Sat, 21 Jun 2014 20:44:36 -0400 Subject: [PATCH 5/8] fixed one little bug, setting size for --- src/jquery.qrcode.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 325f0cb..6a98521 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -129,9 +129,9 @@ // typeNumber < 1 for automatic calculation options = $.extend({}, { append: true, + render: "svg", width: 256, height: 256, - render: "svg", typeNumber: -1, correctLevel: QRErrorCorrectLevel.H, foreground: "#000", @@ -270,7 +270,8 @@ // Returns an DOM element with a dataURI generated from createSVG var createImage = function() { - return $('').attr('src', 'data:image/svg+xml;base64,'+btoa(createSVG())) + return $('') + .attr('src', 'data:image/svg+xml;base64,'+btoa(createSVG())) } return this.each(function(){ @@ -292,13 +293,10 @@ var element = createTable() } - if( options.append ) { - return this.each(function(){ - $(element).appendTo(this) - }) - } else { + if( options.append ) + $(this).append(element) + else return $(element) - } }) } })( jQuery ) From 59970a2d63f777dab08bbb015a41053cb4ac0439 Mon Sep 17 00:00:00 2001 From: "..." Date: Thu, 17 Jul 2014 17:40:48 -0400 Subject: [PATCH 6/8] $.fn.qrcode() now returns a plaintext string got rid of options.append use $( $.fn.qrcode('string') ) to get a DOM element or to use with templates old $('div, p').qrcode('string') still works --- src/jquery.qrcode.js | 54 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 6a98521..9d2c63d 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -128,7 +128,6 @@ // set default values // typeNumber < 1 for automatic calculation options = $.extend({}, { - append: true, render: "svg", width: 256, height: 256, @@ -139,7 +138,7 @@ border: 1 }, options) - var createSVG = function(){ + var createSVG = function(noXML){ // generate the matrix var qrcode = new QRCode(options.typeNumber, options.correctLevel) qrcode.addData(options.text) @@ -147,10 +146,10 @@ var x = qrcode.moduleCount + options.border * 2 - var svg = '' - svg += '' - svg += '' - svg += '' : '' + svg+= '' + svg+= '' + svg+= ' Date: Thu, 17 Jul 2014 17:41:47 -0400 Subject: [PATCH 7/8] small fix --- src/jquery.qrcode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 9d2c63d..c7abe85 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -146,7 +146,7 @@ var x = qrcode.moduleCount + options.border * 2 - var svg = (noXML) ? '' : '' + var svg = (noXML) ? '' : '' svg+= '' svg+= '' svg+= ' Date: Thu, 11 Sep 2014 14:24:12 -0400 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd430b7..58f9fd8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jquery.qrcode.js +# jquery-qrcode jquery.qrcode.js is *jquery plugin for a pure browser qrcode generation*.