-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
291 lines (244 loc) · 10.7 KB
/
main.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// NEW POST VARIABLE ==============================================================================
const postInput = document.querySelector(".post-input");
const post = document.querySelector(".post-container");
const postPar = document.querySelector(".post-par");
// TO POST WHEN CLICK ENTER =================================================================================
postInput.addEventListener("keypress", function(event){
if (event.key === "Enter"){
let newPost = document.createElement('div')
newPost.classList.add('new-post');
newPost.innerHTML = `
<div class="news-header flex-row paragraph-box">
<div class="flex-row">
<div class="news-dp">
<img src="images/robin.png" alt="">
</div>
<div class="dp-name">
<p><strong>Robin Dela Cruz</strong></p>
<div class="flex-row under-name">
<small class="seconds">12s •</small><img src="images/globe.png" alt="" class="news-icon">
</div>
</div>
</div>
<div class="dot-menu hover2">
<img src="images/dotmenu.png" alt="" class="news-icon dot">
<div class="triangle"></div>
<small class="del-post">Delete Post</small>
</div>
</div>
<div class="paragraph">
<p class="post-par">${postInput.value}</p>
</div>
<div class="news-footer flex-column">
<div class="flex-row likes">
<div class="flex-row">
<img src="images/react2.png" alt="">
<p class="react-quan">3</p>
</div>
<div class="flex-row comments">
<p class="com-quan">2 Comments</p>
<p class="share-quan">1 Share</p>
</div>
</div>
<div class="flex-row interact mind share">
<div class="flex-row interact-icons like-container" id="com-react">
<div class="like-icon">
</div>
<p class ="like">Like</p>
</div>
<div class="flex-row interact-icons" id="com-react">
<img src="images/comment.png" alt="">
<p>Comment</p>
</div>
<div class="flex-row interact-icons" id="com-react">
<img src="images/share.png" alt="">
<p>Share</p>
</div>
</div>
</div>`
const toast = document.querySelector('.toast')
const toastBtn = document.querySelector('.btn-toast')
if(postInput.value === ""){
toast.classList.add('active')
setTimeout(function(){
toast.classList.remove('active')
}, 3000)
}
else{
post.appendChild(newPost)
postInput.value = ""
}
toastBtn.addEventListener('click', function(){
toast.classList.remove('active')
})
// RANDOM NUMBERS ON NEW POST LIKE COMMENTS & SHARE =========================================================
const seconds= newPost.querySelectorAll(".seconds");
const shareQuan= newPost.querySelectorAll(".share-quan");
const comQuan= newPost.querySelectorAll(".com-quan");
const reactQuan = newPost.querySelectorAll(".react-quan");
// RANDOM NUMBERS ARRAY ================================================================
const array = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
// DELETING FOR NEW POST VARIABLES ================================================================
const dotMenu = newPost.querySelectorAll(".dot-menu")
let delPost = newPost.querySelector(".del-post")
// LIKE VARIABLES =================================================================================
const likeContainer = newPost.querySelectorAll(".like-container");
// RANDOM NUMBERS FUNCTIONS =================================================================================
for(i = 0; i < likeContainer.length; i++){
reactQuan[i].textContent = generate()
seconds[i].textContent = generate() + "s"
shareQuan[i].textContent = generate() + " Shares"
comQuan[i].textContent = generate() + " Comments"
function generate(){
let random = Math.floor(Math.random()*array.length)
return array[random]
}
// DELETING FOR NEW POST =================================================================================
for(j = 0; j < dotMenu.length; j++){
dotMenu[j].addEventListener('click', function(){
this.classList.toggle('active')
})
}
delPost.addEventListener('click', function(e){
let target = e.target
target.parentElement.parentElement.parentElement.remove()
})
// LIKE FUNCTIONS =================================================================================
likeContainer.forEach(function(btn){
btn.addEventListener('click', function(){
btn.classList.toggle('active')
for(j = 0; j < reactQuan.length; j++){
reactQuan[j].classList.toggle('activequan');
}
})
})
// HIDES DOT MENU AND WHATS NEW =================================================================================
window.addEventListener('scroll', function(){
for(j = 0; j < dotMenu.length; j++){
dotMenu[j].classList.remove('active')
}
})
}
}
})
// =================================================================================================
// LOADING IN START OF WEBSITE ===================================================================
let load = document.querySelector(".loading");
setTimeout(() =>{
load.classList.add('hide-load');
},9620)
// 9620
// ================================================================================================
// DELETES FRIEND REQUEST =========================================================================
let friend = document.querySelector(".div-friend");
function del(){
friend.style.display = 'none';
}
// =================================================================================================
// CHANGE OVERFLOWING TEXT IN SMALLER DEVICES=======================================================
let photo = document.getElementById("photo");
var mq = window.matchMedia('(max-width: 700px)');
function render(e){
if (e.matches){
photo.innerText = "Photo";
postInput.placeholder = "Whats on your mind?";
profNav.classList.remove('block')
for(j = 0; j < dotMenu.length; j++){
dotMenu[j].classList.remove('active')
}
}
else{
photo.textContent = "Photo/Video";
postInput.placeholder = "Whats on your mind? Robin";
}
}
render(mq);
mq.addEventListener('change', render)
// =================================================================================================
// TO DELETE A POST ================================================================
const dotMenu = document.querySelectorAll(".dot-menu")
let delPost = document.querySelectorAll(".del-post")
for(j = 0; j < dotMenu.length; j++){
dotMenu[j].addEventListener('click', function(){
this.classList.toggle('active')
})
}
delPost.forEach(function(del){
del.addEventListener('click', function(e){
let target = e.target
target.parentElement.parentElement.parentElement.remove()
})
})
// LIKE VARIABLES =================================================================================
const likeContainer = document.querySelectorAll(".like-container");
// LIKE FUNCTIONS ================================================================
likeContainer.forEach(function(btn){
btn.addEventListener('click', function(){
btn.classList.toggle('active')
const reactQuan = document.querySelectorAll(".react-quan");
reactQuan.forEach(function(quan){
if(btn.classList.contains('active')){
quan.classList.add('activequan');
}
else{
quan.classList.remove('activequan');
}
})
})
})
// likeContainer.forEach(function(btn){
// btn.addEventListener('click', function(e){
// let target = e.currentTarget
// target.classList.toggle('active')
// for(j = 0; j < reactQuan.length; j++){
// reactQuan[j].classList.toggle('activequan');
// }
// })
// })
// STORIES SCROLL BUTTON =================================================================================
const storyScroll = document.querySelector('.stories-scroll')
const btnNext = document.querySelector('.btn-next')
const btnPrev = document.querySelector('.btn-prev')
btnNext.addEventListener('click', function(){
storyScroll.scrollTo(500,0)
btnPrev.style.display = 'flex'
btnPrev.style.zIndex = '1'
})
btnPrev.addEventListener('click', function(){
storyScroll.scrollTo(0,0)
btnPrev.style.display = 'none'
btnPrev.style.zIndex = '-1'
})
storyScroll.addEventListener("scroll", function(){
const scrollWidth = storyScroll.pageXoffset
console.log(scrollWidth)
if(scrollWidth > 100){
btnPrev.style.display = 'none'
btnPrev.style.zIndex = '-1'
}
else{
btnPrev.style.display = 'flex'
btnPrev.style.zIndex = '1'
}
})
// TO SHOW WHATS NEW ON TOP PROFILE =================================================================================
const profNav = document.querySelector('.profile-nav')
const rightBar = document.querySelector('.right-bar')
profNav.addEventListener('click', function(){
profNav.classList.toggle('block')
})
rightBar.addEventListener('scroll', function(){
profNav.classList.remove('block')
})
const video = document.querySelectorAll('video')
// HIDES DOT MENU AND WHATS NEW =================================================================================
window.addEventListener('scroll', function(){
profNav.classList.remove('block')
video.forEach(function(vid){
vid.pause()
})
for(j = 0; j < dotMenu.length; j++){
dotMenu[j].classList.remove('active')
}
})
// =================================================================================================