Skip to content

Commit 1acb57e

Browse files
committed
Add background image to results
1 parent 42ef06c commit 1acb57e

File tree

9 files changed

+263
-121
lines changed

9 files changed

+263
-121
lines changed

dist/index.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="collapse navbar-collapse" id="navbarText">
1818
<ul class="navbar-nav mr-auto">
1919
<li class="nav-item active">
20-
<a class="nav-link home" href="#">Home</a>
20+
<a class="nav-link" id="home">Home</a>
2121
</li>
2222
</ul>
2323
<span class="navbar-text">
@@ -29,40 +29,40 @@
2929
<div class="text-center bg-dark p-3 w-75 mx-auto d-flex flex-column">
3030
<h1 class="text-white-50">Search by Location</h1>
3131
<h5>Write the location to get the weather</h5>
32-
<form id="search" action="javascript:void(0);">
32+
<form id="searching" action="javascript:void(0);">
3333
<input class="form-class w-50" type="text" id="search" placeholder="Input your search keyword" name="search">
3434
<br><br>
3535
<input type="submit" class="btn btn-warning" id="submit" value="Search!">
3636
</form>
3737
</div>
3838
</main>
39-
<section id="section">
39+
<section id="section" class="bg-dark p-4">
4040
<div class="card bg-dark text-white w-50 m-auto">
41-
<div class="image"></div>
41+
<div id="image"></div>
4242
<div class="card-img-overlay">
43-
<h5 class="card-title title text-center text-warning"></h5>
43+
<h5 class="card-title text-center text-warning" id="title"></h5>
4444
<div class="d-flex flex-row justify-content-around">
4545
<ul class="list-group list-unstyled">
46-
<li style="background-color: 255,255,255,0.8;";class="list-group-item temp"><i class="fas fa-thermometer-half text-warning my-2"></i></li>
47-
<li style="background-color: 255,255,255,0.8;";class="list-grouy-item feel"><i class="fas fa-meteor text-warning my-2"></i></li>
48-
<li style="background-color: 255,255,255,0.8;";class="list-group-item desc"><i class="fas fa-cloud-sun-rain text-warning my-2"></i></li>
49-
<li style="background-color: 255,255,255,0.8;";class="list-group-item pressure"><i class="fas fa-compress-arrows-alt text-warning my-2"></i></li>
50-
<li style="background-color: 255,255,255,0.8;";class="list-group-item humidity"><i class="fas fa-percent text-warning my-2"></i></li>
46+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="temp"></li>
47+
<li style="background-color: 255,255,255,0.8;";class="list-grouy-item" id="feel"></li>
48+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="desc"></li>
49+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="pressure"></li>
50+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="humidity"></li>
5151
</ul>
5252
<ul class="list-group list-unstyled">
53-
<li style="background-color: 255,255,255,0.8;";class="list-group-item minTemp"><i class="fas fa-temperature-low text-warning my-2"></i></li>
54-
<li style="background-color: 255,255,255,0.8;";class="list-group-item maxTemp"><i class="fas fa-temperature-high text-warning my-2"></i></li>
55-
<li style="background-color: 255,255,255,0.8;";class="list-group-item wind"><i class="fas fa-wind text-warning my-2"></i></li>
56-
<li style="background-color: 255,255,255,0.8;";class="list-group-item windDir"><i class="fas fa-compass text-warning my-2"></i></li>
57-
<li style="background-color: 255,255,255,0.8;";class="list-group-item clouds"><i class="fas fa-cloud text-warning my-2"></i></li>
53+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="minTemp"></li>
54+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="maxTemp"></li>
55+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="wind"></li>
56+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="windDir"></li>
57+
<li style="background-color: 255,255,255,0.8;";class="list-group-item" id="clouds"></li>
5858
</ul>
5959
</div>
6060
</div>
6161
</div>
6262
</section>
6363
<footer class="footer bg-dark p-3">
6464
<div class="container">
65-
<p class="text-muted">Powered By &copy; JaviCorp</p>
65+
<p class="text-warning">Powered By &copy; JaviCorp</p>
6666
</div>
6767
</footer>
6868
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>

dist/main.js

Lines changed: 174 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/images/drizzle.jpg

21.5 KB
Loading

src/images/mist.jpg

49 KB
Loading

src/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1+
import { dom } from './js/dom';
2+
import { events } from './js/events';
3+
import { helpers } from './js/helpers';
14
import './style/style.css';
25

6+
let manip = dom();
7+
let event = events();
8+
let help = helpers();
9+
10+
const submit = document.getElementById('submit');
11+
submit.addEventListener('click', event.getSearch);
12+
13+
const home = document.getElementById('home');
14+
home.addEventListener('click', ()=>{ manip.show() });
15+
16+

