Browse files

jquery.qrcode.js: initial version

  • Loading branch information...
1 parent 9a1b2af commit 9cd4d877ff1331fbbab97122e8a553d82fbccd09 @jeromeetienne committed Apr 7, 2011
Showing with 34 additions and 0 deletions.
  1. +34 −0 jquery.qrcode.js
View
34 jquery.qrcode.js
@@ -0,0 +1,34 @@
+(function( $ ){
+ $.fn.qrcode = function(options) {
+
+ var createCanvas = function(text, typeNumber){
+ var tileW = 4;
+
+ // create the qrcode itself
+ var qrcode = new QRCode(typeNumber, QRErrorCorrectLevel.H);
+ qrcode.addData(text);
+ qrcode.make();
+
+ // create canvas element
+ var canvas = document.createElement('canvas');
+ canvas.width = canvas.height = qrcode.getModuleCount()*tileW;
+ var ctx = canvas.getContext('2d');
+
+ for( var row = 0; row < qrcode.getModuleCount(); row++ ){
+ for( var col = 0; col < qrcode.getModuleCount(); col++ ){
+ ctx.fillStyle = qrcode.isDark(row, col) ? "#000000" : "#ffffff";
+ ctx.fillRect( col*tileW, row*tileW, tileW, tileW );
+ }
+ }
+ // return just built canvas
+ return canvas;
+ }
+
+ return this.each(function(){
+ var $this = $(this);
+
+ var canvas = createCanvas("http://jetienne.com", 4);
+ jQuery(canvas).appendTo($this);
+ });
+ };
+})( jQuery );

0 comments on commit 9cd4d87

Please sign in to comment.