forked from Varshitha713/CodeCanvas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
334 lines (292 loc) · 13.9 KB
/
script.js
File metadata and controls
334 lines (292 loc) · 13.9 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
//this data in future contribution should be done using firebase
const sampleProjects = [
{
id: 1,
title: 'Analog Clock Web App',
description: 'A beautifully designed analog clock that updates in real-time using vanilla JavaScript, HTML, and CSS. Perfect for understanding basic DOM manipulation and CSS transformations.',
repoUrl: 'https://github.com/Varshitha713/analog-clock-web-app',
demoUrl: 'https://varshitha713.github.io/analog-clock-web-app/',
difficulty: 'beginner',
upvotes: 15,
hasDemo: true,
hasReadme: true,
previewImage: 'https://github.com/user-attachments/assets/091946a3-d98d-42dc-a22a-90eaefc8b1b1',
tags: ['JavaScript', 'CSS', 'HTML', 'DOM']
},
{
id: 2,
title: 'Weather Dashboard',
description: 'A responsive weather application with beautiful animations and detailed forecasts. Features location-based weather data and interactive charts.',
repoUrl: 'https://github.com/example/weather-dashboard',
demoUrl: 'https://example.github.io/weather-dashboard/',
difficulty: 'Intermediate',
upvotes: 28,
hasDemo: true,
hasReadme: true,
previewImage: null,
tags: ['React', 'API', 'Charts', 'Responsive']
},
{
id: 3,
title: 'Task Management App',
description: 'A full-featured task management application with drag-and-drop functionality, real-time updates, and team collaboration features.',
repoUrl: 'https://github.com/example/task-manager',
demoUrl: null,
difficulty: 'advanced',
upvotes: 42,
hasDemo: false,
hasReadme: true,
previewImage: null,
tags: ['Vue.js', 'Drag & Drop', 'WebSocket', 'PWA']
},
{
id: 4,
title: 'Portfolio Website',
description: 'A modern, responsive portfolio website with smooth animations, dark mode toggle, and optimized performance. Great starting point for personal branding.',
repoUrl: 'https://github.com/example/portfolio',
demoUrl: 'https://example.github.io/portfolio/',
difficulty: 'beginner',
upvotes: 31,
hasDemo: true,
hasReadme: true,
previewImage: null,
tags: ['HTML', 'CSS', 'JavaScript', 'Responsive']
},
{
id: 5,
title: 'Expense Tracker App',
description: 'A simple and intuitive expense tracker app to monitor daily spending, manage budgets, and gain financial insights.',
repoUrl: 'https://github.com/DineshPabboju/Expense-Tracker-App',
demoUrl: 'https://expense-tracker-app-04.netlify.app/',
difficulty: 'Intermediate',
upvotes: 21,
hasDemo: true,
hasReadme: false,
previewImage: 'assets/Expense-Tracker-Preview.png',
tags: ['HTML', 'CSS', 'JavaScript', 'Responsive']
},
{
id: 6,
title: "IMDb Clone",
description: 'A responsive IMDb clone showcasing popular movies with detailed info using TMDb API and modern frontend technologies.',
repoUrl: "https://github.com/Jils31/IMDB-clone",
demoUrl: "https://imdb-clone-seven-virid.vercel.app/",
difficulty: "intermediate",
upvotes: 21,
hasDemo: true,
hasReadme: true,
previewImage: "assets/image.png",
tags: ["REACT", "Tailwind CSS", "Responsive", "React-Router DOM"],
},
];
// Store the current projects array
let currentProjects = [...sampleProjects];
// DOM elements
const projectsContainer = document.getElementById('projects-container');
const loadingElement = document.getElementById('loading');
const emptyStateElement = document.getElementById('empty-state');
const difficultyFilter = document.getElementById('difficulty');
const hasDemoFilter = document.getElementById('has-demo');
const hasReadmeFilter = document.getElementById('has-readme');
const applyFiltersBtn = document.getElementById('apply-filters');
const resetFiltersBtn = document.getElementById('reset-filters');
const searchInput = document.getElementById('search-input');
const clearSearchBtn = document.getElementById('clear-search');
// Initialize the app
function init() {
setTimeout(() => {
hideLoading();
renderProjects(currentProjects);
setupEventListeners();
}, 1000); // Simulate loading time
}
// Hide loading spinner
function hideLoading() {
loadingElement.style.display = 'none';
projectsContainer.style.display = 'grid';
}
// Setup event listeners
function setupEventListeners() {
applyFiltersBtn.addEventListener('click', applyFilters);
resetFiltersBtn.addEventListener('click', resetFilters);
// Search functionality
searchInput.addEventListener('input', handleSearch);
clearSearchBtn.addEventListener('click', clearSearch);
// Smooth scroll for explore button
document.querySelector('a[href="#projects"]').addEventListener('click', (e) => {
e.preventDefault();
document.getElementById('projects').scrollIntoView({
behavior: 'smooth'
});
});
}
// Render projects
function renderProjects(projects) {
if (projects.length === 0) {
projectsContainer.style.display = 'none';
emptyStateElement.style.display = 'block';
return;
}
emptyStateElement.style.display = 'none';
projectsContainer.style.display = 'grid';
projectsContainer.innerHTML = projects.map(project => `
<div class="project-card">
${project.previewImage
? `<img src="${project.previewImage}" alt="${project.title}" class="project-image"
onerror="this.outerHTML='<div class=\\'project-placeholder\\'>No Preview Available</div>'">`
: '<div class="project-placeholder">No Preview Available</div>'
}
<div class="project-header">
<h3 class="project-title">${project.title}</h3>
<a href="${project.repoUrl}" target="_blank" rel="noopener noreferrer" class="repo-link">
<i class="fab fa-github"></i>
</a>
</div>
<span class="difficulty-badge difficulty-${project.difficulty}">
${project.difficulty.charAt(0).toUpperCase() + project.difficulty.slice(1)}
</span>
<p class="project-description">${project.description}</p>
<div class="project-meta">
${project.hasDemo
? '<i class="fas fa-external-link-alt meta-icon"></i> Live Demo Available'
: '<i class="fas fa-code meta-icon"></i> Code Only'
}
${project.hasReadme
? ' • <i class="fas fa-file-alt meta-icon"></i> README Included'
: ' • <i class="fas fa-exclamation-triangle meta-icon"></i> No README'
}
</div>
<div class="upvote-section">
${project.hasDemo && project.demoUrl
? `<a href="${project.demoUrl}" target="_blank" class="btn-primary" style="text-decoration: none; padding: 0.5rem 1rem; font-size: 0.875rem;">
<i class="fas fa-external-link-alt"></i> View Demo
</a>`
: '<span></span>'
}
<button class="upvote-btn" onclick="handleUpvote(${project.id})">
<i class="fas fa-arrow-up"></i>
<span>${project.upvotes}</span>
</button>
</div>
</div>
`).join('');
}
// Handle upvote
function handleUpvote(projectId) {
const project = currentProjects.find(p => p.id === projectId);
if (project) {
project.upvotes++;
// Re-render projects to update the upvote count
renderProjects(applyCurrentFilters());
// Add visual feedback
const button = event.target.closest('.upvote-btn');
button.style.transform = 'scale(1.1)';
setTimeout(() => {
button.style.transform = 'scale(1)';
}, 150);
}
}
// Apply filters
function applyFilters() {
const filteredProjects = applyCurrentFilters();
renderProjects(filteredProjects);
}
// Apply current filter settings
function applyCurrentFilters() {
let filtered = [...sampleProjects];
const difficulty = difficultyFilter.value;
const needsDemo = hasDemoFilter.checked;
const needsReadme = hasReadmeFilter.checked;
const searchTerm = searchInput.value.toLowerCase().trim();
// Apply search filter
if (searchTerm) {
filtered = filtered.filter(project => {
const titleMatch = project.title.toLowerCase().includes(searchTerm);
const descriptionMatch = project.description.toLowerCase().includes(searchTerm);
const tagsMatch = project.tags.some(tag => tag.toLowerCase().includes(searchTerm));
return titleMatch || descriptionMatch || tagsMatch;
});
}
if (difficulty !== 'all') {
filtered = filtered.filter(p => p.difficulty === difficulty);
}
if (needsDemo) {
filtered = filtered.filter(p => p.hasDemo);
}
if (needsReadme) {
filtered = filtered.filter(p => p.hasReadme);
}
return filtered;
}
// Handle search input with debounce
let searchTimeout;
function handleSearch() {
const searchTerm = searchInput.value.trim();
// Show/hide clear button
if (searchTerm) {
clearSearchBtn.style.display = 'flex';
} else {
clearSearchBtn.style.display = 'none';
}
// Clear previous timeout
clearTimeout(searchTimeout);
// Debounce search to improve performance
searchTimeout = setTimeout(() => {
const filteredProjects = applyCurrentFilters();
renderProjects(filteredProjects);
}, 300);
}
// Clear search
function clearSearch() {
searchInput.value = '';
clearSearchBtn.style.display = 'none';
const filteredProjects = applyCurrentFilters();
renderProjects(filteredProjects);
}
// Reset filters
function resetFilters() {
difficultyFilter.value = 'all';
hasDemoFilter.checked = false;
hasReadmeFilter.checked = false;
searchInput.value = '';
clearSearchBtn.style.display = 'none';
renderProjects(sampleProjects);
}
// Make handleUpvote globally available
window.handleUpvote = handleUpvote;
// Start the app
document.addEventListener('DOMContentLoaded', init);
function validateForm() {
const name = document.getElementById("name").value.trim();
const email = document.getElementById("email").value.trim();
const message = document.getElementById("message").value.trim();
if (!name || !email || !message) {
alert("Please fill in all fields.");
return false;
}
const emailPattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/;
if (!email.match(emailPattern)) {
alert("Please enter a valid email.");
return false;
}
document.getElementById("form-status").style.display = "block";
return false; // Prevent actual submission
}
const toggle = document.getElementById('darkModeToggle');
const body = document.body;
const icon = document.getElementById('themeIcon');
// Load preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
body.classList.add('dark-theme');
icon.textContent = '☀️'; // Sun in dark mode
} else {
icon.textContent = '🌙'; // Moon in light mode
}
toggle.addEventListener('click', () => {
body.classList.toggle('dark-theme');
const theme = body.classList.contains('dark-theme') ? 'dark' : 'light';
localStorage.setItem('theme', theme);
// Update icon
icon.textContent = theme === 'dark' ? '☀️' : '🌙';
});