src/js/dom.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,52 @@ const dom = function () {
1313
}
1414

1515
function fillCard(data) {
16-
helpers.addInnerText('temp', data['main']['temp'] + ' Celsius');
17-
helpers.addInnerText('feel', data['main']['feels_like'] + ' Celsius');
18-
helpers.addInnerText('desc', data['weather']['main']);
19-
helpers.addInnerText('pressure', data['main']['pressure'] + ' hPa');
20-
helpers.addInnerText('humidity', data['main']['humidity'] + '%');
21-
helpers.addInnerText('minTemp', data['main']['temp_min'] + ' Celsius');
22-
helpers.addInnerText('maxTemp', data['main']['temp_max'] + ' Celsius');
23-
helpers.addInnerText('wind', data['wind']['speed'] + ' meter/sec');
24-
helpers.addInnerText('windDir', data['wind']['deg'] + ' degrees');
25-
helpers.addInnerText('clouds', data['clouds']['all'] + '%');
16+
helpers().addInnerText('title', data['name']);
17+
helpers().addInnerText('temp', '<i class="fas fa-thermometer-half text-warning my-2"></i> ' + data['main']['temp'] + ' Celsius');
18+
helpers().addInnerText('feel', '<i class="fas fa-meteor text-warning my-2"></i> ' + data['main']['feels_like'] + ' Celsius');
19+
helpers().addInnerText('desc', '<i class="fas fa-cloud-sun-rain text-warning my-2"></i> ' + data['weather'][0]['main']);
20+
helpers().addInnerText('pressure', '<i class="fas fa-compress-arrows-alt text-warning my-2"></i> ' + data['main']['pressure'] + ' hPa');
21+
helpers().addInnerText('humidity', '<i class="fas fa-percent text-warning my-2"></i> ' + data['main']['humidity'] + '%');
22+
helpers().addInnerText('minTemp','<i class="fas fa-temperature-low text-warning my-2"></i> ' + data['main']['temp_min'] + ' Celsius');
23+
helpers().addInnerText('maxTemp','<i class="fas fa-temperature-high text-warning my-2"></i>' + data['main']['temp_max'] + ' Celsius');
24+
helpers().addInnerText('wind','<i class="fas fa-wind text-warning my-2"></i> ' + data['wind']['speed'] + ' meter/sec');
25+
helpers().addInnerText('windDir','<i class="fas fa-compass text-warning my-2"></i> ' + data['wind']['deg'] + ' degrees');
26+
helpers().addInnerText('clouds','<i class="fas fa-cloud text-warning my-2"></i> ' + data['clouds']['all'] + '%');
2627
}
2728

29+
function imageSwitch(data) {
30+
const code = data['weather'][0]['id'];
31+
switch (true) {
32+
case code >= 200 && code <= 232:
33+
document.getElementById('image').style.backgroundImage = "url('../src/images/lighting.jpg')";
34+
break;
35+
case code >= 300 && code <= 321:
36+
document.getElementById('image').style.backgroundImage = "url('../src/images/drizzle.jpg')";
37+
break;
38+
case code >= 500 && code <= 531:
39+
document.getElementById('image').style.backgroundImage = "url('../src/images/rain.jpg')";
40+
break;
41+
case code >= 600 && code <= 622:
42+
document.getElementById('image').style.backgroundImage = "url('../src/images/snow.jpg')";
43+
break;
44+
case code >= 701 && code <= 781:
45+
document.getElementById('image').style.backgroundImage = "url('../src/images/mist.jpg')";
46+
break;
47+
case code >= 801 && code <= 804:
48+
document.getElementById('image').style.backgroundImage = "url('../src/images/rainclouds.jpg')";
49+
break;
50+
case code==800:
51+
document.getElementById('image').style.backgroundImage = "url('../src/images/shiningsun.jpg')";
52+
break;
53+
default:
54+
document.getElementById('image').style.backgroundImage = "url('../src/images/bluesky.jpg')";
55+
break;
56+
}
57+
};
58+
2859

2960

30-
return { show, fillCard, }
61+
return { show, fillCard, imageSwitch, }
3162
};
3263

3364
export { dom }

src/js/events.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {dom} from './dom';
22

