-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
72 lines (63 loc) · 2.38 KB
/
main.js
File metadata and controls
72 lines (63 loc) · 2.38 KB
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
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-app.js";
import { getDatabase, ref, onValue } from "https://www.gstatic.com/firebasejs/10.8.0/firebase-database.js";
import firebaseConfig from "./firebase-config.js";
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
// DOM Elements
const servicesContainer = document.querySelector('.services-grid');
/**
* Fetch and display services from Realtime Database
*/
function loadServices() {
const servicesRef = ref(db, 'services');
onValue(servicesRef, (snapshot) => {
const data = snapshot.val();
if (data) {
// If we have data in RTDB, we could dynamically update the UI
console.log("Services loaded from Firebase:", data);
// This can be expanded to render service cards dynamically
} else {
console.log("No services found in database, using static content.");
}
});
}
// Theme Toggle Logic
const themeToggle = document.getElementById('themeToggle');
const body = document.body;
function initTheme() {
const savedTheme = localStorage.getItem('theme') || 'light'; // Light by default as requested
body.setAttribute('data-theme', savedTheme);
}
themeToggle.addEventListener('click', () => {
const currentTheme = body.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
body.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
});
// Interactivity
document.addEventListener('DOMContentLoaded', () => {
initTheme();
loadServices();
// Smooth scroll for nav links
document.querySelectorAll('nav a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
document.querySelector(targetId).scrollIntoView({
behavior: 'smooth'
});
});
});
// Navbar scroll effect
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.padding = '0.7rem 0';
navbar.style.background = 'var(--nav-bg)';
} else {
navbar.style.padding = '1.5rem 0';
navbar.style.background = 'var(--nav-bg)';
}
});
});