view index.html @ 8:e50d930b2af1

Use lowest error correction level
author nanaya <me@nanaya.pro>
date Fri, 06 Jul 2018 16:28:26 +0900
parents 896b7f28d3ad
children 5998f1f51877
line wrap: on
line source

<!doctype html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QR Code Generator</title>

    <style type="text/css">
        * {
            box-sizing: border-box;
        }

        html {
            height: 100%;
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            font-size: 12px;
        }

        body {
            margin: 0;
            padding: 10px;
            height: 100%;
        }

        .inputbox {
            width: 100%;
            margin-bottom: 10px;
            resize: vertical;
            font-family: Courier New, monospace;
            /* prevent ios zoom */
            font-size: 16px;
        }

        .page {
            width: 100%;
            min-height: 100%;
            max-width: 600px;
            margin: 0 auto;
            display: flex;
            flex-direction: column;
            padding: 10px;
        }

        .page__main {
            flex: 1;
        }

        .outputbox {
            will-change: opacity;
        }

        .outputbox.js-hidden {
            opacity: 0;
        }

        .title {
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="page">
        <div class="page__main">
            <h1>QR Code Generator</h1>

            <p>
                Type something and get its QR code (almost) immediately.
            </p>

            <textarea class="inputbox js-qr-input" rows="4" autofocus></textarea>

            <div class="outputbox js-qr-output"></div>
        </div>

        <div>
            <hr>

            <a href="https://bitbucket.org/nanaya1/qr-html">Source</a>
        </div>
    </div>

    <script src="qrcode.min.js"></script>

    <script>
        var inputDom = document.getElementsByClassName("js-qr-input")[0]
        var outputDom = document.getElementsByClassName("js-qr-output")[0]
        var qr = new QRCode(outputDom, { correctLevel: QRCode.CorrectLevel.L })

        var runTimeout = null
        var debouncedRefreshCode = function() {
            clearTimeout(runTimeout)
            runTimeout = setTimeout(refreshCode, 100)
        }

        var refreshCode = function() {
            var text = inputDom.value

            if (text !== "") {
                qr.makeCode(text)
                outputDom.classList.remove('js-hidden')
            } else {
                outputDom.classList.add('js-hidden')
            }
        }

        inputDom.addEventListener('input', debouncedRefreshCode)
        refreshCode()
    </script>
</body>