33
const events = function () {
4-
const submit = document.getElementById('submit');
4+
55
async function getSearch() {
66
try {
77
const value = (document.getElementById('search').value).toLowerCase();
@@ -15,13 +15,12 @@ const events = function () {
1515
} catch (error) {
1616
console.error('Error:', error);
1717
}
18-
};
19-
submit.addEventListener('click', getSearch);
20-
18+
};
2119

2220
function showFlow(data) {
23-
dom.fillCard(data);
24-
dom.show()
21+
dom().fillCard(data);
22+
dom().imageSwitch(data);
23+
dom().show()
2524
};
2625

2726
return { getSearch, showFlow, }

src/js/helpers.js

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,17 @@
11
const helpers = function helpers() {
2-
3-
const addInnerText = function addInnerText(className, text) {
4-
const element = document.getElementsByClassName(className);
5-
element.innerHTML = text;
2+
const createElement = function createElement(tag, className) {
3+
const element = document.createElement(tag);
4+
element.className = className;
65
return element;
7-
};
8-
9-
const whichCardBg = function whichCardBg(weather) {
10-
let classNames;
11-
switch (weather) {
12-
case 'high':
13-
classNames = {
14-
cardCN: 'card border-danger mb-3',
15-
bodyCN: 'card-body text-danger',
16-
footerCN: 'card-footer bg-transparent border-danger',
17-
headerCN: 'card-header text-danger border-danger border-bottom',
18-
iconEditCN: 'far fa-edit text-danger mr-3',
19-
iconTrashCN: 'far fa-trash-alt text-danger',
20-
};
21-
break;
22-
case 'medium':
23-
classNames = {
24-
cardCN: 'card border-primary mb-3',
25-
bodyCN: 'card-body text-primary',
26-
footerCN: 'card-footer bg-transparent border-primary',
27-
headerCN: 'card-header text-primary border-primary border-bottom',
28-
iconEditCN: 'far fa-edit text-primary mr-3',
29-
iconTrashCN: 'far fa-trash-alt text-primary',
30-
};
31-
break;
32-
default:
33-
classNames = {
34-
cardCN: 'card border-success mb-3',
35-
bodyCN: 'card-body text-success',
36-
footerCN: 'card-footer bg-transparent border-success',
37-
headerCN: 'card-header text-success border-success border-bottom',
38-
iconEditCN: 'far fa-edit text-success mr-3',
39-
iconTrashCN: 'far fa-trash-alt text-success',
40-
};
41-
}
42-
return classNames;
43-
};
44-
45-
// eslint-disable-next-line no-unused-vars
46-
const createCard = function createCard(todo, todoId) {
47-
const {
48-
cardCN,
49-
bodyCN,
50-
footerCN,
51-
headerCN,
52-
iconEditCN,
53-
iconTrashCN,
54-
} = whichCardBg(todo.priority);
55-
const col = createElement('div', 'col-4');
56-
const card = createElement('div', cardCN);
57-
card.style = 'max-width: 18rem;';
58-
const cardHeader = createElementWithInnerText('div', headerCN, todo.title);
59-
60-
const cardBody = createElement('div', bodyCN);
61-
const h5 = createElementWithInnerText('h5', 'card-title', todo.description);
62-
const everything = `${todo.notes} ${todo.dueDate} ${todo.priority}`;
63-
const cardText = createElementWithInnerText('p', 'card-text', everything);
64-
65-
const cardFooter = createElement('footer', footerCN);
66-
const editIcon = createElement('i', iconEditCN);
67-
const trashIcon = createElement('i', iconTrashCN);
68-
69-
cardFooter.appendChild(editIcon);
70-
cardFooter.appendChild(trashIcon);
71-
card.appendChild(cardHeader);
72-
todoList.appendChild(col);
73-
cardBody.appendChild(h5);
74-
cardBody.appendChild(cardText);
75-
card.appendChild(cardBody);
76-
card.appendChild(cardFooter);
77-
col.appendChild(card);
78-
79-
return {
80-
col,
81-
trashIcon,
82-
editIcon,
836
};
7+
8+
const addInnerText = function addInnerText(className, text) {
9+
const element = document.getElementById(className);
10+
return element.innerHTML = text;
8411
};
8512

8613
return {
87-
addInnerText,
14+
addInnerText, createElement,
8815
};
8916
};
9017

src/style/style.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
background-image: url("../images/summer.jpg");
44
background-size: cover;
55
background-position-y: 100%;
6-
height: 100vh;
6+
height: 80vh;
77
}
88

9-
.image {
9+
#image {
1010
background-image: url("../images/sunset.jpg");
1111
background-size: cover;
1212
background-position-y: 100%;
1313
height: 75vh;
1414
}
1515

1616
#section {
17-
display: block;
17+
display: none;
18+
height: 80vh;
1819
}
1920

0 commit comments

Comments
 (0)