From 58c816747985f88e1ff91f46129a30421c28d388 Mon Sep 17 00:00:00 2001 From: Jerome Etienne Date: Thu, 29 Sep 2011 14:40:19 +0200 Subject: [PATCH] src/jquery.qrcode.js including build from imbcmdth (Jon-Carlos Rivera) --- src/jquery.qrcode.js | 47 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index a6cc4d3..441aede 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -19,14 +19,17 @@ 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++ ){ @@ -38,9 +41,49 @@ 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(); + + 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 = $('
') + .css("width", options.width+"px") + .css("height", options.height+"px") + .css("border", "0px") + .css("border-collapse", "collapse") + .css("margin", border_width+"px") + .css('background-color', "#ffffff"); + + // compute tileS percentage + tileS = 100 / qrcode.getModuleCount(); + + // draw in the table + for(row = 0; row < qrcode.getModuleCount(); row++ ){ + $row = $('').css('height', tileS+"%").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"); + } + } + // return just built canvas + return $table; + } + + return this.each(function(){ - var canvas = createCanvas(); - jQuery(canvas).appendTo(this); + //var element = createCanvas(); + var element = createTable(); + jQuery(element).appendTo(this); }); }; })( jQuery );