File size: 3,178 Bytes
65bcc33 | 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 | document.addEventListener('DOMContentLoaded', function() {
// Mobile menu toggle
document.addEventListener('click', function(e) {
if (e.target.closest('.mobile-menu-btn')) {
const navbar = document.querySelector('custom-navbar').shadowRoot.querySelector('.nav-links');
navbar.style.display = navbar.style.display === 'flex' ? 'none' : 'flex';
}
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Live update notification
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(registration => {
registration.addEventListener('updatefound', () => {
const newWorker = registration.installing;
newWorker.addEventListener('statechange', () => {
if (newWorker.state === 'installed') {
showUpdateNotification();
}
});
});
});
}
// Feature card animations
const featureCards = document.querySelectorAll('.feature-card');
featureCards.forEach((card, index) => {
card.style.animationDelay = `${index * 100}ms`;
card.classList.add('animate-fade-in');
});
// Real-time dashboard updates (example)
function updateDashboardStats() {
fetch('https://api.vanityvault.example/stats')
.then(response => response.json())
.then(data => {
// Update stats on dashboard page
if (document.getElementById('dashboard-stats')) {
document.getElementById('total-products').textContent = data.products;
document.getElementById('low-stock').textContent = data.lowStock;
document.getElementById('monthly-spend').textContent = `$${data.monthlySpend}`;
}
});
}
// Check for updates every 5 minutes
setInterval(updateDashboardStats, 300000);
updateDashboardStats();
});
function showUpdateNotification() {
const notification = document.createElement('div');
notification.className = 'fixed bottom-4 right-4 bg-purple-600 text-white px-4 py-3 rounded-lg shadow-lg z-50';
notification.innerHTML = `
<p class="mb-2">A new version of VanityVault is available!</p>
<button onclick="window.location.reload()" class="text-sm underline">Refresh to update</button>
`;
document.body.appendChild(notification);
setTimeout(() => notification.remove(), 10000);
}
// User role management
function checkUserRole() {
const role = localStorage.getItem('userRole') || 'owner';
if (role === 'employee') {
document.querySelectorAll('.admin-only').forEach(el => el.style.display = 'none');
}
}
// Initialize role check on dashboard pages
if (window.location.pathname.includes('dashboard')) {
checkUserRole();
} |