-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
146 lines (111 loc) · 4.35 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
/*=============== SHOW MENU ===============*/
const navMenu = document.getElementById("nav-menu"),
navToggle = document.getElementById("nav-toggle"),
navClose = document.getElementById("nav-close")
// MENU SHOW (validate if constant exists)
if(navToggle){
navToggle.addEventListener('click', () => {
navMenu.classList.add('show-menu')
})
}
// MENU HIDDEN(validate if constant exists)
if(navClose){
navClose.addEventListener('click', () =>{
navMenu.classList.remove("show-menu")
})
}
/*=============== REMOVE MENU MOBILE ===============*/
const navLink = document.querySelectorAll('.nav__link')
const linkAction = () => {
const navMenu = document.getElementById('nav-menu')
//when we click on each nav__link, we remove the show-menu
navMenu.classList.remove('show-menu')
}
navLink.forEach(n => n.addEventListener('click', linkAction))
/*=============== SWIPER PROJECTS ===============*/
let swiperProjects = new Swiper(".projects__container", {
loop: true,
spaceBetween: 24,
cssMode: true,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
pagination: {
el: ".swiper-pagination",
},
breakpoints: {
1200: {
slidesPerView: 2,
spaceBetween: -56,
},
},
});
/*=============== SWIPER TESTIMONIAL ===============*/
let swiperTestimonial = new Swiper(".testimonial__container", {
grabCursor: true,
pagination: {
el: ".swiper-pagination",
},
});
/*=============== EMAIL JS ===============*/
const contactForm = document.getElementById('contact-form'),
contactName = document.getElementById('contact-name'),
contactEmail = document.getElementById('contact-email'),
contactProject = document.getElementById('contact-project'),
contactMessage = document.getElementById('contact-message')
const sendEmail = (e) => {
e.preventDefault()
//check if the field has value
if(contactName.value === '' || contactEmail.value === '' || contactProject === ''){
//add and remove color
contactMessage.classList.remove('color-blue')
contactMessage.classList.add('color-red')
//show message
contactMessage.textContent = 'Write all the input fields 📩'
}else{
//serviceID - templateID - #form - publicKey
emailjs.sendForm('service_rinwr1k','template_kty1jkb','#contact-form','kRl6AkZII0V5cuPSi')
.then(() =>{
//show message and add color
contactMessage.classList.add('color-blue')
contactMessage.textContent = 'Message Sent ✅'
//remove message after 5 seconds
setTimeout(() => {
contactMessage.textContent = ''
}, 5000)
}, (error) => {
alert('OOPS, Something went wrong while sending your message!', error)
})
//to clear the input field
contactName.value = ''
contactEmail.value = ''
contactProject.value = ''
}
}
contactForm.addEventListener('submit', sendEmail)
/*=============== DARK LIGHT THEME ===============*/
const themeButton = document.getElementById('theme-button')
const darkTheme = 'dark-theme'
const iconTheme = 'ri-sun-line'
const selectedTheme = localStorage.getItem('selected-theme')
const selectedIcon = localStorage.getItem('selected-icon')
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'
const getCurrentIcon = () => themeButton.classList.contains(iconTheme) ? 'ri-moon-line' : 'ri-sun-line'
if(selectedTheme){
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme)
themeButton.classList[selectedIcon === 'ri-moon-line' ? 'add' : 'remove'](iconTheme)
}
themeButton.addEventListener('click', () => {
document.body.classList.toggle(darkTheme)
themeButton.classList.toggle(iconTheme)
localStorage.setItem('selected-theme', getCurrentTheme())
localStorage.setItem.apply('selected-icon', getCurrentIcon)
})
/*=============== CHANGE BACKGROUND HEADER ===============*/
const scrollHeader = () =>{
const header = document.getElementById('header')
this.scrollY >= 50 ? header.classList.add('bg-header')
: header.classList.remove('bg-header')
}
window.addEventListener('scroll', scrollHeader)