Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
147 lines (126 loc) · 4.91 KB
/
Copy pathscript.js
File metadata and controls
147 lines (126 loc) · 4.91 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.5/firebase-app.js";
import {
getDatabase,
ref,
onValue,
runTransaction
} from "https://www.gstatic.com/firebasejs/10.12.5/firebase-database.js";
document.addEventListener("DOMContentLoaded", () => {
console.log("Photography portfolio loaded.");
/* MOBILE NAVIGATION */
const navbar = document.querySelector(".navbar");
const navToggle = document.querySelector(".nav-toggle");
const navLinks = document.querySelectorAll("#primary-nav a");
if (navbar && navToggle) {
navToggle.addEventListener("click", () => {
const isOpen = navbar.classList.toggle("nav-open");
navToggle.setAttribute("aria-expanded", String(isOpen));
navToggle.setAttribute("aria-label", isOpen ? "Close navigation" : "Open navigation");
});
navLinks.forEach(link => {
link.addEventListener("click", () => {
navbar.classList.remove("nav-open");
navToggle.setAttribute("aria-expanded", "false");
navToggle.setAttribute("aria-label", "Open navigation");
});
});
}
/* CARD CURSOR */
const cards = document.querySelectorAll(".photo-card, .place-card");
cards.forEach(card => {
card.addEventListener("mouseenter", () => {
card.style.cursor = "pointer";
});
});
/* FEATURED CINEMATIC REEL */
const reel = document.getElementById("cinematicReel");
if (reel && !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
const frames = [
"yosemite_revised_1.jpg", "yellowstone/yellowstone-4931.jpg",
"guilin/guilin-da-mian-shan-hero.jpg", "spain-portugal/spain-portugal-hero-casa-batllo-courtyard.jpg",
"yellowstone/yellowstone-5305-2.jpg", "JNP1.JPG", "tahoe1.JPG", "Tibet1.jpg",
"yunnan1.jpg", "cruise-lighthouse.jpg"
].map(path => `https://meclues37-photo-1447476321.cos.ap-hongkong.myqcloud.com/images/${path}`);
const image = reel.querySelector(".cinematic-reel__image");
const count = reel.querySelector(".cinematic-reel__count b");
frames.slice(1).forEach(src => { const preload = new Image(); preload.src = src; });
let current = 0;
let paused = false;
reel.addEventListener("mouseenter", () => { paused = true; });
reel.addEventListener("mouseleave", () => { paused = false; });
window.setInterval(() => {
if (paused) return;
reel.classList.add("is-transitioning");
window.setTimeout(() => {
current = (current + 1) % frames.length;
image.src = frames[current];
count.textContent = String(current + 1).padStart(2, "0");
reel.classList.remove("is-transitioning");
}, 750);
}, 7000);
}
/* FIREBASE LIKE BUTTON */
const firebaseConfig = {
apiKey: "AIzaSyDxz6MLWVbtuCPnLPDA1V1X9UB-YMb1jx0",
authDomain: "log1-a334f.firebaseapp.com",
databaseURL: "https://log1-a334f-default-rtdb.firebaseio.com",
projectId: "log1-a334f",
storageBucket: "log1-a334f.firebasestorage.app",
messagingSenderId: "387877176052",
appId: "1:387877176052:web:e1b332e96487d59ed8d4a1"
};
const app = initializeApp(firebaseConfig);
const db = getDatabase(app);
const likeBtn = document.getElementById("likeBtn");
const likeCount = document.getElementById("likeCount");
if (likeBtn && likeCount) {
const likesRef = ref(db, "portfolioLikes/count");
onValue(likesRef, (snapshot) => {
likeCount.textContent = snapshot.val() || 0;
});
if (localStorage.getItem("likedPortfolio")) {
likeBtn.classList.add("liked");
likeBtn.disabled = true;
}
likeBtn.addEventListener("click", () => {
if (localStorage.getItem("likedPortfolio")) return;
runTransaction(likesRef, (count) => {
return (count || 0) + 1;
});
localStorage.setItem("likedPortfolio", "true");
likeBtn.classList.add("liked");
likeBtn.disabled = true;
});
}
/* LIGHTBOX */
const images = document.querySelectorAll(
".photo-section img, .photo-grid-horizontal img, .photo-grid-vertical img, .cancun-gallery img, .loscabos-gallery img"
);
const lightbox = document.getElementById("lightbox");
const lightboxImg = document.getElementById("lightboxImg");
const closeBtn = document.querySelector(".lightbox-close");
if (lightbox && lightboxImg && closeBtn) {
images.forEach(img => {
img.addEventListener("click", (event) => {
event.preventDefault();
event.stopPropagation();
lightbox.style.display = "flex";
lightboxImg.src = img.src;
lightboxImg.alt = img.alt || "Full size photo";
});
});
closeBtn.addEventListener("click", () => {
lightbox.style.display = "none";
});
lightbox.addEventListener("click", (event) => {
if (event.target !== lightboxImg) {
lightbox.style.display = "none";
}
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
lightbox.style.display = "none";
}
});
}
});