1 line
1.3 KiB
JavaScript
1 line
1.3 KiB
JavaScript
!function(a){a.fn.qrcode=function(b){"string"==typeof b&&(b={text:b}),b=a.extend({},{render:"canvas",width:256,height:256,typeNumber:-1,correctLevel:QRErrorCorrectLevel.H,background:"#ffffff",foreground:"#000000"},b);var c=function(){var a=new QRCode(b.typeNumber,b.correctLevel);a.addData(b.text),a.make();var c=document.createElement("canvas");c.width=b.width,c.height=b.height;for(var d=c.getContext("2d"),e=b.width/a.getModuleCount(),f=b.height/a.getModuleCount(),g=0;g<a.getModuleCount();g++)for(var h=0;h<a.getModuleCount();h++){d.fillStyle=a.isDark(g,h)?b.foreground:b.background;var i=Math.ceil((h+1)*e)-Math.floor(h*e),j=Math.ceil((g+1)*e)-Math.floor(g*e);d.fillRect(Math.round(h*e),Math.round(g*f),i,j)}return c},d=function(){var c=new QRCode(b.typeNumber,b.correctLevel);c.addData(b.text),c.make();for(var d=a("<table></table>").css("width",b.width+"px").css("height",b.height+"px").css("border","0px").css("border-collapse","collapse").css("background-color",b.background),e=b.width/c.getModuleCount(),f=b.height/c.getModuleCount(),g=0;g<c.getModuleCount();g++)for(var h=a("<tr></tr>").css("height",f+"px").appendTo(d),i=0;i<c.getModuleCount();i++)a("<td></td>").css("width",e+"px").css("background-color",c.isDark(g,i)?b.foreground:b.background).appendTo(h);return d};return this.each(function(){var e="canvas"==b.render?c():d();a(e).appendTo(this)})}}(jQuery); |