jquery.qrcode.js: initial version
This commit is contained in:
parent
9a1b2af560
commit
9cd4d877ff
1 changed files with 34 additions and 0 deletions
34
jquery.qrcode.js
Normal file
34
jquery.qrcode.js
Normal file
|
|
@ -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 );
|
||||
Loading…
Reference in a new issue