-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
153 lines (124 loc) · 4.46 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
/* eslint-disable no-plusplus */
// import from card.js
import projects from './card.js';
// nav bar
const mobileMenu = document.querySelector('nav .mobile-menu');
const mobileClose = document.querySelector('nav .mobile-close');
const mobileNavigation = document.querySelector('.mobile-navigation');
// nav bar display
const navLinkList = document.querySelectorAll('.nav-link');
function display() {
mobileNavigation.classList.toggle('active');
mobileClose.classList.toggle('active');
}
for (let index = 0; index < navLinkList.length; index++) {
const element = navLinkList[index];
element.addEventListener('click', display);
}
mobileMenu.addEventListener('click', display);
mobileClose.addEventListener('click', display);
// card
const projectsContainer = document.querySelector('.works-section');
projects.forEach((project) => {
projectsContainer.innerHTML += `<article class="card">
<div class="card-image">
<img src="${project.image}" alt="Portfolio" >
</div>
<div class="card-content">
<h2 class="card-title">${project.title}</h2>
<ul class="card-info">
<li>Microverse</li>
<li>2023</li>
</ul>
<P class="card-description">
${project.description}
</P>
<ul class="card-tags">
<li>html</li>
<li>css</li>
<li>javaScript</li>
</ul>
<button class="primary-button extend-project card-button" id="${project.id}" type="button">
see Project
</button>
</div>
</article>
`;
});
// PROJECT POPUP MENU
// call class .main-popup-container
const popupMainContainer = document.querySelector('.main-popup-container');
// call class of extend-project added dynamically in js for all project
const extendProjectBtns = document.querySelectorAll('.extend-project');
// call for class close-icon-wrapper for icon image in htm
const closePopUp = document.querySelector('.close-icon-wrapper');
// Fonction to remove opupMainContainer on the body when close-icon-wrapper is clicked
function closePopUpFunc() {
popupMainContainer.classList.remove('open');
}
// function to add class list
function showPopUp(event) {
const projectId = event.target.id;
const project = projects.find((project) => project.id === Number(projectId));
const popImg = document.querySelector('.pop-img');
const popPar = document.querySelector('.popup-card-description');
const poPitle = document.querySelector('.main-popup-container .card-title');
const sourcelink = document.querySelector('.sourcelink');
const livelink = document.querySelector('.livelink');
poPitle.innerHTML = project.title;
popPar.innerHTML = project.description;
popImg.src = project.image;
sourcelink.innerHTML = `
<a id="source" href="${project.source}" target="_blank">Source code <img
src="images/Icon.png"></a>
`
livelink.innerHTML = `
<a id= "live" href="${project.live}" target="_blank">See live <img
src="images/git.png"></a>
`
popupMainContainer.classList.add('open');
}
// function to close addEventListener
closePopUp.addEventListener('click', closePopUpFunc);
// console.log('btns', extendProjectBtns);
// to access all button
for (let index = 0; index < extendProjectBtns.length; index++) {
const element = extendProjectBtns[index];
element.addEventListener('click', showPopUp);
}
// client side form validation form
const form = document.querySelector('#register');
const email = document.querySelector('#email');
const errorMessage = document.querySelector('#error-message');
const name = document.querySelector('#name');
const feedback = document.querySelector('#message');
form.addEventListener('submit', (event) => {
if (email.value !== email.value.toLowerCase()) {
errorMessage.style.visibility = 'visible';
event.preventDefault();
}
});
// storing data in local Storage
function visitorData() {
const visitor = {
Name: name.value,
Email: email.value,
Message: feedback.value,
};
// store the object
localStorage.setItem('visitor', JSON.stringify(visitor));
}
name.addEventListener('focusout', visitorData);
email.addEventListener('focusout', visitorData);
feedback.addEventListener('focusout', visitorData);
// retrieve data from local storage
const visitorDataExist = JSON.parse(localStorage.getItem('visitor'));
if (visitorDataExist) {
name.value = visitorDataExist.Name;
email.value = visitorDataExist.Email;
feedback.value = visitorDataExist.Message;
}
// live and source
// const source = document.getElementById('.source');
// const live = document.getElementById('.live');
// source.href = "somelink url"