-
Notifications
You must be signed in to change notification settings - Fork 63
/
index.html
71 lines (61 loc) · 1.9 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
<!DOCTYPE html>
<html>
<head>
<title>QR Test</title>
<style>
#preview img {
border: 1px solid black;
float: left;
margin: 0 1em 1em 0;
width: 10em;
}
</style>
</head>
<body>
<h1>Simple browser demo using the FileReader API</h1>
<h2>Upload file</h2>
<input type="file" id="upload">
<h2>Result</h2>
<div id="preview"></div>
<script type="text/javascript" src="../../dist/index.js"></script>
<script type="text/javascript">
(function() {
'use strict';
var upload = document.getElementById('upload');
var preview = document.getElementById('preview');
var qr = new QrCode();
qr.callback = function(err, result) {
var span = document.querySelector('span') || document.createElement('span');
if(result){
span.textContent = result;
}
else{
span.textContent = 'Error! See error message in console!';
console.error(err);
}
preview.appendChild(span);
}
upload.addEventListener('change', function() {
for (var i = 0; i < this.files.length; i++) {
var file = this.files[i];
var imageType = /^image\//;
if (!imageType.test(file.type)) {
throw new Error('File type not valid');
}
// Read file
var reader = new FileReader();
reader.addEventListener('load', function() {
// Show as preview image
var img = document.querySelector('img') || document.createElement('img');
img.src = this.result;
preview.appendChild(img);
// Analyse code
qr.decode(this.result);
}.bind(reader), false);
reader.readAsDataURL(file);
}
}, false);
})();
</script>
</body>
</html>