ffcc9393's picture
Redesign my website
b97f52c verified
Raw History Blame Contribute Delete
2.86 kB
// Shared JavaScript across all pages
console.log('Network Analytics Dashboard loaded');
// Initialize tooltips and interactive elements
document.addEventListener('DOMContentLoaded', function() {
// Add loading states to buttons
const buttons = document.querySelectorAll('button');
buttons.forEach(button => {
button.addEventListener('click', function() {
if (this.textContent.includes('Real-time')) {
// Simulate real-time data loading
this.classList.add('loading');
setTimeout(() => {
this.classList.remove('loading');
// Update active state
buttons.forEach(btn => btn.classList.remove('bg-primary', 'text-white'));
buttons.forEach(btn => btn.classList.add('bg-gray-200', 'text-gray-700'));
this.classList.remove('bg-gray-200', 'text-gray-700');
this.classList.add('bg-primary', 'text-white');
}, 500);
}
});
});
// Add smooth transitions for chart containers
const chartContainers = document.querySelectorAll('.bg-gray-50');
chartContainers.forEach(container => {
container.classList.add('transition-all', 'duration-300');
});
// Initialize live data updates
function updateLiveData() {
const liveIndicators = document.querySelectorAll('.pulse-live');
liveIndicators.forEach(indicator => {
// Simulate data update
indicator.style.opacity = Math.random() * 0.3 + 0.7;
});
}
// Update data every 5 seconds
setInterval(updateLiveData, 5000);
// Add scroll animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fade-in');
}
}, observerOptions);
// Observe all feature cards and stats
document.querySelectorAll('.bg-white').forEach(card => {
observer.observe(card);
});
});
// Utility functions
const Utils = {
formatNumber: (num) => {
return new Intl.NumberFormat().format(num);
},
formatPercentage: (num) => {
return new Intl.NumberFormat('en-US', {
style: 'percent',
minimumFractionDigits: 1,
maximumFractionDigits: 1
}).format(num / 100);
},
formatBytes: (bytes) => {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
};