File size: 2,249 Bytes
e1d7fc6 | 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 | // Handle role-based UI elements
document.addEventListener('DOMContentLoaded', function() {
// Get user role from localStorage (simulated)
const userRole = localStorage.getItem('userRole') || 'teacher';
// Hide/show elements based on role
const adminElements = document.querySelectorAll('.admin-only');
const teacherElements = document.querySelectorAll('.teacher-only');
const studentElements = document.querySelectorAll('.student-only');
if (userRole === 'admin') {
adminElements.forEach(el => el.style.display = 'block');
teacherElements.forEach(el => el.style.display = 'none');
studentElements.forEach(el => el.style.display = 'none');
} else if (userRole === 'teacher') {
adminElements.forEach(el => el.style.display = 'none');
teacherElements.forEach(el => el.style.display = 'block');
studentElements.forEach(el => el.style.display = 'none');
} else {
adminElements.forEach(el => el.style.display = 'none');
teacherElements.forEach(el => el.style.display = 'none');
studentElements.forEach(el => el.style.display = 'block');
}
// Mobile menu toggle
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', function() {
const expanded = this.getAttribute('aria-expanded') === 'true';
this.setAttribute('aria-expanded', !expanded);
mobileMenu.classList.toggle('hidden');
});
}
});
// Calculate age from birth date
function calculateAge(birthDate) {
const today = new Date();
const birth = new Date(birthDate);
let age = today.getFullYear() - birth.getFullYear();
const monthDiff = today.getMonth() - birth.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
age--;
}
return age;
}
// Simulate sending WhatsApp message
function sendWhatsAppMessage(phone, message) {
const encodedMessage = encodeURIComponent(message);
window.open(`https://wa.me/${phone}?text=${encodedMessage}`, '_blank');
} |