annotate index.html @ 5:461c6e7dea56

Better mobile handling
author nanaya <me@myconan.net>
date Sun, 15 Jan 2017 19:31:54 +0900
parents cc0a5142a56f
children 896b7f28d3ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
1 <!doctype html>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
2 <head>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
3 <meta charset="utf-8">
5
461c6e7dea56 Better mobile handling
nanaya <me@myconan.net>
parents: 4
diff changeset
4 <meta name="viewport" content="width=device-width, initial-scale=1.0">
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
5 <title>QR Code Generator</title>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
6
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
7 <style type="text/css">
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
8 * {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
9 position: relative;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
10 box-sizing: border-box;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
11 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
12
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
13 html {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
14 height: 100%;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
15 margin: 0;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
16 padding: 0;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
17 font-family: sans-serif;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
18 font-size: 12px;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
19 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
20
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
21 body {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
22 margin: 0;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
23 padding: 10px;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
24 height: 100%;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
25 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
26
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
27 .inputbox {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
28 width: 100%;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
29 margin-bottom: 10px;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
30 resize: vertical;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
31 font-family: monospace;
5
461c6e7dea56 Better mobile handling
nanaya <me@myconan.net>
parents: 4
diff changeset
32 /* prevent ios zoom */
461c6e7dea56 Better mobile handling
nanaya <me@myconan.net>
parents: 4
diff changeset
33 font-size: 16px;
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
34 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
35
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
36 .page {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
37 width: 100%;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
38 height: 100%;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
39 max-width: 600px;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
40 margin: 0 auto;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
41 display: flex;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
42 flex-direction: column;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
43 padding: 10px;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
44 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
45
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
46 .page__main {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
47 flex: 1;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
48 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
49
1
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
50 .outputbox {
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
51 will-change: opacity;
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
52 }
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
53
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
54 .outputbox.js-hidden {
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
55 opacity: 0;
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
56 }
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
57
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
58 .title {
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
59 font-size: 16px;
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
60 }
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
61 </style>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
62 </head>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
63 <body>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
64 <div class="page">
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
65 <div class="page__main">
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
66 <h1>QR Code Generator</h1>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
67
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
68 <p>
2
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
69 Type something and get its QR code (almost) immediately.
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
70 </p>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
71
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
72 <textarea class="inputbox js-qr-input" rows="4" autofocus></textarea>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
73
1
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
74 <div class="outputbox js-qr-output"></div>
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
75 </div>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
76
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
77 <div>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
78 <hr>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
79
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
80 <a href="https://bitbucket.org/nanaya1/qr-html">Source</a>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
81 </div>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
82 </div>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
83
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
84 <script src="qrcode.min.js"></script>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
85
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
86 <script>
3
6875be47fb24 Now with less jquery
nanaya <me@myconan.net>
parents: 2
diff changeset
87 var inputDom = document.getElementsByClassName("js-qr-input")[0]
2
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
88 var outputDom = document.getElementsByClassName("js-qr-output")[0]
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
89 var qr = new QRCode(outputDom)
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
90
4
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
91 var runTimeout = null
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
92 var debouncedRefreshCode = function() {
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
93 clearTimeout(runTimeout)
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
94 runTimeout = setTimeout(refreshCode, 100)
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
95 }
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
96
3
6875be47fb24 Now with less jquery
nanaya <me@myconan.net>
parents: 2
diff changeset
97 var refreshCode = function() {
6875be47fb24 Now with less jquery
nanaya <me@myconan.net>
parents: 2
diff changeset
98 var text = inputDom.value
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
99
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
100 if (text !== "") {
2
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
101 qr.makeCode(text)
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
102 outputDom.classList.remove('js-hidden')
1
30cd1768611b Hide when box is empty
nanaya <me@myconan.net>
parents: 0
diff changeset
103 } else {
2
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
104 outputDom.classList.add('js-hidden')
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
105 }
2
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
106 }
f27dbbc6e978 Now with debounce
nanaya <me@myconan.net>
parents: 1
diff changeset
107
4
cc0a5142a56f Now without lodash
nanaya <me@myconan.net>
parents: 3
diff changeset
108 inputDom.addEventListener('input', debouncedRefreshCode)
3
6875be47fb24 Now with less jquery
nanaya <me@myconan.net>
parents: 2
diff changeset
109 refreshCode()
0
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
110 </script>
6b5cab0b3f91 Initial
nanaya <me@myconan.net>
parents:
diff changeset
111 </body>