boatable-mvp / script.js
productJ's picture
# 🚢 **BOATABLE MVP FRONTEND - COMPREHENSIVE OVERVIEW**
feb6f9e verified
Raw History Blame Contribute Delete
3.56 kB
// Toggle mobile menu
function toggleMobileMenu() {
const sidebar = document.querySelector('.sidebar-container');
sidebar.classList.toggle('active');
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Add any global initialization code here
// Example: Set up mobile menu toggle if it exists
const menuToggle = document.getElementById('menu-toggle');
if (menuToggle) {
menuToggle.addEventListener('click', toggleMobileMenu);
}
// Close sidebar when clicking outside on mobile
document.addEventListener('click', function(event) {
const sidebar = document.querySelector('.sidebar-container');
const menuButton = document.getElementById('menu-toggle');
if (sidebar &&
!sidebar.contains(event.target) &&
menuButton &&
!menuButton.contains(event.target) &&
window.innerWidth < 768) {
sidebar.classList.remove('active');
}
});
});
// Simple chart drawing function (placeholder)
function drawChart(canvasId, data) {
const canvas = document.getElementById(canvasId);
if (!canvas) return;
const ctx = canvas.getContext('2d');
const width = canvas.width;
const height = canvas.height;
// Clear canvas
ctx.clearRect(0, 0, width, height);
// Draw simple bar chart
const barWidth = width / data.length - 10;
const maxValue = Math.max(...data);
data.forEach((value, index) => {
const barHeight = (value / maxValue) * (height - 20);
const x = index * (barWidth + 10) + 10;
const y = height - barHeight - 10;
ctx.fillStyle = '#3b82f6';
ctx.fillRect(x, y, barWidth, barHeight);
ctx.fillStyle = '#1e293b';
ctx.font = '12px Inter, sans-serif';
ctx.textAlign = 'center';
ctx.fillText(value, x + barWidth/2, y - 5);
});
}
// Notification system
function showNotification(message, type = 'info') {
const notificationContainer = document.createElement('div');
notificationContainer.className = `fixed top-4 right-4 p-4 rounded-lg shadow-lg text-white z-50 fade-in ${
type === 'success' ? 'bg-green-500' :
type === 'error' ? 'bg-red-500' :
type === 'warning' ? 'bg-yellow-500' :
'bg-blue-500'
}`;
notificationContainer.textContent = message;
document.body.appendChild(notificationContainer);
setTimeout(() => {
notificationContainer.remove();
}, 3000);
}
// Form validation helper
function validateForm(formId, rules) {
const form = document.getElementById(formId);
if (!form) return false;
let isValid = true;
Object.keys(rules).forEach(fieldName => {
const field = form.querySelector(`[name="${fieldName}"]`);
const rule = rules[fieldName];
if (field && rule.required && !field.value.trim()) {
isValid = false;
field.classList.add('border-red-500');
const errorElement = document.createElement('p');
errorElement.className = 'text-red-500 text-sm mt-1';
errorElement.textContent = rule.message || 'This field is required';
field.parentNode.appendChild(errorElement);
}
});
return isValid;
}
// Export functions for global use
window.toggleMobileMenu = toggleMobileMenu;
window.drawChart = drawChart;
window.showNotification = showNotification;
window.validateForm = validateForm;