-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
126 lines (107 loc) · 4.28 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
document.addEventListener('DOMContentLoaded', function () {
const sections = document.querySelectorAll('main > section');
const navLinks = document.querySelectorAll('.nav-links a');
const logo = document.querySelector('.logo');
const getStartedButton = document.getElementById('get-started-button');
function hideAllSections() {
sections.forEach(section => {
section.classList.add('hidden');
});
}
function showSection(id) {
hideAllSections();
const section = document.getElementById(id);
if (section) {
section.classList.remove('hidden');
}
}
navLinks.forEach(link => {
link.addEventListener('click', function (e) {
e.preventDefault();
const sectionId = this.getAttribute('href').substring(1);
showSection(sectionId);
});
});
logo.addEventListener('click', function (e) {
e.preventDefault();
showSection('home');
document.getElementById('about').classList.remove('hidden');
});
if (getStartedButton) {
getStartedButton.addEventListener('click', function (e) {
e.preventDefault();
showSection('login');
});
}
showSection('home');
document.getElementById('about').classList.remove('hidden');
const uploadForm = document.getElementById('upload-form');
if (uploadForm) {
uploadForm.addEventListener('submit', async function (e) {
e.preventDefault();
// console.log(e);
const formUploadData = new FormData();
const subjectName = document.getElementById('subject').value;
const courseCode = document.getElementById('course-code').value;
const examType = document.getElementById('exam-type').value;
const year = document.getElementById('year').value;
const semester = document.getElementById('semester').value;
const fileInput = document.getElementById('file').files[0];
const description = document.getElementById('description').value;
formUploadData.append('subject', subjectName);
formUploadData.append('course', courseCode);
formUploadData.append('examtype', examType);
formUploadData.append('year', year);
formUploadData.append('sem', semester);
formUploadData.append('file', fileInput);
formUploadData.append('desc', description);
// for (let [key, value] of formUploadData.entries()) {
// console.log(key, value);
// }
try {
const response = await fetch('http://localhost:3000/api/files', {
method: 'POST',
body: formUploadData
});
if (response.ok) {
alert('File uploaded successfully!')
// alert(response)
} else {
alert('File uploaded failed!')
}
} catch (err) {
console.log('ERROR SOMEWHER :', err)
}
// alert('File uploaded successfully!');
});
}
const loginForm = document.getElementById('login-form');
if (loginForm) {
loginForm.addEventListener('submit', function (e) {
e.preventDefault();
alert('Login successful!');
});
}
const searchButton = document.getElementById('search-button');
const searchInput = document.getElementById('search-input');
if (searchButton && searchInput) {
searchButton.addEventListener('click', function () {
const searchTerm = searchInput.value.toLowerCase();
alert(`Searching for: ${searchTerm}`);
});
}
const menuBtn = document.querySelector('.menu-btn');
const navLinksContainer = document.querySelector('.nav-links');
if (menuBtn && navLinksContainer) {
menuBtn.addEventListener('click', function () {
navLinksContainer.classList.toggle('active');
});
}
navLinks.forEach(link => {
link.addEventListener('click', function () {
if (navLinksContainer.classList.contains('active')) {
navLinksContainer.classList.remove('active');
}
});
});
});