| 
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 
 | 
| 
0
 | 
    57         .title {
 | 
| 
 | 
    58             font-size: 16px;
 | 
| 
 | 
    59         }
 | 
| 
 | 
    60     </style>
 | 
| 
 | 
    61 </head>
 | 
| 
 | 
    62 <body>
 | 
| 
 | 
    63     <div class="page">
 | 
| 
 | 
    64         <div class="page__main">
 | 
| 
 | 
    65             <h1>QR Code Generator</h1>
 | 
| 
 | 
    66 
 | 
| 
 | 
    67             <p>
 | 
| 
2
 | 
    68                 Type something and get its QR code (almost) immediately.
 | 
| 
0
 | 
    69             </p>
 | 
| 
 | 
    70 
 | 
| 
 | 
    71             <textarea class="inputbox js-qr-input" rows="4" autofocus></textarea>
 | 
| 
 | 
    72 
 | 
| 
1
 | 
    73             <div class="outputbox js-qr-output"></div>
 | 
| 
0
 | 
    74         </div>
 | 
| 
 | 
    75 
 | 
| 
 | 
    76         <div>
 | 
| 
 | 
    77             <hr>
 | 
| 
 | 
    78 
 | 
| 
 | 
    79             <a href="https://bitbucket.org/nanaya1/qr-html">Source</a>
 | 
| 
 | 
    80         </div>
 | 
| 
 | 
    81     </div>
 | 
| 
 | 
    82 
 | 
| 
 | 
    83     <script src="qrcode.min.js"></script>
 | 
| 
 | 
    84 
 | 
| 
 | 
    85     <script>
 | 
| 
9
 | 
    86         var inputDom = document.querySelector(".js-qr-input")
 | 
| 
 | 
    87         var outputDom = document.querySelector(".js-qr-output")
 | 
| 
8
 | 
    88         var qr = new QRCode(outputDom, { correctLevel: QRCode.CorrectLevel.L })
 | 
| 
0
 | 
    89 
 | 
| 
4
 | 
    90         var runTimeout = null
 | 
| 
 | 
    91         var debouncedRefreshCode = function() {
 | 
| 
 | 
    92             clearTimeout(runTimeout)
 | 
| 
 | 
    93             runTimeout = setTimeout(refreshCode, 100)
 | 
| 
 | 
    94         }
 | 
| 
 | 
    95 
 | 
| 
3
 | 
    96         var refreshCode = function() {
 | 
| 
 | 
    97             var text = inputDom.value
 | 
| 
0
 | 
    98 
 | 
| 
 | 
    99             if (text !== "") {
 | 
| 
2
 | 
   100                 qr.makeCode(text)
 | 
| 
 | 
   101                 outputDom.classList.remove('js-hidden')
 | 
| 
1
 | 
   102             } else {
 | 
| 
2
 | 
   103                 outputDom.classList.add('js-hidden')
 | 
| 
0
 | 
   104             }
 | 
| 
2
 | 
   105         }
 | 
| 
 | 
   106 
 | 
| 
4
 | 
   107         inputDom.addEventListener('input', debouncedRefreshCode)
 | 
| 
3
 | 
   108         refreshCode()
 | 
| 
0
 | 
   109     </script>
 | 
| 
 | 
   110 </body>
 |