added example for multiple readers; reordered urls
parent
a18fbcd501
commit
aca7f015f0
@ -0,0 +1,16 @@
|
||||
---
|
||||
layout: default
|
||||
---
|
||||
|
||||
<h1>Examples</h1>
|
||||
|
||||
<ul>
|
||||
<li><a href="../scan-to-input/">Video-based Example</a> showcasing an input field for barcodes</li>
|
||||
<li><a href="../file-input/">File-based Example</a> showcasing an input field for barcodes</li>
|
||||
<li><a href="../multiple/">Video-based Example</a> showcasing the use of multiple readers</li>
|
||||
<li><a href="../static_images/">Demo with sample images</a></li>
|
||||
<li><a href="../live_w_locator/">Demo with live-stream</a> using <code>getUserMedia</code></li>
|
||||
<li><a href="../file_input/">Demo with file-input</a> showcasing a use for mobile</li>
|
||||
</ul>
|
||||
|
||||
{{ content }}
|
@ -0,0 +1,58 @@
|
||||
---
|
||||
layout: v1.0.0-beta.1/examples
|
||||
title: Demo with live-stream
|
||||
showInMenu: false
|
||||
---
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="./styles.css" />
|
||||
<section id="container" class="container">
|
||||
<h3>Scan various barcodes continously</h3>
|
||||
<p>
|
||||
Be aware that not all combinations play together nicely. Some
|
||||
codes do not have a checksum (e.g. ITF).
|
||||
</p>
|
||||
<div class="controls">
|
||||
<button type="button" class="icon-barcode button scan">Start Scanning</button>
|
||||
<div class="readers">
|
||||
<label>
|
||||
<span>EAN-13</span>
|
||||
<input type="checkbox" checked name="ean_reader" />
|
||||
</label>
|
||||
<label>
|
||||
<span>EAN-8</span>
|
||||
<input type="checkbox" name="ean_8_reader" />
|
||||
</label>
|
||||
<label>
|
||||
<span>UPC-E</span>
|
||||
<input type="checkbox" name="upc_e_reader" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Code 39</span>
|
||||
<input type="checkbox" checked name="code_39_reader" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Codabar</span>
|
||||
<input type="checkbox" name="codabar_reader" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Code 128</span>
|
||||
<input type="checkbox" checked name="code_128_reader" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Interleaved 2 of 5</span>
|
||||
<input type="checkbox" name="i2of5_reader" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overlay overlay--inline">
|
||||
<div class="overlay__content">
|
||||
<div class="overlay__close">X</div>
|
||||
<ul class="results"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<ul class="results"></ul>
|
||||
|
||||
<script src="../js/quagga.js" type="text/javascript"></script>
|
||||
<script src="index.js" type="text/javascript"></script>
|
||||
<script src="../js/prism.js"></script>
|
@ -0,0 +1,100 @@
|
||||
var Quagga = window.Quagga;
|
||||
var App = {
|
||||
_lastResult: null,
|
||||
init: function() {
|
||||
this.attachListeners();
|
||||
},
|
||||
activateScanner: function() {
|
||||
var scanner = this.configureScanner('.overlay__content'),
|
||||
onDetected = function (result) {
|
||||
this.addToResults(result);
|
||||
}.bind(this),
|
||||
stop = function() {
|
||||
scanner.stop(); // should also clear all event-listeners?
|
||||
scanner.removeEventListener('detected', onDetected);
|
||||
this.hideOverlay();
|
||||
this.attachListeners();
|
||||
}.bind(this);
|
||||
|
||||
this.showOverlay(stop);
|
||||
console.log("activateScanner");
|
||||
scanner.addEventListener('detected', onDetected).start();
|
||||
},
|
||||
addToResults: function(result) {
|
||||
if (this._lastResult === result.codeResult.code) {
|
||||
return;
|
||||
}
|
||||
this._lastResult = result.codeResult.code;
|
||||
var resultSets = document.querySelectorAll('ul.results');
|
||||
|
||||
Array.prototype.slice.call(resultSets).forEach(function(resultSet) {
|
||||
var li = document.createElement('li'),
|
||||
format = document.createElement('span'),
|
||||
code = document.createElement('span');
|
||||
|
||||
console.log(result);
|
||||
li.className = "result";
|
||||
format.className = "format";
|
||||
code.className = "code";
|
||||
|
||||
li.appendChild(format);
|
||||
li.appendChild(code);
|
||||
|
||||
format.appendChild(document.createTextNode(result.codeResult.format));
|
||||
code.appendChild(document.createTextNode(result.codeResult.code));
|
||||
|
||||
resultSet.insertBefore(li, resultSet.firstChild);
|
||||
});
|
||||
},
|
||||
attachListeners: function() {
|
||||
var button = document.querySelector('button.scan'),
|
||||
self = this;
|
||||
|
||||
button.addEventListener("click", function clickListener (e) {
|
||||
e.preventDefault();
|
||||
button.removeEventListener("click", clickListener);
|
||||
self.activateScanner();
|
||||
});
|
||||
},
|
||||
showOverlay: function(cancelCb) {
|
||||
document.querySelector('.container .controls')
|
||||
.classList.add('hide');
|
||||
document.querySelector('.overlay--inline')
|
||||
.classList.add('show');
|
||||
var closeButton = document.querySelector('.overlay__close');
|
||||
closeButton.addEventListener('click', function closeHandler() {
|
||||
closeButton.removeEventListener("click", closeHandler);
|
||||
cancelCb();
|
||||
});
|
||||
},
|
||||
hideOverlay: function() {
|
||||
document.querySelector('.container .controls')
|
||||
.classList.remove('hide');
|
||||
document.querySelector('.overlay--inline')
|
||||
.classList.remove('show');
|
||||
},
|
||||
querySelectedReaders: function() {
|
||||
return Array.prototype.slice.call(document.querySelectorAll('.readers input[type=checkbox]'))
|
||||
.filter(function(element) {
|
||||
return !!element.checked;
|
||||
})
|
||||
.map(function(element) {
|
||||
return element.getAttribute("name");
|
||||
});
|
||||
},
|
||||
configureScanner: function(selector) {
|
||||
var scanner = Quagga
|
||||
.decoder({readers: this.querySelectedReaders()})
|
||||
.locator({patchSize: 'medium'})
|
||||
.fromSource({
|
||||
target: selector,
|
||||
constraints: {
|
||||
width: 600,
|
||||
height: 600,
|
||||
facingMode: "environment"
|
||||
}
|
||||
});
|
||||
return scanner;
|
||||
}
|
||||
};
|
||||
App.init();
|
@ -0,0 +1,121 @@
|
||||
/* Scan! Button */
|
||||
|
||||
.icon-barcode.scan {
|
||||
font-size: large;
|
||||
padding: 0.5em 0.5em 0.5em 4em;
|
||||
text-align: center;
|
||||
display: block;
|
||||
background-position: 0.5em center;
|
||||
}
|
||||
|
||||
.icon-barcode.scan:before {
|
||||
margin-right: 0.5em;
|
||||
}
|
||||
|
||||
/* Reader Checkboxes */
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.controls .readers {
|
||||
font-size: 1.3em;
|
||||
margin-left: 1em;
|
||||
}
|
||||
|
||||
.controls .readers label {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.controls .readers input {
|
||||
flex: 0 0 auto;
|
||||
height: 1.5rem;
|
||||
width: 1.5rem;
|
||||
}
|
||||
|
||||
.controls .readers span {
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
/* Results */
|
||||
|
||||
.overlay .results {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
background-color: white;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
.results {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
background-color: #DDD;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style-type: none;
|
||||
padding: 0.25rem;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
border-top: 1px solid #777;
|
||||
}
|
||||
|
||||
.results > li {
|
||||
flex: 0 1 auto;
|
||||
margin: 0.25rem;
|
||||
background: #fff;
|
||||
border-radius: 2px;
|
||||
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
|
||||
}
|
||||
|
||||
.results:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.result {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.result > .format {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.result > .code {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Scanner */
|
||||
|
||||
.container .controls.hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.overlay--inline {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.overlay--inline.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media (max-width: 603px) {
|
||||
.controls {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.controls .readers {
|
||||
margin-left: 0;
|
||||
margin-top: 1em;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue