File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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 ) ;
You can’t perform that action at this time.
0 commit comments