You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
quaggaJS/example/file-input/index.html

124 lines
4.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>index</title>
<meta name="description" content="" />
<meta name="author" content="Christoph Oberhofer" />
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="../css/fonts.css" />
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<link rel="stylesheet" type="text/css" href="../css/prism.css" />
</head>
<body>
<header>
<div class="headline">
<h1>QuaggaJS</h1>
<h2>An advanced barcode-scanner written in JavaScript</h2>
</div>
</header>
<section id="container" class="container">
<h3>Scan barcode to input-field</h3>
<p>Click the <strong>button</strong> next to the input-field
to select a file or snap a picture</p>
<div>
<form>
<div class="input-field">
<label for="isbn_input">EAN:</label>
<input id="isbn_input" class="isbn" type="text" />
<button type="button" class="icon-barcode button scan">&nbsp;</button>
<input type="file" id="file" capture/>
</div>
</form>
</div>
<p>This example demonstrates the following features:
<ul>
<li>Use static image as source</li>
<li>Configuring EAN-Reader</li>
</ul>
</p>
<div class="source-code">
<h4>Source</h4>
<div class="collapsable-source">
<pre>
<code class="language-javascript">
var Quagga = window.Quagga;
var App = {
_scanner: null,
init: function() {
this.attachListeners();
},
decode: function(file) {
Quagga.fromImage({
constraints: {src: file, width: 800, height: 800},
decoder: {readers: ['ean_reader']},
})
.then(function(scanner) {
return scanner.detect();
})
.then(function(result) {
document.querySelector('input.isbn').value = result.codeResult.code;
})
.catch(function() {
document.querySelector('input.isbn').value = "Not Found";
})
.then(function() {
this.attachListeners();
}.bind(this));
},
attachListeners: function() {
var self = this,
button = document.querySelector('.input-field input + .button.scan'),
fileInput = document.querySelector('.input-field input[type=file]');
button.addEventListener("click", function onClick(e) {
e.preventDefault();
button.removeEventListener("click", onClick);
document.querySelector('.input-field input[type=file]').click();
});
fileInput.addEventListener("change", function onChange(e) {
e.preventDefault();
fileInput.removeEventListener("change", onChange);
if (e.target.files && e.target.files.length) {
self.decode(e.target.files[0]);
}
});
}
};
App.init();
</code>
</pre>
</div>
<div class="collapsable-source">
<pre>
<code class="language-html">
&lt;form&gt;
&lt;div class=&quot;input-field&quot;&gt;
&lt;label for=&quot;isbn_input&quot;&gt;EAN:&lt;/label&gt;
&lt;input id=&quot;isbn_input&quot; class=&quot;isbn&quot; type=&quot;text&quot; /&gt;
&lt;button type=&quot;button&quot; class=&quot;icon-barcode button scan&quot;&gt;&amp;nbsp;&lt;/button&gt;
&lt;input type=&quot;file&quot; id=&quot;file&quot; capture/&gt;
&lt;/div&gt;
&lt;/form&gt;
</code>
</pre>
</div>
</div>
</section>
<footer>
<p>
&copy; Copyright by Christoph Oberhofer
</p>
</footer>
<script src="../../dist/quagga.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<script src="../vendor/prism.js"></script>
</body>
</html>