-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
389 lines (332 loc) · 12.4 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*---------------------------------navigation menu-------------------------------*/
(() =>{
const hamburgerBtn = document.querySelector(".hamburger-btn"),
navMenu = document.querySelector(".nav-menu"),
closeNavBtn = navMenu.querySelector(".close-nav-menu");
hamburgerBtn.addEventListener("click", showNavMenu);
closeNavBtn.addEventListener("click", hideNavMenu);
function showNavMenu(){
navMenu.classList.add("open");
bodyScrollingToggle();
}
function hideNavMenu(){
navMenu.classList.remove("open");
fadeOutEffect();
bodyScrollingToggle();
}
function fadeOutEffect(){
document.querySelector(".fade-out-effect").classList.add("active");
setTimeout(() =>{
document.querySelector(".fade-out-effect").classList.remove("active");
},300)
}
// attach and event handler to document.
document.addEventListener("click", (event) =>{
if(event.target.classList.contains('link-item')){
if(event.target.hash !==""){
event.preventDefault();
const hash = event.target.hash;
document.querySelector(".section.active").classList.add("hide");
document.querySelector(".section.active").classList.remove("active");
document.querySelector(hash).classList.add("active");
document.querySelector(hash).classList.remove("hide");
/* deactivate existing active navigation menu 'link-item' */
navMenu.querySelector(".active").classList.add("outer-shadow","hover-in-shadow");
navMenu.querySelector(".active").classList.remove("active","inner-shadow");
/*if clicked 'link-item' contained within the navigation menu*/
if(navMenu.classList.contains("open")){
// activate new naviagation menu 'link-item'
event.target.classList.add("active","inner-shadow");
event.target.classList.remove("outer-shadow","hover-in-shadow");
// hide navigation menu
hideNavMenu();
}
else{
let navItems = navMenu.querySelectorAll(".link-item");
navItems.forEach((item) =>{
if(hash === item.hash){
// activate new navigation menu 'link-item'
item.classList.add("active","inner-shadow");
item.classList.remove("outer-shadow","hover-in-shadow");
}
})
fadeOutEffect();
}
//add hash (#) to url
window.location.hash = hash;
}
}
})
})();
/*----------------- about us section tabs---------------*/
(() =>{
const aboutSection = document.querySelector(".about-section"),
tabsContainer = document.querySelector(".about-tabs");
/*if event.target contains 'tab-item' class and not contains 'active' class */
tabsContainer,addEventListener("click", (event) =>{
if(event.target.classList.contains("tab-item") &&
!event.target.classList.contains("active")){
const target = event.target.getAttribute("data-target");
// deactivate existing activev 'tab-item'
tabsContainer.querySelector(".active").classList.remove("outer-shadow","active");
// activate new 'tab-item'
event.target.classList.add("active", "outer-shadow");
// deactivate existing active 'tab-content'
aboutSection.querySelector(".tab-content.active").classList.remove("active");
//activate new tab-content'
aboutSection.querySelector(target).classList.add("active");
}
})
})();
function bodyScrollingToggle(){
document.body.classList.toggle("hidden-scrolling");
}
/*----------------------------------------------------- portfolio filter ad popup ----------------------------------------*/
(() =>{
const filterContainer = document.querySelector(".portfolio-filter"),
portfolioItemsContainer = document.querySelector(".portfolio-items"),
portfolioItems = document.querySelectorAll(".portfolio-item"),
popup = document.querySelector(".portfolio-popup"),
prevBtn = popup.querySelector(".pp-prev"),
nextBtn = popup.querySelector(".pp-next"),
closeBtn = popup.querySelector(".pp-close"),
projectDetailsContainer = popup.querySelector(".pp-details"),
projectDetailsBtn = popup.querySelector(".pp-project-details-btn");
let itemIndex, slideIndex, screenshots;
/* filter portfolio items*/
filterContainer.addEventListener("click", (event)=>{
if(event.target.classList.contains("filter-item")&&
!event.target.classList.contains("active")){
// deactivate existing active 'filter-item'
filterContainer.querySelector(".active").classList.remove("outer-shadow","active");
//activate new 'filter item'
event.target.classList.add("active","outer-shadow");
const target = event.target.getAttribute("data-target");
portfolioItems.forEach((item) =>{
if(target === item.getAttribute("data-category") || target === 'all'){
item.classList.remove("hide");
item.classList.add("show");
}
else{
item.classList.remove("show");
item.classList.add("hide");
}
})
}
})
portfolioItemsContainer.addEventListener("click", (event) =>{
if(event.target.closest(".portfolio-item-inner")){
const portfolioItem = event.target.closest(".portfolio-item-inner").
parentElement;
// get the portfolioItem index
itemIndex = Array.from(portfolioItem.parentElement.children).indexOf(portfolioItem);
screenshots = portfolioItems[itemIndex].querySelector(".portfolio-item-img img").getAttribute("data-screenshots");
// convert screenshots into array
screenshots = screenshots.split(",");
if(screenshots.length === 1){
prevBtn.style.display="none";
nextBtn.style.display="none";
}
else{
prevBtn.style.display="block";
nextBtn.style.display="block";
}
slideIndex = 0;
popupToggle();
popupSlideshow();
popupDetails();
}
})
closeBtn.addEventListener("click", () =>{
popupToggle();
if(projectDetailsContainer.classList.contains("active")){
popupDetailsToggle();
}
})
function popupToggle() {
popup.classList.toggle("open");
bodyScrollingToggle();
}
function popupSlideshow(){
const imgSrc = screenshots[slideIndex];
const popupImg = popup.querySelector(".pp-img");
/* activate loader until the popupImg loaded*/
popup.querySelector(".pp-loader").classList.add("active");
popupImg.src=imgSrc;
popupImg.onload = () =>{
// deactivate loader after the popupImg loaded
popup.querySelector(".pp-loader").classList.remove("active");
}
popup.querySelector(".pp-counter").innerHTML = (slideIndex+1) + " of " + screenshots.length;
}
// next slide
nextBtn.addEventListener("click", () =>{
if(slideIndex === screenshots.length-1){
slideIndex = 0;
}
else{
slideIndex++;
}
popupSlideshow();
})
// prev slide
prevBtn.addEventListener("click", () =>{
if(slideIndex ===0){
slideIndex = screenshots.length-1
}
else{
slideIndex--;
}
popupSlideshow();
})
function popupDetails(){
//if portfolio-item-details not exists
if(!portfolioItems[itemIndex].querySelector(".portfolio-item-details")){
projectDetailsBtn.style.display="none";
return; /*end function execution*/
}
projectDetailsBtn.style.display="block";
// get the project details
const details = portfolioItems[itemIndex].querySelector(".portfolio-item-details").innerHTML;
//set the project details
popup.querySelector(".pp-project-details").innerHTML = details;
// get the project title
const title = portfolioItems[itemIndex].querySelector(".portfolio-item-title").innerHTML;
// set the project title
popup.querySelector(".pp-title h2").innerHTML = title;
//get the project category
const category = portfolioItems[itemIndex].getAttribute("data-category");
// set the project category
popup.querySelector(".pp-project-category").innerHTML = category.split("-").join(" ");
}
projectDetailsBtn.addEventListener("click",() =>{
popupDetailsToggle();
})
function popupDetailsToggle(){
if(projectDetailsContainer.classList.contains("active")){
projectDetailsBtn.querySelector("i").classList.remove("fa-minus");
projectDetailsBtn.querySelector("i").classList.add("fa-plus");
projectDetailsContainer.classList.remove("active");
projectDetailsContainer.style.maxHeight = 0 + "px"
}
else{
projectDetailsBtn.querySelector("i").classList.remove("fa-plus");
projectDetailsBtn.querySelector("i").classList.add("fa-minus");
projectDetailsContainer.classList.add("active");
projectDetailsContainer.style.maxHeight = projectDetailsContainer.scrollHeight + "px";
popup.scrollTo(0, projectDetailsContainer.offsetTop);
}
}
})();
/*----------------------------------------------------- testimonial slider ----------------------------------------*/
(() =>{
const sliderContainer = document.querySelector(".testi-slider-container"),
slides = sliderContainer.querySelectorAll(".testi-item"),
slideWidth = sliderContainer.offsetWidth,
prevBtn = document.querySelector(".testi-slider-nav .prev"),
nextBtn = document.querySelector(".testi-slider-nav .next");
activeSlide = sliderContainer.querySelector(".testi-item.active");
let slideIndex = Array.from(activeSlide.parentElement.children).indexOf(activeSlide);
// set width of all slides
slides.forEach((slide) =>{
slide.style.width = slideWidth + "px";
})
// set width of sliderContainer
sliderContainer.style.width = slideWidth * slides.length + "px";
nextBtn.addEventListener("click", () =>{
if(slideIndex === slides.length-1){
slideIndex =0;
}
else{
slideIndex++;
}
slider();
})
prevBtn.addEventListener("click", () =>{
if(slideIndex === 0){
slideIndex = slides.length-1;
}
else{
slideIndex--;
}
slider();
})
function slider(){
// deactivate existing active slides
sliderContainer.querySelector(".testi-item.active").classList.remove("active");
// activate new slide
slides[slideIndex].classList.add("active");
sliderContainer.style.marginLeft = - (slideWidth * slideIndex) + "px";
}
slider();
})();
/*----------------------------------------------------- hide all section except active ----------------------------------------*/
(() =>{
const sections = document.querySelectorAll(".section");
sections.forEach((section) =>{
if(!section.classList.contains("active")){
section.classList.add("hide");
}
})
})();
window.addEventListener("load", () =>{
//preloader
document.querySelector(".preloader").classList.add("fade-out");
setTimeout(() =>{
document.querySelector(".preloader").style.display="none";
},600)
})
/*----------------------------------------------------- Contact Form Validation ----------------------------------------*/
function validation(){
var user = document.getElementById('user').value;
var email = document.getElementById('email').value;
var message = document.getElementById('message').value;
if(user == ""){
document.getElementById('username').innerHTML = "*Enter your Name";
return false;
}
if(!isNaN(user)){
document.getElementById('username').innerHTML = "*Your name should be in Characters";
return false;
}
if(email == ""){
document.getElementById('emailId').innerHTML = "*Enter Email";
return false;
}
if(email.indexOf('@') <= 0){
document.getElementById('emailId').innerHTML = "*@ Invalid Position";
return false;
}
if((email.charAt(email.length-4)!='.') && (email.charAt(email.lenght-3)!='.')){
document.getElementById('emailId').innerHTML = "*Invalid email";
return false;
}
if(message == ""){
document.getElementById('msg').innerHTML = "*Enter your Message";
return false;
}
}
// -------------- Microphone---------------------
function record() {
var recognition = new webkitSpeechRecognition();
recognition.lang = "en-GB";
recognition.onresult = function(event) {
// console.log(event);
document.getElementById('message').value = event.results[0][0].transcript;
}
recognition.start();
}
// KeyBoard Key Press Disabled
window.onkeydown = function(e) {
if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) {//Alt+c, Alt+v will also be disabled sadly.
var warningMessage = document.querySelector('.wrn_msg');
warningMessage.style.display="block";
}
return false;
};
//Wrong KeyPress Warning message
var cross = document.querySelector('.crs');
cross.addEventListener('click',()=>{
var warningMessage = document.querySelector('.wrn_msg');
warningMessage.style.display="none";
})