Skip to content

Commit 935347e

Browse files
committed
user frinedly and readme updates
1 parent 678f36c commit 935347e

17 files changed

+563
-189
lines changed

1.hello-world/2.read-an-image.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,13 @@ <h1 style="font-size: 1.5em;">Read Barcode from Images</h1>
5050
}
5151
})();
5252

53-
54-
55-
5653
// html elements
5754
const iptFile = document.getElementById('ipt-file');
5855
const iptReadonlyLastResult = document.getElementById('ipt-readonly-last-result');
5956
const pReading = document.getElementById('p-reading');
6057
const divResults = document.getElementById('div-results');
6158
const divCvsContainer = document.getElementById('div-cvs-container');
6259

63-
6460
// reader for decoding pictures
6561
let pReader = null;
6662
iptFile.addEventListener('change', async function() {

1.hello-world/4.read-video-react/src/components/HelloWorld/HelloWorld.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ span {
4343

4444
.latest-result:focus {
4545
outline: none;
46-
box-shadow: 0.1rem 0.4rem 0.8rem #5e35b1;
46+
box-shadow: 0.1rem 0.4rem 0.8rem #fe8e14;
4747
}
4848

4949
#results {

1.hello-world/5.read-video-vue/src/components/HelloWorld.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ span {
109109
110110
.latest-result:focus {
111111
outline: none;
112-
box-shadow: 0.1rem 0.4rem 0.8rem #5e35b1;
112+
box-shadow: 0.1rem 0.4rem 0.8rem #fe8e14;
113113
}
114114
115115
#results {

1.hello-world/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# The Hello World Sample Set
2+
3+
As you have gone through the [user guide](https://www.dynamsoft.com/barcode-reader/programming/javascript/user-guide/?ver=latest#getting-started---hello-world), you might have seen some basic "Hello World" code to help you quickly create a basic web application that uses our SDK.
4+
5+
This sample set will revisit the Hello World code, and its implementation in some of the popular frameworks such as Angular, React, an Vue.
6+
7+
Let's break down each of the samples
8+
9+
## Hello World - Read Barcodes via Video
10+
11+
In this sample, you will find the basic lines of code ncessary to initialize the SDK and set it up.
12+
13+
Let's quickly break down the methods used in order:
14+
15+
* `license`: This property specifies a license key. Read more on Specify the license.
16+
* `createInstance()`: This method creates a `BarcodeScanner` object. This object can read barcodes directly from a video input with the help of its interactive UI (hidden by default) and the MediaDevices interface.
17+
* `onFrameRead`: This event is triggered every time the SDK finishes scanning a video frame. The results object contains all the barcode results that the SDK have found on this frame. In this example, we print the results to the browser console.
18+
* `onUniqueRead`: This event is triggered when the SDK finds a new barcode, which is not a duplicate among multiple frames. txt holds the barcode text value while result is an object that holds details of the barcode. In this example, an alert will be displayed for this new barcode.
19+
* `show()`: This method brings up the built-in UI of the `BarcodeScanner` object and starts scanning
20+
21+
In fact, `onFrameRead` and `onUniqueRead` do not have to both be defined in the code. `onUniqueRead` is the more used one between the two as it is triggered when a new barcode is found rather than on every frame.
22+
23+
## Hello World - Read Barcodes from an Image
24+
25+
The second sample in this set focuses on the secondary class `BarcodeReader` which is a low-level barcode reader that processes still images and returns barcode results.
26+
27+
In this sample, a listener is set up so that the SDK decodes any image that the user uploads.
28+
29+
[`decode`](https://www.dynamsoft.com/barcode-reader/programming/javascript/api-reference/BarcodeReader.html?ver=latest#decode) is the main method to go for when using the `BarcodeReader` class, although the class offers a number of other methods should you work with base64 strings, for instance. The rest of the image decoding methods can be found [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/api-reference/BarcodeReader.html?ver=latest#decode-barcodes).
30+
31+
## Hello World - Angular
32+
33+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-angular.html).
34+
35+
## Hello World in React
36+
37+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-reactjs.html).
38+
39+
## Hello World in Vue 2
40+
41+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-vuejs.html).
42+
43+
## Hello World in Vue 3
44+
45+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-vuejsv3.html).
46+
47+
## Hello World in Next.js
48+
49+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-nextjs.html).
50+
51+
## Hello World in NuxtJS
52+
53+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-nuxtjs.html).
54+
55+
## Hello World in Electron
56+
57+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-electron.html).
58+
59+
## Hello World in PWA
60+
61+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-pwa.html).
62+
63+
## Hello World with RequireJS
64+
65+
Read more on the sample [here](https://www.dynamsoft.com/barcode-reader/programming/javascript/samples-demos/helloworld-requirejs.html).
66+
67+
## Hello World with ES6
68+
69+
This sample shows how to use the SDK in a web page based on ES6 (also known as ECMAScript 2015 or ECMAScript 6).
70+
71+
## Support
72+
73+
If you have any questions, feel free to contact Dynamsoft support via [email](mailto:support@dynamsoft.com) or [live chat](https://www.dynamsoft.com/barcode-reader/overview/) via the "Let's Chat" button.

2.ui-tweaking/1.read-video-show-result.html

Lines changed: 115 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
</head>
1111

1212
<body>
13-
<h1>Use the Default Built-in UI</h1>
13+
<h1 style="font-size: 1.5em;">Use the Default Built-in UI</h1>
14+
<input type="text" id="result" title="Double click to clear!" readonly="true" class="latest-result" placeholder="The Last Read Barcode">
1415
<div id="UIElement" class="UIElement">
15-
<button id="showScanner" class="showScanner">Show The Scanner</button>
16+
<span id='lib-load' style='font-size:x-large' hidden>Loading Library...</span><br />
17+
<button id="showScanner" hidden>Show The Scanner</button>
18+
</div>
19+
<div>
20+
<span style="float:left;margin-top:20px;">All Results:</span><br />
21+
<div id="results"></div>
1622
</div>
1723
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.0.0/dist/dbr.js"></script>
1824
<script>
@@ -31,77 +37,151 @@ <h1>Use the Default Built-in UI</h1>
3137

3238
// scanner for decoding video
3339
let pScanner = null;
34-
(async () => {
40+
(async() => {
3541
//Load the library on page load to speed things up.
3642
try {
43+
document.getElementById('lib-load').hidden = false;
3744
await Dynamsoft.DBR.BarcodeReader.loadWasm();
45+
startBarcodeScanner();
3846
} catch (ex) {
3947
alert(ex.message);
4048
throw ex;
4149
}
50+
document.getElementById('result').addEventListener('dblclick', async() => {
51+
document.getElementById('result').value = "";
52+
});
53+
document.getElementById('showScanner').addEventListener('click', async() => {
54+
if (pScanner)(await pScanner).show();
55+
});
4256
})();
43-
document.getElementById('showScanner').addEventListener('click', async () => {
57+
// decode video from camera
58+
async function startBarcodeScanner() {
4459
try {
4560
let scanner = await (pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance());
46-
scanner.onUniqueRead = (txt, result) => { alert(txt); };
61+
document.getElementById('showScanner').hidden = false;
62+
scanner.onFrameRead = (_results) => {
63+
for (let result of _results) {
64+
let newElements = [];
65+
newElements.push(createASpan(result.barcodeFormatString + ": "));
66+
newElements.push(createASpan(result.barcodeText, "resultText"));
67+
newElements.push(document.createElement('br'));
68+
if (result.barcodeText.indexOf("Attention(exceptionCode") != -1) {
69+
newElements.push(createASpan(" Error: " + result.exception.message));
70+
newElements.push(document.createElement('br'));
71+
}
72+
for (let span of newElements) {
73+
document.getElementById('results').appendChild(span);
74+
}
75+
document.getElementById('results').scrollTop = document.getElementById('results').scrollHeight;
76+
}
77+
};
78+
scanner.onUniqueRead = (txt, result) => {
79+
document.getElementById('result').value = result.barcodeFormatString + ": " + txt;
80+
document.getElementById('result').focus();
81+
setTimeout(() => {
82+
document.getElementById('result').blur();
83+
}, 2000);
84+
};
4785
document.getElementById('UIElement').appendChild(scanner.getUIElement());
4886
await scanner.show();
49-
} catch (ex) {
50-
alert(ex.message);
51-
setSingleFrameMode();
52-
throw ex;
53-
}
54-
});
55-
async function setSingleFrameMode() {
56-
try {
57-
let scanner = await(pScanner = pScanner || Dynamsoft.DBR.BarcodeScanner.createInstance());
58-
scanner.singleFrameMode = true;
59-
await scanner.show();
87+
document.getElementById('lib-load').hidden = true;
88+
document.getElementById('results').style.visibility = "visible";
6089
} catch (ex) {
6190
alert(ex.message);
6291
throw ex;
6392
}
6493
}
94+
95+
function createASpan(txt, className) {
96+
let newSPAN = document.createElement("span");
97+
newSPAN.textContent = txt;
98+
if (className)
99+
newSPAN.className = className;
100+
return newSPAN;
101+
}
65102
</script>
66103
</body>
67104
<style>
68-
* {
69-
margin: 0;
70-
padding: 0;
105+
button#showScanner {
106+
position: absolute;
107+
width: 50%;
108+
left: 25%;
109+
top: 30%;
71110
}
72-
111+
73112
body {
74113
display: flex;
75114
flex-direction: column;
76115
align-items: center;
77116
justify-content: center;
78117
overflow: hidden;
79118
width: 100vw;
80-
height: 100vh;
119+
height: 90vh;
81120
color: #455A64;
121+
margin: 0;
82122
}
83-
84-
h1 {
85-
font-size: 1.5em;
86-
}
87-
123+
88124
button {
89-
margin-bottom: 2vh;
90125
font-size: 1.5rem;
126+
margin-bottom: 2vh;
91127
}
92-
93-
.UIElement {
94-
height: 60vh;
128+
129+
span {
130+
font-size: 0.8rem;
131+
}
132+
133+
.latest-result {
134+
display: block;
135+
margin: 0;
136+
padding: 0.4rem 0.8rem;
137+
color: inherit;
138+
min-width: 40vw;
139+
width: auto;
140+
border: none;
141+
font-size: 1rem;
142+
border-radius: 0.2rem;
143+
text-align: center;
144+
}
145+
146+
.latest-result::placeholder {
147+
color: #B0BEC5;
148+
}
149+
150+
.latest-result:focus {
151+
outline: none;
152+
box-shadow: 0.1rem 0.4rem 0.8rem #fe8e14;
153+
}
154+
155+
#results {
156+
border: 1px dashed grey;
157+
overflow: auto;
95158
width: 80vw;
159+
padding: 2vmin;
160+
margin-bottom: 3vh;
161+
height: 15vh;
162+
}
163+
164+
.resultText {
165+
color: #cE5E04
166+
}
167+
168+
.bigger {
169+
font-size: large;
170+
margin-bottom: 2%;
171+
}
172+
173+
#UIElement {
96174
margin: 2vmin auto;
97175
text-align: center;
98176
font-size: medium;
177+
height: 40vh;
178+
width: 80vw;
99179
}
100-
101-
.showScanner {
102-
position: absolute;
103-
width: 50%;
104-
left: 25%;
180+
181+
#UIElement img {
182+
max-width: 100%;
183+
max-height: 90%;
184+
border: solid 1px gray;
105185
}
106186
</style>
107187

0 commit comments

Comments
 (0)