@@ -2,14 +2,24 @@ import {helpers} from './helpers';
22
33const dom = function ( ) {
44
5- function show ( ) {
6- if ( document . getElementById ( 'main' ) . style . display == 'block' ) {
7- document . getElementById ( 'main' ) . style . display = 'none' ;
8- document . getElementById ( 'section' ) . style . display = 'block' ;
9- } else {
10- document . getElementById ( 'main' ) . style . display = 'none' ;
11- document . getElementById ( 'section' ) . style . display = 'block' ;
12- }
5+ function show ( value ) {
6+ switch ( true ) {
7+ case value === 'search' :
8+ document . getElementById ( 'main' ) . style . display = 'none' ;
9+ document . getElementById ( 'section' ) . style . display = 'block' ;
10+ document . getElementById ( 'section2' ) . style . display = 'none' ;
11+ break ;
12+ case value === 'forecast' :
13+ document . getElementById ( 'main' ) . style . display = 'none' ;
14+ document . getElementById ( 'section' ) . style . display = 'none' ;
15+ document . getElementById ( 'section2' ) . style . display = 'block' ;
16+ break ;
17+ default :
18+ document . getElementById ( 'main' ) . style . display = 'block' ;
19+ document . getElementById ( 'section' ) . style . display = 'none' ;
20+ document . getElementById ( 'section2' ) . style . display = 'none' ;
21+ break ;
22+ }
1323 }
1424
1525 function fillCard ( data ) {
@@ -28,39 +38,104 @@ const dom = function () {
2838 helpers ( ) . addInnerText ( 'sunset' , '<i class="fas fa-sun text-warning my-2"></i> ' + `Sunset: ${ new Date ( ( data . sys . sunset + data . timezone ) * 1000 ) . toUTCString ( ) . slice ( - 11 , - 7 ) } PM` ) ;
2939 }
3040
31- function imageSwitch ( data ) {
41+ function imageSwitch ( data , id ) {
3242 const code = data [ 'weather' ] [ 0 ] [ 'id' ] ;
3343 switch ( true ) {
3444 case code >= 200 && code <= 232 :
35- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/lighting.jpg')" ;
45+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/lighting.jpg')" ;
3646 break ;
3747 case code >= 300 && code <= 321 :
38- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/drizzle.jpg')" ;
48+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/drizzle.jpg')" ;
3949 break ;
4050 case code >= 500 && code <= 531 :
41- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/rain.jpg')" ;
51+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/rain.jpg')" ;
4252 break ;
4353 case code >= 600 && code <= 622 :
44- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/snow.jpg')" ;
54+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/snow.jpg')" ;
4555 break ;
4656 case code >= 701 && code <= 781 :
47- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/mist.jpg')" ;
57+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/mist.jpg')" ;
4858 break ;
4959 case code >= 801 && code <= 804 :
50- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/rainclouds.jpg')" ;
60+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/rainclouds.jpg')" ;
5161 break ;
5262 case code == 800 :
53- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/shiningsun.jpg')" ;
63+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/shiningsun.jpg')" ;
5464 break ;
5565 default :
56- document . getElementById ( 'image' ) . style . backgroundImage = "url('../src/images/bluesky.jpg')" ;
66+ document . getElementById ( id ) . style . backgroundImage = "url('../src/images/bluesky.jpg')" ;
5767 break ;
5868 }
5969 } ;
6070
71+ function clearForms ( ) {
72+ document . getElementById ( "searching" ) . reset ( ) ;
73+ document . getElementById ( 'navSearch' ) . reset ( ) ;
74+ }
75+
76+ function createCard ( data ) {
77+ const name = document . getElementById ( 'cityName' ) ;
78+ name . innerHTML = data . city . name ;
79+ const row = document . getElementById ( 'row' ) ;
80+ row . innerHTML = "" ;
81+ const forecastFive = data . list . filter ( function ( value , index , Arr ) {
82+ return index % 8 == 0 ;
83+ } ) ;
84+ forecastFive . forEach ( ( day , index ) => {
85+ const cont = helpers ( ) . createElement ( 'div' , "col-5" ) ;
86+ const card = helpers ( ) . createElement ( 'div' , "card bg-dark text-white w-100 mb-2 mx-2" ) ;
87+ const imgBg = helpers ( ) . createElement ( 'div' , '' ) ;
88+ imgBg . id = 'images' + `${ index + 1 } ` ;
89+ imgBg . style = "background-size: cover;background-position-y: 100%;height: 75vh;" ;
90+ const over = helpers ( ) . createElement ( 'div' , "card-img-overlay" ) ;
91+ const h5 = helpers ( ) . createElement ( 'h5' , "card-title text-center text-warning" ) ;
92+ h5 . innerHTML = day . dt_txt . slice ( 0 , - 9 ) ;
93+ const listCont = helpers ( ) . createElement ( 'div' , "d-flex flex-row justify-content-around" ) ;
94+ const ul1 = helpers ( ) . createElement ( 'ul' , "list-group list-unstyled" ) ;
95+ const ul2 = helpers ( ) . createElement ( 'ul' , "list-group list-unstyled" ) ;
96+ const temp = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-thermometer-half text-warning my-2"></i> Temp: ' + day [ 'main' ] [ 'temp' ] + ' Celsius' ) ;
97+ const feel = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-meteor text-warning my-2"></i> Feel: ' + day [ 'main' ] [ 'feels_like' ] + ' Celsius' ) ;
98+ const pressure = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-compress-arrows-alt text-warning my-2"></i> Pressure: ' + day [ 'main' ] [ 'pressure' ] + ' hPa' ) ;
99+ const humidity = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-percent text-warning my-2"></i> Humidity: ' + day [ 'main' ] [ 'humidity' ] + '%' ) ;
100+ const desc = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-cloud-sun-rain text-warning my-2"></i> ' + day [ 'weather' ] [ 0 ] [ 'main' ] ) ;
101+ const minTemp = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-temperature-low text-warning my-2"></i> Min: ' + day [ 'main' ] [ 'temp_min' ] + ' Celsius' ) ;
102+ const maxTemp = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-temperature-high text-warning my-2"></i> Max: ' + day [ 'main' ] [ 'temp_max' ] + ' Celsius' ) ;
103+ const clouds = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-cloud text-warning my-2"></i> Clouds: ' + day [ 'clouds' ] [ 'all' ] + '%' ) ;
104+ const wind = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-wind text-warning my-2"></i> ' + day [ 'wind' ] [ 'speed' ] + ' meter/sec' ) ;
105+ const windDir = helpers ( ) . createElementWithInnerText ( 'li' , "list-group-item" , '<i class="fas fa-compass text-warning my-2"></i> ' + day [ 'wind' ] [ 'deg' ] + ' degrees' ) ;
106+ const color = document . getElementsByClassName ( 'list-group-item' ) ;
107+ for ( let i = 0 ; i < color . length ; i ++ ) {
108+ color [ i ] . style = "background-color: rgba(255,255,255,0.1);" ;
109+ } ;
110+ ul2 . appendChild ( minTemp ) ;
111+ ul2 . appendChild ( maxTemp ) ;
112+ ul2 . appendChild ( wind ) ;
113+ ul2 . appendChild ( windDir ) ;
114+ ul2 . appendChild ( clouds ) ;
115+
116+ ul1 . appendChild ( temp ) ;
117+ ul1 . appendChild ( feel ) ;
118+ ul1 . appendChild ( desc ) ;
119+ ul1 . appendChild ( pressure ) ;
120+ ul1 . appendChild ( humidity ) ;
121+
122+ listCont . appendChild ( ul1 ) ;
123+ listCont . appendChild ( ul2 ) ;
124+
125+ over . appendChild ( h5 ) ;
126+ over . appendChild ( listCont ) ;
61127
128+ card . appendChild ( imgBg ) ;
129+ card . appendChild ( over ) ;
130+
131+ cont . appendChild ( card ) ;
132+ row . appendChild ( cont ) ;
133+
134+ imageSwitch ( day , ( 'images' + `${ index + 1 } ` ) ) ;
135+ } ) ;
136+ }
62137
63- return { show, fillCard, imageSwitch, }
138+ return { show, fillCard, imageSwitch, createCard , clearForms }
64139} ;
65140
66141export { dom }
0 commit comments