File size: 4,456 Bytes
5cbad2a 0347414 5cbad2a 0347414 5cbad2a 0347414 5cbad2a 0347414 5cbad2a 3c7f0b3 5cbad2a 3c7f0b3 | 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
// Authentication functionality
function checkAuth() {
return localStorage.getItem('userToken') !== null;
}
function handleLogin(event) {
event.preventDefault();
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
// In a real app, this would call an API
if ((username === 'admin' && password === 'pp888') ||
(username === 'user' && password === 'user123')) {
const token = btoa(`${username}:${Date.now()}`);
localStorage.setItem('userToken', token);
localStorage.setItem('username', username);
if (username === 'admin') {
window.location.href = '/admin';
} else {
window.location.href = '/';
}
} else {
alert('Invalid credentials');
}
}
function handleLogout() {
localStorage.removeItem('userToken');
localStorage.removeItem('username');
window.location.href = '/login.html';
}
// Admin features
function enableEditMode() {
if (!checkAuth()) return;
// Enable logo editing
const logo = document.querySelector('custom-navbar').shadowRoot.getElementById('logo-image');
logo.style.cursor = 'pointer';
logo.addEventListener('click', () => {
const newUrl = prompt('Enter new logo URL:', logo.src);
if (newUrl) {
logo.src = newUrl;
// In real app, save to backend here
}
});
// Enable footer editing
const footer = document.querySelector('custom-footer');
if (footer) {
footer.shadowRoot.querySelectorAll('.edit-btn').forEach(btn => {
btn.style.display = 'inline-block';
btn.addEventListener('click', (e) => {
const section = e.target.dataset.section;
const column = e.target.closest('.footer-column');
const content = column.innerHTML;
const newContent = prompt('Edit content (HTML):', content);
if (newContent) {
column.innerHTML = newContent;
// In real app, save to backend here
}
});
});
}
}
document.addEventListener('DOMContentLoaded', function() {
// Handle login form if exists
const loginForm = document.getElementById('loginForm');
if (loginForm) {
loginForm.addEventListener('submit', handleLogin);
}
// Enable admin features if authenticated
if (checkAuth()) {
enableEditMode();
}
// Initialize services carousel
const serviceCarousel = document.getElementById('service-carousel');
if (serviceCarousel) {
let currentIndex = 0;
const services = document.querySelectorAll('.service-item');
const totalServices = services.length;
function showService(index) {
services.forEach((service, i) => {
service.classList.toggle('hidden', i !== index);
service.classList.toggle('block', i === index);
});
}
document.getElementById('next-service').addEventListener('click', () => {
currentIndex = (currentIndex + 1) % totalServices;
showService(currentIndex);
});
document.getElementById('prev-service').addEventListener('click', () => {
currentIndex = (currentIndex - 1 + totalServices) % totalServices;
showService(currentIndex);
});
showService(0);
}
// Booking modal toggle
const bookingModal = document.getElementById('booking-modal');
const openBookingBtn = document.getElementById('open-booking');
const closeBookingBtn = document.getElementById('close-booking');
if (openBookingBtn && bookingModal) {
openBookingBtn.addEventListener('click', () => {
bookingModal.classList.remove('hidden');
document.body.classList.add('overflow-hidden');
});
closeBookingBtn.addEventListener('click', () => {
bookingModal.classList.add('hidden');
document.body.classList.remove('overflow-hidden');
});
}
// Initialize calendar
const calendarEl = document.getElementById('calendar');
if (calendarEl) {
// This would be replaced with actual calendar initialization
// For example, using FullCalendar.js in a real implementation
console.log('Calendar would be initialized here');
}
}); |