Skip to content

Commit 9cd4d87

Browse files
committed
jquery.qrcode.js: initial version
1 parent 9a1b2af commit 9cd4d87

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

jquery.qrcode.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(function( $ ){
2+
$.fn.qrcode = function(options) {
3+
4+
var createCanvas = function(text, typeNumber){
5+
var tileW = 4;
6+
7+
// create the qrcode itself
8+
var qrcode = new QRCode(typeNumber, QRErrorCorrectLevel.H);
9+
qrcode.addData(text);
10+
qrcode.make();
11+
12+
// create canvas element
13+
var canvas = document.createElement('canvas');
14+
canvas.width = canvas.height = qrcode.getModuleCount()*tileW;
15+
var ctx = canvas.getContext('2d');
16+
17+
for( var row = 0; row < qrcode.getModuleCount(); row++ ){
18+
for( var col = 0; col < qrcode.getModuleCount(); col++ ){
19+
ctx.fillStyle = qrcode.isDark(row, col) ? "#000000" : "#ffffff";
20+
ctx.fillRect( col*tileW, row*tileW, tileW, tileW );
21+
}
22+
}
23+
// return just built canvas
24+
return canvas;
25+
}
26+
27+
return this.each(function(){
28+
var $this = $(this);
29+
30+
var canvas = createCanvas("http://jetienne.com", 4);
31+
jQuery(canvas).appendTo($this);
32+
});
33+
};
34+
})( jQuery );

0 commit comments

Comments
 (0)