-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
143 lines (125 loc) · 5.38 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
import projects from './data.js';
const menuToggler = document.getElementById('toggle');
const navMenu = document.getElementById('mobile-floating-nav');
const closeBtn = document.getElementById('menu-close-btn');
let navItems = document.getElementsByClassName('mob-nav-item');
navItems = Array.prototype.slice.call(navItems);
const portfolioWrapper = document.querySelector('.portfoilio-wrapper');
const popupContainer = document.querySelector('.popup-container');
const popupBackground = document.getElementById('popup-background');
let popupBtns;
const btnId = [];
menuToggler.addEventListener('click', () => {
navMenu.style.left = '0';
});
closeBtn.addEventListener('click', () => {
navMenu.style.left = '-100%';
});
navItems.forEach((item) => {
item.addEventListener('click', () => {
navMenu.style.left = '-100%';
});
});
window.addEventListener('DOMContentLoaded', () => {
displayProjects(projects);
popupBtns = document.querySelectorAll('.popupBtn');
popupBtns.forEach((btn) => {
btn.addEventListener('click', (e) => {
if (btnId.includes(parseInt(e.target.dataset.id))) {
const projectIndex = projects[parseInt(e.target.dataset.id) - 1];
popupContainer.innerHTML = `
<div data-id=${projectIndex.id}>
<div class="popup-title">
<div class="popup-info">
<h2 class="project-name">${projectIndex.projectName}</h2>
<p class="job">
${projectIndex.projectInfo}
</p>
</div>
<i class="uil uil-multiply close-btn" id = "popup-btn"></i>
</div>
<img src="${projectIndex.projectimg}" alt="popup project img" class="popimg">
<div class="pop-text">
<p class="articel-context-popup">
${projectIndex.porjectDetail}
</p>
<div class="btn-popup">
<ul class="btns">
<li class="mini button">${projectIndex.techpopup[0]}</li>
<li class="mini button desktop">${projectIndex.techpopup[1]}</li>
<li class="mini button">${projectIndex.techpopup[2]}</li>
<li class="mini button">${projectIndex.techpopup[3]}</li>
<li class="mini button">${projectIndex.techpopup[4]}</li>
<li class="mini button">${projectIndex.techpopup[5]}</li>
</ul>
<button class="btn"><a href="https://soesandarwin2201.github.io/portfolio-website-soesandarwin2201.github.io/"> ${projectIndex.popupBtn1} <img src="./images/Icon.svg" alt="live icon"></a>
</button>
<button class="btn"><a href="https://github.com/soesandarwin2201"> ${projectIndex.popupBtn2} <img src="./images/Vector (2).svg" alt="github icon"> </a></button>
</div>
</div>
</div>
`;
popupBackground.style.transform = 'translateX(0)';
}
const popupBtn = document.getElementById('popup-btn');
popupBtn.addEventListener('click', () => {
popupBackground.style.transform = 'translateX(-100%)';
});
});
});
});
function displayProjects(projectItems) {
let displayProject = projectItems.map((project) => {
btnId.push(project.id);
return `<article class="flexbox order-1">
<img class="portfoilio-img desktop" src="${project.projectimg}" alt="project img">
<img class="portfoilio-img mobile" src="${project.projectimg}" alt="project2 img">
<div class="article-text">
<h2 class="project-name">${project.projectName}</h2>
<p class="job">
${project.projectInfo}
</p>
<p class="articel-context">
${project.porjectDetail}
</p>
<ul class="btns">
<li class="mini button">${project.tech[0]}</li>
<li class="mini button">${project.tech[1]}</li>
<li class="mini button">${project.tech[2]}</li>
</ul>
<button data-id=${project.id} class="btn popupBtn">${project.projectBtn}</button>
</div>
</article>`;
});
displayProject = displayProject.join('');
portfolioWrapper.innerHTML = displayProject;
}
const form = document.getElementsByTagName('form')[0];
const email = document.getElementById('email');
const errorContainer = document.getElementById('error-message');
form.addEventListener('submit', (e) => {
if (form.elements.email.value.toLowerCase() === form.elements.email.value) {
form.submit();
} else {
e.preventDefault();
const message = document.createElement('p');
message.innerText = 'Your Email need to be in Lowercase.';
errorContainer.append(message);
errorContainer.style.opacity = 1;
}
});
const name = document.getElementById('name');
const message = document.getElementById('comment');
form.addEventListener('input', () => {
const formData = {
userName: form.elements.name.value,
userEmail: form.elements.email.value,
userMessage: form.elements.comment.value,
};
localStorage.setItem('UserStoreData', JSON.stringify(formData));
console.log(form.elements.name.value);
});
const getData = JSON.parse(localStorage.getItem('formData'));
form.elements.name.value = getData.userName;
form.elements.email.value = getData.userEmail;
form.elements.comment.value = getData.userMessage;