0
|
1 <!doctype html>
|
|
2 <head>
|
|
3 <meta charset="utf-8">
|
5
|
4 <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
0
|
5 <title>QR Code Generator</title>
|
|
6
|
|
7 <style type="text/css">
|
|
8 * {
|
|
9 box-sizing: border-box;
|
|
10 }
|
|
11
|
|
12 html {
|
|
13 height: 100%;
|
|
14 margin: 0;
|
|
15 padding: 0;
|
7
|
16 font-family: Arial, sans-serif;
|
0
|
17 font-size: 12px;
|
|
18 }
|
|
19
|
|
20 body {
|
|
21 margin: 0;
|
|
22 padding: 10px;
|
|
23 height: 100%;
|
|
24 }
|
|
25
|
|
26 .inputbox {
|
|
27 width: 100%;
|
|
28 margin-bottom: 10px;
|
|
29 resize: vertical;
|
7
|
30 font-family: Courier New, monospace;
|
5
|
31 /* prevent ios zoom */
|
|
32 font-size: 16px;
|
0
|
33 }
|
|
34
|
|
35 .page {
|
|
36 width: 100%;
|
7
|
37 min-height: 100%;
|
0
|
38 max-width: 600px;
|
|
39 margin: 0 auto;
|
|
40 display: flex;
|
|
41 flex-direction: column;
|
|
42 padding: 10px;
|
|
43 }
|
|
44
|
|
45 .page__main {
|
|
46 flex: 1;
|
|
47 }
|
|
48
|
1
|
49 .outputbox {
|
|
50 will-change: opacity;
|
|
51 }
|
|
52
|
|
53 .outputbox.js-hidden {
|
|
54 opacity: 0;
|
|
55 }
|
|
56
|
10
|
57 .outputbox > img {
|
|
58 max-width: 100%;
|
|
59 max-height: 100vh;
|
|
60 }
|
|
61
|
0
|
62 .title {
|
|
63 font-size: 16px;
|
|
64 }
|
|
65 </style>
|
|
66 </head>
|
|
67 <body>
|
|
68 <div class="page">
|
|
69 <div class="page__main">
|
|
70 <h1>QR Code Generator</h1>
|
|
71
|
|
72 <p>
|
2
|
73 Type something and get its QR code (almost) immediately.
|
0
|
74 </p>
|
|
75
|
|
76 <textarea class="inputbox js-qr-input" rows="4" autofocus></textarea>
|
|
77
|
1
|
78 <div class="outputbox js-qr-output"></div>
|
0
|
79 </div>
|
|
80
|
|
81 <div>
|
|
82 <hr>
|
|
83
|
|
84 <a href="https://bitbucket.org/nanaya1/qr-html">Source</a>
|
|
85 </div>
|
|
86 </div>
|
|
87
|
|
88 <script src="qrcode.min.js"></script>
|
|
89
|
|
90 <script>
|
9
|
91 var inputDom = document.querySelector(".js-qr-input")
|
|
92 var outputDom = document.querySelector(".js-qr-output")
|
10
|
93 var qr = new QRCode(outputDom, { correctLevel: QRCode.CorrectLevel.L, width: 1024, height: 1024 })
|
0
|
94
|
4
|
95 var runTimeout = null
|
|
96 var debouncedRefreshCode = function() {
|
|
97 clearTimeout(runTimeout)
|
|
98 runTimeout = setTimeout(refreshCode, 100)
|
|
99 }
|
|
100
|
3
|
101 var refreshCode = function() {
|
|
102 var text = inputDom.value
|
0
|
103
|
|
104 if (text !== "") {
|
2
|
105 qr.makeCode(text)
|
|
106 outputDom.classList.remove('js-hidden')
|
1
|
107 } else {
|
2
|
108 outputDom.classList.add('js-hidden')
|
0
|
109 }
|
2
|
110 }
|
|
111
|
4
|
112 inputDom.addEventListener('input', debouncedRefreshCode)
|
3
|
113 refreshCode()
|
0
|
114 </script>
|
|
115 </body>
|