From 5407cfcf172f0e5820e62fbd505cc8726dd553fd Mon Sep 17 00:00:00 2001
From: Christoph Oberhofer
Date: Thu, 30 Apr 2015 17:58:51 +0200
Subject: [PATCH] Improved static-images example
---
example/static_images.html | 32 +++++-----
example/static_images.js | 90 +++++++++++++++++++++------
test/fixtures/code_128/image-001.jpg | Bin 56988 -> 49506 bytes
test/fixtures/ean/image-001.jpg | Bin 693735 -> 70037 bytes
test/fixtures/ean/image-002.jpg | Bin 609094 -> 86373 bytes
test/fixtures/ean/image-003.jpg | Bin 694188 -> 64138 bytes
test/fixtures/ean/image-004.jpg | Bin 584107 -> 120805 bytes
test/fixtures/ean/image-005.jpg | Bin 792296 -> 113528 bytes
test/fixtures/ean/image-006.jpg | Bin 703108 -> 91234 bytes
test/fixtures/ean/image-007.jpg | Bin 755788 -> 128048 bytes
test/fixtures/ean/image-008.jpg | Bin 678100 -> 61445 bytes
test/fixtures/ean/image-009.jpg | Bin 679681 -> 86627 bytes
test/fixtures/ean/image-010.jpg | Bin 775456 -> 100796 bytes
13 files changed, 87 insertions(+), 35 deletions(-)
diff --git a/example/static_images.html b/example/static_images.html
index a61ef0c..dd0b174 100644
--- a/example/static_images.html
+++ b/example/static_images.html
@@ -29,23 +29,21 @@
Code128 and EAN encoded barcodes.
diff --git a/example/static_images.js b/example/static_images.js
index feb3de8..e7daa28 100644
--- a/example/static_images.js
+++ b/example/static_images.js
@@ -1,41 +1,95 @@
$(function() {
var App = {
init: function() {
- Quagga.init({
- inputStream: { name: "Test",
- type: "ImageStream",
- src: "../test/fixtures/" + App.config.reader + "/",
- length: App.config.length
- },
- decoder : {
- readers : [App.config.reader + "_reader"]
- }
- }, function() {
+ Quagga.init(this.state, function() {
App.attachListeners();
Quagga.start();
});
},
config: {
- reader: "upc_e",
+ reader: "code_128",
length: 10
},
attachListeners: function() {
+ var self = this;
+
$(".controls").on("click", "button.next", function(e) {
e.preventDefault();
Quagga.start();
});
-
- $(".controls .reader-group").on("change", "input", function(e) {
+
+ $(".controls .reader-config-group").on("change", "input, select", function(e) {
e.preventDefault();
- App.detachListeners();
- Quagga.stop();
- App.config.reader = e.target.value;
- App.init();
+ var $target = $(e.target),
+ value = $target.attr("type") === "checkbox" ? $target.prop("checked") : $target.val(),
+ name = $target.attr("name"),
+ states = self._convertNameToStates(name);
+
+ console.log("Value of "+ states + " changed to " + value);
+ self.setState(states, value);
});
},
detachListeners: function() {
$(".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"]
+ }
}
};
diff --git a/test/fixtures/code_128/image-001.jpg b/test/fixtures/code_128/image-001.jpg
index 8156afb5f8fbc76643a5436250aaab07dc2b7df7..2075809554cb375a519368ead48cae28a3703094 100644
GIT binary patch
literal 49506
zcmb5Ubx<7L6E?a83GVK0i@PVdyF0-bcPGIeg6l59-QAtVA$aiMPJ#u8kN0=Ks(b&v
zJySC^HB#NveY($i`g!~H_8WkyAR{jWfPsMl$h~iXw>5wy0QSR&|Mqu*d*9&^;o;%n
z;E_LmL_kDEMny$IMnOSC$HqiM$3jOz!NkYJ!okJE!$ZX&AjHQd#Ky(L{qG|%u|-
z_q)XJcKlENzjxtb;Sk
dTr|&i(_+(a
zTk=lxk}hYAMUmd??##A{okv1WIizCR#G)G4dMbg{db30o6lHw-rE}3tlIhynfInM8
zZvX;K+b5B-FDETJzRM_^4<@{~