Improved static-images example
@@ -29,22 +29,20 @@
|
|||||||
<strong>Code128</strong> and <strong>EAN</strong> encoded barcodes.
|
<strong>Code128</strong> and <strong>EAN</strong> encoded barcodes.
|
||||||
</p>
|
</p>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
<fieldset class="input-group">
|
||||||
<button class="next">Next</button>
|
<button class="next">Next</button>
|
||||||
<fieldset class="reader-group">
|
</fieldset>
|
||||||
<label>UPC-E</label>
|
<fieldset class="reader-config-group">
|
||||||
<input type="radio" name="reader" checked="checked" value="upc_e" />
|
<span>Barcode-Type</span>
|
||||||
<label>EAN-8</label>
|
<select name="decoder_readers;input-stream_src">
|
||||||
<input type="radio" name="reader" value="ean_8" />
|
<option value="code_128" selected="selected">Code 128</option>
|
||||||
<label>UPC</label>
|
<option value="code_39">Code 39</option>
|
||||||
<input type="radio" name="reader" value="upc" />
|
<option value="ean">EAN</option>
|
||||||
<label>Codabar</label>
|
<option value="ean_8">EAN-8</option>
|
||||||
<input type="radio" name="reader" value="codabar" />
|
<option value="upc">UPC</option>
|
||||||
<label>Code39</label>
|
<option value="upc_e">UPC-E</option>
|
||||||
<input type="radio" name="reader" value="code_39" />
|
<option value="codabar">Codabar</option>
|
||||||
<label>Code128</label>
|
</select>
|
||||||
<input type="radio" name="reader" value="code_128" />
|
|
||||||
<label>EAN</label>
|
|
||||||
<input type="radio" name="reader" value="ean" />
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div id="result_strip">
|
<div id="result_strip">
|
||||||
|
|||||||
@@ -1,41 +1,95 @@
|
|||||||
$(function() {
|
$(function() {
|
||||||
var App = {
|
var App = {
|
||||||
init: function() {
|
init: function() {
|
||||||
Quagga.init({
|
Quagga.init(this.state, function() {
|
||||||
inputStream: { name: "Test",
|
|
||||||
type: "ImageStream",
|
|
||||||
src: "../test/fixtures/" + App.config.reader + "/",
|
|
||||||
length: App.config.length
|
|
||||||
},
|
|
||||||
decoder : {
|
|
||||||
readers : [App.config.reader + "_reader"]
|
|
||||||
}
|
|
||||||
}, function() {
|
|
||||||
App.attachListeners();
|
App.attachListeners();
|
||||||
Quagga.start();
|
Quagga.start();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
reader: "upc_e",
|
reader: "code_128",
|
||||||
length: 10
|
length: 10
|
||||||
},
|
},
|
||||||
attachListeners: function() {
|
attachListeners: function() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
$(".controls").on("click", "button.next", function(e) {
|
$(".controls").on("click", "button.next", function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
Quagga.start();
|
Quagga.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".controls .reader-group").on("change", "input", function(e) {
|
$(".controls .reader-config-group").on("change", "input, select", function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
App.detachListeners();
|
var $target = $(e.target),
|
||||||
Quagga.stop();
|
value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
|
||||||
App.config.reader = e.target.value;
|
name = $target.attr("name"),
|
||||||
App.init();
|
states = self._convertNameToStates(name);
|
||||||
|
|
||||||
|
console.log("Value of "+ states + " changed to " + value);
|
||||||
|
self.setState(states, value);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
detachListeners: function() {
|
detachListeners: function() {
|
||||||
$(".controls").off("click", "button.next");
|
$(".controls").off("click", "button.next");
|
||||||
$(".controls .reader-group").off("change", "input");
|
$(".controls .reader-config-group").off("change", "input, select");
|
||||||
|
},
|
||||||
|
_accessByPath: function(obj, path, val) {
|
||||||
|
var parts = path.split('.'),
|
||||||
|
depth = parts.length,
|
||||||
|
setter = (typeof val !== "undefined") ? true : false;
|
||||||
|
|
||||||
|
return parts.reduce(function(o, key, i) {
|
||||||
|
if (setter && (i + 1) === depth) {
|
||||||
|
o[key] = val;
|
||||||
|
}
|
||||||
|
return key in o ? o[key] : {};
|
||||||
|
}, obj);
|
||||||
|
},
|
||||||
|
_convertNameToStates: function(names) {
|
||||||
|
return names.split(";").map(this._convertNameToState.bind(this));
|
||||||
|
},
|
||||||
|
_convertNameToState: function(name) {
|
||||||
|
return name.replace("_", ".").split("-").reduce(function(result, value) {
|
||||||
|
return result + value.charAt(0).toUpperCase() + value.substring(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
setState: function(paths, value) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
paths.forEach(function(path) {
|
||||||
|
var mappedValue;
|
||||||
|
if (typeof self._accessByPath(self.inputMapper, path) === "function") {
|
||||||
|
mappedValue = self._accessByPath(self.inputMapper, path)(value);
|
||||||
|
}
|
||||||
|
self._accessByPath(self.state, path, mappedValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(JSON.stringify(self.state));
|
||||||
|
App.detachListeners();
|
||||||
|
Quagga.stop();
|
||||||
|
App.init();
|
||||||
|
},
|
||||||
|
inputMapper: {
|
||||||
|
decoder: {
|
||||||
|
readers: function(value) {
|
||||||
|
return [value + "_reader"];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
inputStream: {
|
||||||
|
src: function(value) {
|
||||||
|
return "../test/fixtures/" + value + "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
state: {
|
||||||
|
inputStream: { name: "Test",
|
||||||
|
type: "ImageStream",
|
||||||
|
src: "../test/fixtures/code_128/",
|
||||||
|
length: 10
|
||||||
|
},
|
||||||
|
decoder : {
|
||||||
|
readers : ["code_128_reader"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 678 KiB After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 595 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 678 KiB After Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 570 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 774 KiB After Width: | Height: | Size: 111 KiB |
|
Before Width: | Height: | Size: 687 KiB After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 738 KiB After Width: | Height: | Size: 125 KiB |
|
Before Width: | Height: | Size: 662 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 664 KiB After Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 757 KiB After Width: | Height: | Size: 98 KiB |