1(function( $ ){ 2 $.fn.qrcode = function(options) { 3 // if options is string, 4 if( typeof options === 'string' ){ 5 options = { text: options }; 6 } 7 8 // set default values 9 // typeNumber < 1 for automatic calculation 10 options = $.extend( {}, { 11 render : "canvas", 12 width : 256, 13 height : 256, 14 typeNumber : -1, 15 correctLevel : QRErrorCorrectLevel.H, 16 background : "#ffffff", 17 foreground : "#000000" 18 }, options); 19 20 var createCanvas = function(){ 21 // create the qrcode itself 22 var qrcode = new QRCode(options.typeNumber, options.correctLevel); 23 qrcode.addData(options.text); 24 qrcode.make(); 25 26 // create canvas element 27 var canvas = document.createElement('canvas'); 28 canvas.width = options.width; 29 canvas.height = options.height; 30 var ctx = canvas.getContext('2d'); 31 32 // compute tileW/tileH based on options.width/options.height 33 var tileW = options.width / qrcode.getModuleCount(); 34 var tileH = options.height / qrcode.getModuleCount(); 35 36 // draw in the canvas 37 for( var row = 0; row < qrcode.getModuleCount(); row++ ){ 38 for( var col = 0; col < qrcode.getModuleCount(); col++ ){ 39 ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background; 40 var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW)); 41 var h = (Math.ceil((row+1)*tileH) - Math.floor(row*tileH)); 42 ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h); 43 } 44 } 45 // return just built canvas 46 return canvas; 47 } 48 49 // from Jon-Carlos Rivera (https://github.com/imbcmdth) 50 var createTable = function(){ 51 // create the qrcode itself 52 var qrcode = new QRCode(options.typeNumber, options.correctLevel); 53 qrcode.addData(options.text); 54 qrcode.make(); 55 56 // create table element 57 var $table = $('<table></table>') 58 .css("width", options.width+"px") 59 .css("height", options.height+"px") 60 .css("border", "0px") 61 .css("border-collapse", "collapse") 62 .css('background-color', options.background); 63 64 // compute tileS percentage 65 var tileW = options.width / qrcode.getModuleCount(); 66 var tileH = options.height / qrcode.getModuleCount(); 67 68 // draw in the table 69 for(var row = 0; row < qrcode.getModuleCount(); row++ ){ 70 var $row = $('<tr></tr>').css('height', tileH+"px").appendTo($table); 71 72 for(var col = 0; col < qrcode.getModuleCount(); col++ ){ 73 $('<td></td>') 74 .css('width', tileW+"px") 75 .css('background-color', qrcode.isDark(row, col) ? options.foreground : options.background) 76 .appendTo($row); 77 } 78 } 79 // return just built canvas 80 return $table; 81 } 82 83 84 return this.each(function(){ 85 var element = options.render == "canvas" ? createCanvas() : createTable(); 86 $(element).appendTo(this); 87 }); 88 }; 89})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.