-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
147 lines (124 loc) · 4.56 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
//DOM Elements
const mainPage = document.querySelector('.main-page');
const loginPage = document.querySelector('.login-page');
const middleContent = document.querySelector('.middle-content');
const btnTop = document.querySelector('.btn-top');
const newsFeedPage = document.querySelector('.feeds-page')
const loginModal = document.querySelector('.login-modal');
const modalX = document.querySelector('.login-modal i');
const loginFormBtn = document.querySelector('.login-form-btn');
const postBtn = document.querySelector('.post-btn');
const modalWrapper = document.querySelector('.modal-wrapper');
const modal = document.querySelector('.modal');
const postModalX = document.querySelector('.modal-header i');
const modalPostBtn = document.querySelector('.modal-header button');
const modalFooterPlus = document.querySelector('.modal-footer span');
const modalInput = document.querySelector('.modal-input');
const user = document.querySelector('.user');
const sidebar = document.querySelector('.sidebar');
const sidebarWrapper =document.querySelector('.sidebar-wrapper');
const xBtn = document.querySelector('.sidebar-header i');
const toggle = document.querySelector('.toggle');
const circle = document.querySelector('.circle');
/************************************************ */
/************************************************ */
//MAIN PAGE
const goToLoginPage = () => {
mainPage.style.display = 'none';
loginPage.style.display = 'grid';
};
middleContent.addEventListener('click', (e) => {
// console.log(e.target.classList[1]);
if(e.target.classList[1] === 'main-btn'){
goToLoginPage();
}
});
btnTop.addEventListener('click',()=>{
const inputUserInfo = document.querySelector('.user-info');
const inputPassword = document.querySelector('.password');
// console.log(inputUserInfo.value);
if(inputUserInfo.value !== "" && inputPassword.value !== ""){
mainPage.style.display = 'none';
newsFeedPage.style.display = 'block';
}
else{
goToLoginPage();
loginModal.style.display = 'block';
}
});
// Login Page
modalX.addEventListener('click',() => { /*when * is clicked, hiding our box*/
loginModal.style.display = 'none';
});
loginFormBtn.addEventListener('click', () =>{
const loginUserInfo = document.querySelector('.login-useer-info');
const loginPassword = document.querySelector('.login-password');
if(loginUserInfo.value!=='' && loginPassword.value!==''){
loginPage.style.display = 'none';
newsFeedPage.style.display = 'block';
}
else{
loginModal.style.display = 'block';
}
});
// News feed page
//Post modal
postBtn.addEventListener('click', ()=>{
modal.style.display = 'block';
modalWrapper.classList.add('modal-wrapper-display');
});
const changeOpacity = (x) =>{
modalPostBtn.style.opacity = x;
modalFooterPlus.style.opacity = x;
}
postModalX.addEventListener('click', () => {
modal.style.display = 'none';
modalWrapper.classList.remove('modal-wrapper-display');
if(modalInput.value!==''){
modalInput.value = '';
changeOpacity(0.5);
}
});
modalInput.addEventListener('keypress', e=>{
if(e.target.value !== ''){
changeOpacity(1);
}
else if(e.target.value === ""){
console.log("hello");
changeOpacity(0.5);
}
});
modalInput.addEventListener('blur', e=>{ /*blur is when we remove focus*/
if(e.target.value === ''){
changeOpacity(0.5);
}
});
//sidebar
user.addEventListener('click', ()=>{
sidebar.classList.add('sidebar-display');
sidebarWrapper.classList.add('sidebar-wrapper-display');
});
xBtn.addEventListener('click', ()=>{
sidebar.classList.remove('sidebar-display');
sidebarWrapper.classList.remove('sidebar-wrapper-display');
});
// DARK MODE
const darkElements1 = document.querySelectorAll('.dark-mode-1');
const darkElements2 = document.querySelectorAll('.dark-mode-2');
const lightTexts = document.querySelectorAll('.light-text');
const borders = document.querySelectorAll('.border');
toggle.addEventListener('click', ()=>{
circle.classList.toggle('move');
Array.from(darkElements1).map((darkEl1)=>{ /*queryselector all returns nodelist at default, so we are converting to nodelist to array here*/
darkEl1.classList.toggle('dark-1');
});
Array.from(darkElements2).map((darkEl2)=>{
darkEl2.classList.toggle('dark-2');
});
Array.from(lightTexts).map((lightText)=>{
lightText.classList.toggle('light');
});
Array.from(borders).map(border =>{
border.classList.toggle('border-color');
})
});