-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
228 lines (197 loc) · 7.25 KB
/
main.js
File metadata and controls
228 lines (197 loc) · 7.25 KB
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
/*==================== MENU SHOW Y HIDDEN ====================*/
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');
navLink.forEach((a) =>
a.addEventListener('click', () => {
const navMenu = document.getElementById('nav-menu');
// when user click on each nav__link , remove the show-menu class
navMenu.classList.remove('show-menu');
}),
);
/*==================== ACCORDION SKILLS ====================*/
const skillsContent = document.getElementsByClassName('skills__content'),
skillsHeader = document.querySelectorAll('.skills__header');
skillsHeader.forEach((element) => {
element.addEventListener('click', function toggleSkills() {
if (this.parentNode.className === 'skills__content skills__open') {
this.parentNode.className = 'skills__content skills__close';
} else {
this.parentNode.className = 'skills__content skills__open';
}
});
});
/*==================== QUALIFICATION TABS ====================*/
const educationBtn = document.getElementById('education-btn'),
workBtn = document.getElementById('work-btn'),
educationDiv = document.getElementById('education'),
workDiv = document.getElementById('work');
educationBtn.addEventListener('click', function showEducations() {
educationBtn.style.color = '#6e57e0';
workBtn.style.color = '#6d6a7c';
educationDiv.className = 'ualification__content qualification__active';
workDiv.className = 'qualification__content';
});
workBtn.addEventListener('click', function showWorks() {
workBtn.style.color = '#6e57e0';
educationBtn.style.color = '#6d6a7c';
workDiv.className = 'ualification__content qualification__active';
educationDiv.className = 'qualification__content';
});
/*==================== SERVICES MODAL ====================*/
const modalViews = document.querySelectorAll('.services__modal'),
modalBtns = document.querySelectorAll('.services__button'),
modalCloses = document.querySelectorAll('.services__modal-close');
let modal = function (modalClick) {
modalViews[modalClick].classList.add('active-modal');
};
modalBtns.forEach((modalBtn, i) => {
modalBtn.addEventListener('click', () => {
modal(i);
});
});
modalCloses.forEach((modalClose) => {
modalClose.addEventListener('click', () => {
modalViews.forEach((modalView) => {
modalView.classList.remove('active-modal');
});
});
});
/*==================== PORTFOLIO SWIPER ====================*/
var swiper = new Swiper('.portfolio__container', {
cssMode: true,
loop: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
pagination: {
el: '.swiper-pagination',
clickable: true,
},
mousewheel: true,
keyboard: true,
});
/*==================== TESTIMONIAL ====================*/
/*==================== SCROLL SECTIONS ACTIVE LINK ====================*/
// const sections = document.querySelectorAll("section[id]");
// function scrollActive() {
// const scrollY = window.pageYOffset;
// sections.forEach((current) => {
// const sectionHeight = current.offsetHeight;
// const sectionTop = current.offsetTop - 50;
// const sectionId = current.getAttribute("id");
// if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
// document.querySelector(".nav__menu a[href*=" + sectionId + "]").classList.add('.active-link');
// }else{
// document.querySelector(".nav__menu a[href*=" + sectionId + "]").classList.remove('.active-link')
// }
// });
// }
// window.addEventListener('scroll', scrollActive)
/*==================== CHANGE BACKGROUND HEADER ====================*/
/*==================== SHOW SCROLL UP ====================*/
function scrollUp() {
const scrollUp = document.getElementById('scroll-up');
if (this.scrollY >= 560) scrollUp.classList.add('show-scroll');
else scrollUp.classList.remove('show-scroll');
}
window.addEventListener('scroll', scrollUp);
/*==================== DARK LIGHT THEME ====================*/
const themeButton = document.getElementById('theme-button');
const darkTheme = 'dark-theme';
const iconTheme = 'uil-sun';
// previously selected topic (if user selected)
const selectedTheme = localStorage.getItem('selected-theme');
const selectedIcon = localStorage.getItem('selected-icon');
// we obtain the current theme that the interface has by validating the dark-them
const getCurrentTheme = () =>
document.body.classList.contains(darkTheme) ? 'dark' : 'light';
const getCurrentIcon = () =>
themeButton.classList.contains(iconTheme) ? 'uil-moon' : 'uil-sun';
// we validate if the user previously chose a topic
if (selectedTheme) {
// if the validation is fulfilled, we ask what the issue was to know if we activated
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](
darkTheme,
);
themeButton.classList[selectedIcon === 'uil-moon' ? 'add' : 'remove'](
iconTheme,
);
}
// activate / deactivate the theme manually with the button
themeButton.addEventListener('click', () => {
// add or remove the dark / icon theme
document.body.classList.toggle(darkTheme);
themeButton.classList.toggle(iconTheme);
// we save the theme and the current icon that the user chose
localStorage.setItem('selected-themee', getCurrentTheme());
localStorage.setItem('selected-icon', getCurrentIcon());
});
// ------ TYPICAL ------
var TxtType = function (el, toRotate, period) {
this.toRotate = toRotate;
this.el = el;
this.loopNum = 0;
this.period = parseInt(period, 10) || 2000;
this.txt = '';
this.tick();
this.isDeleting = false;
};
TxtType.prototype.tick = function () {
var i = this.loopNum % this.toRotate.length;
var fullTxt = this.toRotate[i];
if (this.isDeleting) {
this.txt = fullTxt.substring(0, this.txt.length - 1);
} else {
this.txt = fullTxt.substring(0, this.txt.length + 1);
}
this.el.innerHTML = '<span class="wrap">' + this.txt + '</span>';
var that = this;
var delta = 200 - Math.random() * 100;
if (this.isDeleting) {
delta /= 2;
}
if (!this.isDeleting && this.txt === fullTxt) {
delta = this.period;
this.isDeleting = true;
} else if (this.isDeleting && this.txt === '') {
this.isDeleting = false;
this.loopNum++;
delta = 500;
}
setTimeout(function () {
that.tick();
}, delta);
};
window.onload = function () {
var elements = document.getElementsByClassName('typewrite');
for (var i = 0; i < elements.length; i++) {
var toRotate = elements[i].getAttribute('data-type');
var period = elements[i].getAttribute('data-period');
if (toRotate) {
new TxtType(elements[i], JSON.parse(toRotate), period);
}
}
// INJECT CSS
var css = document.createElement('style');
css.type = 'text/css';
css.innerHTML = '.typewrite > .wrap { border-right: 0.08em solid #fff}';
document.body.appendChild(css);
};