-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
231 lines (195 loc) · 7.08 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//Like count
let aboutMeCount = 0;
let fccCount = 0;
let tributePageCount = 0;
let functionsPartOneCount = 0;
let functionsPartTwoCount = 0;
let domCount = 0;
let arrayCount = 0;
let objectsCount = 0;
let featureCount = 0;
let aboutMeLikeCount = document.getElementById("aboutMeLikeCount");
let fccLikeCount = document.getElementById("fccLikeCount");
let tributePageLikeCount = document.getElementById("tributePageLikeCount");
let functionsPartOneLikeCount = document.getElementById("functionsPartOne");
let functionsPartTwoLikeCount = document.getElementById(
"functionsPartTwoLikeCount"
);
let domLikeCount = document.getElementById("domLikeCount");
let arrayLikeCount = document.getElementById("arrayLikeCount");
let objectsLikeCount = document.getElementById("objectsLikeCount");
let featureLikeCount = document.getElementById("featureLikeCount");
function aboutMeLike() {
aboutMeCount += 1;
aboutMeLikeCount.innerHTML = `${aboutMeCount}`;
}
function aboutMeDislike() {
aboutMeCount -= 1;
aboutMeLikeCount.innerHTML = `${aboutMeCount}`;
}
function fccLike() {
fccCount += 1;
fccLikeCount.innerHTML = `${fccCount}`;
}
function fccDislike() {
fccCount -= 1;
fccLikeCount.innerHTML = `${fccCount}`;
}
function tributePageLike() {
tributePageCount += 1;
tributePageLikeCount.innerHTML = `${tributePageCount}`;
}
function tributePageDislike() {
tributePageCount -= 1;
tributePageLikeCount.innerHTML = `${tributePageCount}`;
}
function functionsPartOneLike() {
functionsPartOneCount += 1;
functionsPartOneLikeCount.innerHTML = `${functionsPartOneCount}`;
}
function functionsPartOneDislike() {
functionsPartOneCount -= 1;
functionsPartOneLikeCount.innerHTML = `${functionsPartOneCount}`;
}
function functionsPartTwoLike() {
functionsPartTwoCount += 1;
functionsPartTwoLikeCount.innerHTML = `${functionsPartTwoCount}`;
}
function functionsPartTwoDislike() {
functionsPartTwoCount -= 1;
functionsPartTwoLikeCount.innerHTML = `${functionsPartTwoCount}`;
}
function domLike() {
domCount += 1;
domLikeCount.innerHTML = `${domCount}`;
}
function domDislike() {
domCount -= 1;
domLikeCount.innerHTML = `${domCount}`;
}
function arrayLike() {
arrayCount += 1;
arrayLikeCount.innerHTML = `${arrayCount}`;
}
function arrayDislike() {
arrayCount -= 1;
arrayLikeCount.innerHTML = `${arrayCount}`;
}
function objectsLike() {
objectsCount += 1;
objectsLikeCount.innerHTML = `${objectsCount}`;
}
function objectsDislike() {
objectsCount -= 1;
objectsLikeCount.innerHTML = `${objectsCount}`;
}
function featureLike() {
featureCount += 1;
featureLikeCount.innerHTML = `${featureCount}`;
}
function featureDislike() {
featureCount -= 1;
featureLikeCount.innerHTML = `${featureCount}`;
}
//Weather feature
let temperature = document.getElementById("temperature");
let weatherDescription = document.getElementById("weather-description");
let iconElement = document.getElementById("weather-icon");
function displayCelciusTemp(response) {
let temp = Math.round(response.data.main.temp);
let description = response.data.weather[0].description;
let descriptionUpper =
description.charAt(0).toUpperCase() + description.slice(1);
temperature.innerHTML = `${temp}°C`;
weatherDescription.innerHTML = `${descriptionUpper}`;
iconElement.setAttribute(
`src`,
`https://openweathermap.org/img/wn/${response.data.weather[0].icon}@2x.png`
);
}
function showPosition(position) {
let latitude = position.coords.latitude;
let longitude = position.coords.longitude;
let apiUrl = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&units=metric`;
let apiKey = `d3da927bc59cf1a6983a5b442fc7678e`;
let timeApiKey = `1da0e66d8c6e4cb08f8b2086326b20b6`;
let timeURL = `https://api.ipgeolocation.io/timezone?apiKey=${timeApiKey}&lat=${latitude}&long=${longitude}`;
axios.get(`${apiUrl}&appid=${apiKey}`).then(displayCelciusTemp);
axios.get(`${timeURL}`).then(showLiveTime);
}
function getCurrentLocation() {
navigator.geolocation.getCurrentPosition(showPosition);
}
getCurrentLocation();
// Comment box
let time;
let zoneName;
function addComment(element) {
const boxContainer = element.parentNode.parentNode.parentNode;
const commentContainer = element.parentNode;
commentContainer.classList.add("comment-container-after-click");
const commentBox = document.createElement("textarea");
commentBox.classList.add("comment-box-after-click");
commentBox.placeholder = "What are your thoughts?";
commentBox.innerHTML = "";
const submitComment = document.createElement("button");
submitComment.classList.add("submit-comment-after-click");
submitComment.innerHTML = "Comment";
commentContainer.append(commentBox, submitComment);
submitComment.onclick = function postComment() {
let comment = commentBox.value;
const commentBoxContainer = document.createElement("div");
commentBoxContainer.classList.add("comment-box-container");
const newComments = document.createElement("p");
newComments.classList.add("comment-boxes");
boxContainer.appendChild(commentBoxContainer);
boxContainer.appendChild(newComments);
commentBoxContainer.innerHTML = `You posted: @${time} ${zoneName} `;
newComments.innerHTML = `${comment}`;
commentBox.value = "";
};
}
function comment(event) {
if (event.target.classList.value === "comment-button") {
const commentButton = event.target;
commentButton.style.display = "none";
const commentIcon = document.getElementsByClassName("comment-icon");
const iconArray = Array.from(commentIcon);
iconArray.forEach((icon) => {
if (icon.nextElementSibling.style.display === "none") {
icon.style.display = "none";
}
});
addComment(commentButton);
}
if (event.target.classList.value === "comment-icon") {
const icon = event.target;
icon.style.display = "none";
const button = document.getElementsByClassName("comment-button");
const buttonArray = Array.from(button);
if (event.target.parentNode.parentNode.id === "aboutMe") {
buttonArray[0].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "freeCodeCamp") {
buttonArray[1].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "tributePage") {
buttonArray[2].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "functionsPartOne") {
buttonArray[3].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "functionsPartTwo") {
buttonArray[4].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "dom") {
buttonArray[5].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "arrays") {
buttonArray[6].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "objects") {
buttonArray[7].style.display = "none";
} else if (event.target.parentNode.parentNode.id === "feature") {
buttonArray[8].style.display = "none";
}
addComment(icon);
}
}
function showLiveTime(response) {
time = response.data.date_time.slice(10, 16);
zoneName = response.data.timezone;
}