@@ -53,26 +53,29 @@ $('#cep-in').on('input', () => {
53
53
type : 'GET' ,
54
54
success : cepData => {
55
55
if ( ! cepData . erro ) {
56
- console . log ( cepData ) ;
57
- // arranging the result area for the CEP data
58
- $ ( '.catch-data' ) . addClass ( 'catch-data-active' ) ;
59
- $ ( '.user-input' ) . addClass ( 'user-input-active' ) ;
56
+ console . table ( cepData ) ;
60
57
61
- // inserting cep data on html
62
- for ( let data in cepData ) {
63
- if ( cepData [ data ] && data !== 'logradouro' && data !== 'complemento' && data !== 'gia' ) {
64
- const cepDataParagraph = document . createElement ( 'p' ) ;
65
- cepDataParagraph . innerHTML = `<strong>${ data . toUpperCase ( ) } </strong>: ${ cepData [ data ] } ` ;
66
- $ ( '.viaCEP-api-data' ) . append ( cepDataParagraph ) ;
58
+ // inserting cep data on html (IIFE function)
59
+ ( insertCepData = cepData => {
60
+ for ( let data in cepData ) {
61
+ if ( cepData [ data ] && data !== 'logradouro' && data !== 'complemento' && data !== 'gia' ) {
62
+ const cepDataParagraph = document . createElement ( 'p' ) ;
63
+ cepDataParagraph . innerHTML = `<strong>${ data . toUpperCase ( ) } </strong>: ${ cepData [ data ] } ` ;
64
+ $ ( '.viaCEP-api-data' ) . append ( cepDataParagraph ) ;
65
+ }
67
66
}
68
- }
67
+ } ) ( cepData ) ;
69
68
70
- // inserting map iframe based on CEP data on html
71
- const mapData = document . createElement ( 'iframe' ) ;
72
- $ ( mapData ) . attr ( { id : 'map-iframe' , src : `https://maps.google.com/maps?q=${ cepData . siafi } ${ cepData . localidade } , ${ cepData . uf } &t=k&z=15&ie=UTF8&iwloc=&output=embed` , frameBorder : '0' , scrolling : 'no' , marginHeight : '0' , marginWidth : '0' } ) ;
73
- $ ( '.map' ) . append ( mapData ) ;
69
+ // inserting map iframe based on CEP data on html (IIFE function)
70
+ ( insertMap = cepData => {
71
+ const mapData = document . createElement ( 'iframe' ) ;
72
+ $ ( mapData ) . attr ( { id : 'map-iframe' , src : `https://maps.google.com/maps?q=${ cepData . siafi } ${ cepData . localidade } , ${ cepData . uf } &t=k&z=15&ie=UTF8&iwloc=&output=embed` , frameBorder : '0' , scrolling : 'no' , marginHeight : '0' , marginWidth : '0' } ) ;
73
+ $ ( '.map' ) . append ( mapData ) ;
74
+ } ) ( cepData ) ;
74
75
75
76
// showing results
77
+ $ ( '.catch-data' ) . addClass ( 'catch-data-active' ) ;
78
+ $ ( '.user-input' ) . addClass ( 'user-input-active' ) ;
76
79
$ ( '.spinner-border' ) . delay ( 600 ) . hide ( 0 ) ;
77
80
$ ( '.result' ) . show ( ) . addClass ( 'result-active' ) ;
78
81
} else {
0 commit comments