forked from siciarek/javascript-qrcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
593 lines (494 loc) · 22.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>QR Code Model 2</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css"/>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css"/>
<style>
@import url(https://fonts.googleapis.com/css?family=Roboto+Slab|Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic&subset=latin-ext);
body {
background-color: #FFFFFF;
font-family: 'Open Sans', sans-serif;
font-weight: 400;
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
color: #555555 !important;
font-family: 'Roboto Slab', serif;
line-height: 1.3;
}
.navbar-brand {
font-family: 'Roboto Slab', serif;
}
#canvas {
image-rendering: -moz-crisp-edges; /* FF 6.0+ */
image-rendering: -webkit-optimize-contrast; /* Webkit */
/* (Safari now, Chrome soon) */
image-rendering: -o-crisp-edges; /* OS X & Windows Opera (12.02+) */
image-rendering: optimize-contrast; /* Possible future browsers. */
-ms-interpolation-mode: nearest-neighbor; /* IE */
}
.canvas {
text-align: center;
padding-top: 32px;
padding-bottom: 32px;
background-color: #EEEEEE;
border: 1px solid #CCCCCC;
border-radius: 4px;
}
.page-header {
margin-top: 0;
}
form.form-horizontal textarea {
resize: vertical;
}
form.form-horizontal .input-group label {
min-width: 130px;
text-align: right;
vertical-align: top;
padding-top: 9px;
}
form.form-horizontal .input-group {
margin-bottom: 8px;
}
.info.list-group {
box-shadow: none;
}
.info .list-group-item {
display: table-row;
}
.info div {
display: table-cell;
padding-bottom: 8px;
}
.info div.label {
color: #555555 !important;
font-size: 1em;
text-align: right;
margin-right: 4px
}
.info div.data {
white-space: pre-wrap;
word-break: break-all;
}
.info div.label:after {
content: ':'
}
</style>
</head>
<body>
<div id="wrap">
<div class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">
<i class="icon-qrcode"></i>
QR Code Model 2
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a title="References" class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-book icon-large"></i>
References
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li class="dropdown-header">Inventor’s Page</li>
<li><a target="_blank" href="http://www.qrcode.com/en/">QRcode.com|DENSO WAVE</a></li>
<li class="divider"></li>
<li class="dropdown-header">Info</li>
<li><a target="_blank" href="http://en.wikipedia.org/wiki/QR_code">QR code - Wikipedia, the free encyclopedia</a></li>
<li class="divider"></li>
<li class="dropdown-header">Documentation</li>
<li><a target="_blank" href="http://www.swisseduc.ch/informatik/theoretische_informatik/qr_codes/docs/qr_standard.pdf">INTERNATIONAL STANDARD ISO/IEC 18004</a></li>
<li class="divider"></li>
<li class="dropdown-header">Tutorials</li>
<li><a target="_blank" href="http://www.thonky.com/qr-code-tutorial/">QR Code Tutorial</a></li>
<li><a target="_blank" href="http://www.swetake.com/qrcode/index-e.html">QRCode (Tutorial and demo)</a></li>
<li class="divider"></li>
<li class="dropdown-header">QR Code Desktop Reader</li>
<li><a target="_blank" href="http://www.codetwo.pl/freeware/qr-code-desktop-reader/">CodeTwo QR Code Desktop Reader</a>
<li class="dropdown-header">QR Code Commandline Decoder</li>
<li><a target="_blank" href="http://zbar.sourceforge.net/">ZBar bar code reader</a>
</li>
</ul>
</li>
<li class="dropdown">
<a title="Examples" class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-edit icon-large"></i>
Examples
<b class="caret"></b>
</a>
<ul class="dropdown-menu examples">
<li><a href="#">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a></li>
<li><a href="#">Pchnąć w tę łódź jeża lub ośm skrzyń fig.</a></li>
<li><a href="#">Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч.</a></li>
<li><a href="#">El jefe buscó el éxtasis en un imprevisto baño de whisky y gozó como un duque.</a></li>
<li><a href="#">川月木心火左北今名美見外成空明静海雲新語道聞強飛</a></li>
<li><a href="#">דג סקרן שט בים מאוכזב ולפתע מצא חברה</a></li>
<li><a href="#">키스의 고유조건은 입술끼리 만나야 하고 특별한 기술은 필요치 않다.</a></li>
<li><a href="#">À noite, vovô Kowalsky vê o ímã cair no pé do pingüim queixoso e vovó põe açúcar no chá de tâmaras do jabuti feliz.</a></li>
<li><a href="#">Ταχίστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός</a></li>
<li><a href="#">Ça me fait peur de fêter noël là, sur cette île bizarroïde où une mère et sa môme essaient de me tuer avec un gâteau à la cigüe brûlé.</a></li>
</ul>
</li>
<li>
<a target="_blank" title="Tests" href="qunit/index.src.html">
<i class="icon-wrench icon-large"></i>
Tests
</a>
</li>
<li>
<a target="_blank" title="GitHub" href="https://github.com/siciarek/javascript-qrcode">
<i class="icon-github icon-large"></i>
Source on GitHub
</a>
</li>
<li>
<a target="_blank" title="NPM" href="https://www.npmjs.org/package/javascript-qrcode">
<i class="icon-info-sign icon-large"></i>
Module on NPM
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="page-header">
<h1>
<i class="icon-qrcode text-muted"></i>
QR Code Model 2
</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<form class="form-horizontal qrcode-form">
<div class="input-group">
<label class="input-group-addon" for="data">Data</label>
<textarea name="data" id="data" class="form-control" rows="5" placeholder="Insert textual data"></textarea>
</div>
<span class="help-block data"></span>
<div class="input-group">
<label class="input-group-addon" for="ec">Error Correction</label>
<select name="ec" id="ec" class="form-control">
<option title="Level L (Low) ~7% of codewords can be restored." value="L">Level L (Low) ~7% of codewords can be
restored.
</option>
<option title="Level M (Medium) ~15% of codewords can be restored." value="M" selected="selected">Level M (Medium) ~15% of
codewords can be restored.
</option>
<option title="Level Q (Quartile) ~25% of codewords can be restored." value="Q">Level Q (Quartile) ~25% of codewords can
be restored.
</option>
<option title="Level H (High) ~30% of codewords can be restored." value="H">Level H (High) ~30% of codewords can be
restored.
</option>
</select>
</div>
<div class="input-group">
<label class="input-group-addon" for="version">Version</label>
<select name="version" id="version" class="form-control">
<option value="0" selected="selected">Auto</option>
</select>
</div>
<div class="input-group">
<label class="input-group-addon" for="version">Mask Pattern</label>
<select name="mask" id="mask" class="form-control">
<option value="" selected="selected">Auto</option>
<option value="-1">Raw Data</option>
</select>
</div>
<div class="input-group">
<label class="input-group-addon" for="size">Module Size</label>
<select name="size" id="size" class="form-control">
<option value="2">Small</option>
<option value="3" selected="selected">Medium</option>
<option value="5">Large</option>
</select>
</div>
<br/>
<a href="javascript:void(null)" id="generate-qrcode" class="btn btn-default btn-lg pull-right hidden">
<i class="icon-cog text-muted"></i>
Generate
</a>
<div class="clearfix"></div>
<br/>
<br/>
</form>
</div>
<div class="col-md-6">
<div class="canvas center">
<canvas id="canvas"></canvas>
</div>
<div>
<h3>
<i class="icon-info-sign text-muted"></i>
Info
</h3>
<div id="info"></div>
</div>
</div>
</div>
</div>
</div>
<script src="//code.jquery.com/jquery.js"></script>
<script src="//cdn.jsdelivr.net/jquery.cookie/1.3.1/jquery.cookie.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="src/Utils.js"></script>
<script src="src/QrCode/Exceptions.js"></script>
<script src="src/QrCode/GeneratorPolynominal.js"></script>
<script src="src/QrCode/Config.js"></script>
<script src="src/QrCode/ErrorCorrection.js"></script>
<script src="src/QrCode/DataEncoder.js"></script>
<script src="src/QrCode/DataAnalyzer.js"></script>
<script src="src/QrCode/Matrix.js"></script>
<script src="src/QrCode/Matrix.js"></script>
<script src="src/QrCode/Mask.js"></script>
<script src="src/QrCode/Evaluation.js"></script>
<script src="src/QrCode/QrCode.js"></script>
<script>
var data = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
var ecstrategy = ['M'];
var version = null;
var maskPattern = null;
var maskTest = false;
var quietZoneSize = 4;
var modulesize = 3;
/**
* HTTP HttpRequest support
* @constructor
*/
var HttpRequest = function () {
this.href = location.href;
this.host = this.href.split('?').shift();
this.query = this.href.split('?').pop();
this.params = this.getParams();
};
HttpRequest.prototype.constructor = HttpRequest;
HttpRequest.prototype.getParams = function () {
var params = {};
if (location.search) {
var parts = location.search.slice(1).split('&');
parts.forEach(function (part) {
var pair = part.split('=');
pair[0] = decodeURIComponent(pair[0]);
pair[1] = decodeURIComponent(pair[1]);
params[pair[0]] = (pair[1] !== 'undefined') ? pair[1] : true;
});
}
return params;
};
function setInfo(info) {
var size = 4 * (info.version - 1) + 21;
info.size = size + ' × ' + size;
var fields = {
version: 'Version',
size: 'Size',
mode: 'Mode',
eclevel: 'Error Correction',
pattern: 'Mask Pattern',
capacity: 'Max Capacity',
charcount: 'Character Count',
datalen: 'Data Size',
data: 'Data'
};
var html = '';
html += '<ul class="list-group info">';
for (var key in fields) {
if (fields.hasOwnProperty(key) && info.hasOwnProperty(key)) {
var value = info[key];
var field = fields[key];
if (key === 'eclevel') {
value = $('select[name="ec"]').find('option[value="' + value + '"]').text();
}
else if (key === 'datalen') {
value += ' B';
}
html += '<li class="list-group-item"><div class="label">' + field + '</div><div class="' + key + '">' + value + '</div></li>';
}
}
html += '</ul>';
$('#info').html(html);
}
function draw(code, blocksize, quietZoneSize) {
blocksize = blocksize || 4;
quietZoneSize = quietZoneSize || 4;
var colors = {};
colors[code.matrix.DATA_DARK_MODULE] = '#000000';
colors[code.matrix.DATA_LIGHT_MODULE] = '#FFFFFF';
colors[code.matrix.DATA_UNDEFINED_MODULE] = '#CCCCCC';
var quietZone = quietZoneSize * blocksize;
var size = code.getSize() * blocksize + 2 * quietZone;
var grid = code.getData();
console.log(grid.toSource());
var canvas = document.getElementById('canvas');
canvas.setAttribute('width', size);
canvas.setAttribute('height', size);
var context = canvas.getContext('2d');
context.beginPath();
context.fillStyle = colors[code.matrix.DATA_LIGHT_MODULE];
context.rect(0, 0, size, size);
context.fill();
for (var top = 0; top < grid.length; top++) {
for (var left = 0; left < grid[0].length; left++) {
if (grid[top][left] !== 0) {
context.beginPath();
context.fillStyle = colors[grid[top][left]];
context.rect(quietZone + left * blocksize, quietZone + top * blocksize, blocksize, blocksize);
context.fill();
}
}
}
}
var request = new HttpRequest();
if (request.params.hasOwnProperty('data')) {
data = request.params['data'];
}
if (request.params.hasOwnProperty('ec')) {
ecstrategy = [request.params['ec']];
}
if (request.params.hasOwnProperty('mp')) {
maskPattern = request.params['mp'];
}
if (request.params.hasOwnProperty('mt')) {
maskTest = request.params['mt'] == 1;
}
if (request.params.hasOwnProperty('version')) {
version = request.params['version'];
}
if (request.params.hasOwnProperty('size')) {
var temp = parseInt(request.params['size']);
modulesize = !isNaN(temp) && temp > 0 ? temp : modulesize;
}
function run(data, ecstrategy, maskPattern, version, modulesize, quietZoneSize, dataOnly) {
dataOnly = dataOnly || false;
try {
var qrcode = new QrCode(data, ecstrategy, maskPattern, version, dataOnly, maskTest);
draw(qrcode, modulesize, quietZoneSize);
var info = qrcode.getInfo();
info.charcount = data.length;
setInfo(qrcode.getInfo());
}
catch (e) {
$('.qrcode-form .help-block.data').html(e.toString());
}
}
run(data, ecstrategy, maskPattern, version, modulesize, quietZoneSize, false);
</script>
<script>
function clearCanvas(context, canvas) {
context.clearRect(0, 0, canvas.width, canvas.height);
var w = canvas.width;
canvas.width = 1;
canvas.width = w;
}
$(document).ready(function () {
var o;
$('.dropdown-menu.examples').on('click', 'li a', function (e) {
e.preventDefault();
var self = $(this);
$('.qrcode-form textarea').val(self.html()).trigger('keyup');
});
$('.qrcode-form textarea').val(data);
for (o = 1; o <= 40; o++) {
$('.qrcode-form select[name="version"]').append('<option value="' + o + '">' + o + '</option>');
}
for (o = 0; o < 8; o++) {
$('.qrcode-form select[name="mask"]').append('<option value="' + o + '">' + o + '</option>');
}
$('.qrcode-form')
.on('change', 'select', function () {
var self = $(this);
if (self.attr('name') === 'version') {
if (self.val() > 35) {
$('#size').val(2);
} else {
$('#size').val(3);
}
}
$('#generate-qrcode').trigger('click');
})
.on('focus', 'textarea', function () {
var self = $(this);
var val = self.val();
// self.attr('tempval', val);
// self.val('');
})
.on('blur', 'textarea', function () {
var self = $(this);
var val = self.val();
if (val.trim().length === 0) {
self.val(self.attr('tempval'));
}
self.removeAttr('tempval');
})
.on('keyup', 'textarea', function () {
var border = {
ok: {
'border-color': '#66AFE9',
'box-shadow': '0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(102, 175, 233, 0.6)'
},
notok: {
'border-color': '#FF7777',
'box-shadow': '0 1px 1px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(233, 175, 102, 0.6)'
}
};
var br = 'notok';
if ($(this).val().length > 0) {
br = 'ok';
$('.qrcode-form .help-block.data').html('');
}
else {
$('.info .list-group-item div.data').html('<em class="text-muted">empty</em>');
$('.info .list-group-item div.charcount').html('<em class="text-muted">0</em>');
$('.info .list-group-item div.datalen').html('<em class="text-muted">0 B</em>');
}
$('.form-control:focus').css(border[br]);
$('#generate-qrcode').trigger('click');
});
$('#generate-qrcode').click(function () {
var quietZoneSize = 4;
var maskPattern = null;
var dataOnly = false;
var mask = $('.form-horizontal *[name="mask"]').val();
mask = parseInt(mask);
if (!isNaN(mask) && mask >= 0 && mask < 8) {
maskPattern = parseInt(mask);
}
else if (isNaN(mask)) {
maskPattern = null;
}
else if (mask < 0) {
dataOnly = true;
}
var data = $('.form-horizontal *[name="data"]').val();
var ec = $('.form-horizontal *[name="ec"]').val();
var version = $('.form-horizontal *[name="version"]').val();
version = version == 0 ? null : version;
var modulesize = $('.form-horizontal *[name="size"]').val();
var ecstrategy = [ec];
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.webkitImageSmoothingEnabled = false;
clearCanvas(context, canvas);
run(data, ecstrategy, maskPattern, version, modulesize, quietZoneSize, dataOnly);
});
});
</script>
</body>
</html>