1212< body >
1313 < div style ="width:80vw;margin:0 auto; ">
1414 < h1 style ="font-size: 1.5em; "> Read Barcode from Images</ h1 >
15- < input id ="ipt-file " type ="file " accept ="image/png,image/jpeg,image/bmp,image/gif ">
15+ < input id ="ipt-file " type ="file " accept ="image/png,image/jpeg,image/bmp,image/gif " disabled =" disabled " >
1616 < input id ="ipt-readonly-last-result " title ="Double click to clear! " readonly placeholder ="The Last Read Barcode " style ="width:80vw;margin-top:20px; ">
17- < p id ='p-loading ' style ='font-size:1.5em '> Loading Library ...</ p >
17+ < p id ='p-loading ' style ='font-size:1.5em '> Loading...</ p >
1818 < p id ='p-reading ' style ='font-size:1.5em;display:none; '> Reading Barcodes...</ p >
1919 < div id ="div-cvs-container " style ="width:80vw;height:40vh;margin-top:20px;display:flex;justify-content:center; "> </ div >
2020 < p > All Results:</ p >
2121 < div id ="div-results " style ="width:80vw;height:15vh;padding:16px;overflow-y:auto;border: 1px dashed grey; "> </ div >
2222 </ div >
2323 < style >
24- .sp-resultText { color : # cE5E04 }
25- # div-cvs-container canvas { border : solid 1px gray; }
24+ .sp-resultText {
25+ color : # cE5E04
26+ }
27+
28+ # div-cvs-container canvas {
29+ border : solid 1px gray;
30+ }
2631 </ style >
2732 < script src ="https://cdn.jsdelivr.net/npm/dynamsoft-javascript-barcode@9.0.0/dist/dbr.js "> </ script >
2833 < script >
@@ -43,24 +48,25 @@ <h1 style="font-size: 1.5em;">Read Barcode from Images</h1>
4348 ( async ( ) => {
4449 try {
4550 await Dynamsoft . DBR . BarcodeReader . loadWasm ( ) ;
46- document . getElementById ( 'p-loading' ) . style . display = 'none' ;
51+ document . getElementById ( 'p-loading' ) . innerText = "Library loaded and ready!"
52+ document . getElementById ( 'ipt-file' ) . disabled = false ;
53+ setTimeout ( function ( ) {
54+ document . getElementById ( 'p-loading' ) . style . display = 'none' ;
55+ } , 1000 ) ;
4756 } catch ( ex ) {
48- alert ( ex . message ) ;
57+ document . getElementById ( 'p-loading' ) . innerText = ex ;
58+ document . getElementById ( 'ipt-file' ) . disabled = true ;
4959 throw ex ;
5060 }
5161 } ) ( ) ;
5262
53-
54-
55-
5663 // html elements
5764 const iptFile = document . getElementById ( 'ipt-file' ) ;
5865 const iptReadonlyLastResult = document . getElementById ( 'ipt-readonly-last-result' ) ;
5966 const pReading = document . getElementById ( 'p-reading' ) ;
6067 const divResults = document . getElementById ( 'div-results' ) ;
6168 const divCvsContainer = document . getElementById ( 'div-cvs-container' ) ;
6269
63-
6470 // reader for decoding pictures
6571 let pReader = null ;
6672 iptFile . addEventListener ( 'change' , async function ( ) {
@@ -74,7 +80,7 @@ <h1 style="font-size: 1.5em;">Read Barcode from Images</h1>
7480 // show image
7581 divCvsContainer . innerHTML = '' ;
7682 divCvsContainer . appendChild ( reader . getOriginalImageInACanvas ( ) ) ;
77-
83+
7884 // show results
7985 divResults . appendChild ( createEl ( 'h3' , file . name + ": " ) ) ;
8086 if ( 0 === results . length ) {
@@ -94,7 +100,6 @@ <h1 style="font-size: 1.5em;">Read Barcode from Images</h1>
94100 divResults . appendChild ( document . createElement ( 'hr' ) ) ;
95101 divResults . scrollTop = divResults . scrollHeight ;
96102 } catch ( ex ) {
97- alert ( ex . message ) ;
98103 throw ex ;
99104 } finally {
100105 pReading . style . display = 'none' ;
@@ -109,7 +114,7 @@ <h1 style="font-size: 1.5em;">Read Barcode from Images</h1>
109114 function createEl ( type , txt , className ) {
110115 const el = document . createElement ( type ) ;
111116 el . textContent = txt ;
112- if ( className ) {
117+ if ( className ) {
113118 el . className = className ;
114119 }
115120 return el ;
0 commit comments