File size: 3,644 Bytes
83faa89 | 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 | // Shared JavaScript across all pages
console.log('TimeTracker Pro - Work Hours Wizard loaded');
// Initialize app functionality
document.addEventListener('DOMContentLoaded', function() {
// Check for service worker support
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then(registration => console.log('SW registered'))
.catch(error => console.log('SW registration failed'));
}
// Handle mobile menu toggle
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuBtn && mobileMenu) {
mobileMenuBtn.addEventListener('click', function() {
mobileMenu.classList.toggle('hidden');
});
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Theme handling
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', function() {
const html = document.documentElement;
if (html.classList.contains('dark')) {
html.classList.remove('dark');
localStorage.setItem('theme', 'light');
} else {
html.classList.add('dark');
localStorage.setItem('theme', 'dark');
}
feather.replace();
});
}
// Check for saved theme preference
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.documentElement.classList.add('dark');
}
// Add loading states to buttons
document.querySelectorAll('button, a').forEach(element => {
element.addEventListener('click', function() {
if (this.classList.contains('btn-loading')) {
this.classList.add('loading');
const originalText = this.innerHTML;
this.innerHTML = '<i data-feather="loader" class="animate-spin"></i> Loading...';
feather.replace();
// Reset after 2 seconds for demo
setTimeout(() => {
this.classList.remove('loading');
this.innerHTML = originalText;
feather.replace();
}, 2000);
}
});
});
});
// API functions for time tracking
const TimeTrackerAPI = {
// Simulate time tracking data
getCurrentTime: function() {
return new Date().toLocaleTimeString();
},
// Calculate work duration
calculateDuration: function(startTime, endTime) {
const start = new Date(`1970-01-01T${startTime}`);
const end = new Date(`1970-01-01T${endTime}`);
const diff = end - start;
const hours = Math.floor(diff / 3600000);
const minutes = Math.floor((diff % 3600000) / 60000);
return `${hours}h ${minutes}m`;
},
// Get today's summary
getTodaySummary: function() {
return {
totalHours: '8.5',
tasksCompleted: 12,
breaksTaken: 3,
overtime: '0.5'
};
}
};
// Export for use in other modules
window.TimeTrackerAPI = TimeTrackerAPI; |