-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
331 lines (277 loc) · 10.8 KB
/
main.js
File metadata and controls
331 lines (277 loc) · 10.8 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
let tarotDataGlobal;
const tarotGrid = document.getElementById("tarotGrid");
// Only initialize modal components if they exist on the page
let tarotModal, tarotModalLabel, tarotModalBody;
const tarotModalElement = document.getElementById("tarotModal");
if (tarotModalElement) {
tarotModal = new bootstrap.Modal(tarotModalElement);
tarotModalLabel = document.getElementById("tarotModalLabel");
tarotModalBody = document.querySelector(".modal-body");
}
document.getElementById('year').textContent = new Date().getFullYear();
function scrollToHashSection() {
// Get the hash without the # symbol
const hash = window.location.hash.slice(1);
if (hash) {
// Find the element with matching ID
const element = document.getElementById(hash);
if (element) {
// Wait a brief moment for content to load
setTimeout(() => {
element.scrollIntoView({ behavior: 'smooth' });
}, 100);
}
}
}
function createCardElement(card) {
const cardContainer = document.createElement("div");
cardContainer.classList.add("tarot-card-container");
const cardElement = document.createElement("div");
cardElement.classList.add("tarot-card");
cardElement.style.backgroundImage = `url('cards/${card.img}')`;
cardElement.onclick = () => showCardDetails(card);
const cardTitle = document.createElement("div");
cardTitle.classList.add("card-name");
cardTitle.textContent = 'The High Priestess' == card.name ? 'High Priestess' : card.name;
cardContainer.appendChild(cardElement);
cardContainer.appendChild(cardTitle);
return cardContainer;
}
function createBadgeHTML(url, imgSrc, altText) {
if (!url) return '';
return `
<a href="${url}" target="_blank">
<img src="images/${imgSrc}" alt="${altText}" style="width: 36px; height: 36px; margin-left: 10px;">
</a>`;
}
function showCardDetails(card) {
if (!tarotModal || !tarotModalLabel || !tarotModalBody) return;
tarotModalLabel.textContent = card.name;
let modalContent = '';
if (card.yt_embed_url) {
modalContent += `
<div class="embed-responsive embed-responsive-16by9 mt-3" style="width:300px; height:168px; margin:auto;">
<iframe class="embed-responsive-item" src="${card.yt_embed_url}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen loading="lazy"></iframe>
</div>`;
}
modalContent += `
<div class="text-center"><img src="cards/${card.img}" alt="${card.name}" class="img-fluid" style="width:175px;height:300px;margin-top:1rem;"></div>
<p><strong>Card:</strong> ${card.name}</p>`;
if (card.album) {
const album = tarotDataGlobal.albums.find(a => a.title === card.album);
if (album) {
modalContent += `<p><strong>Album:</strong> ${card.album}`;
modalContent += createBadgeHTML(album.spotify, 'badge-spot.png', 'Spotify');
modalContent += createBadgeHTML(album.youtube, 'badge-yt.png', 'YouTube');
modalContent += createBadgeHTML(album.apple, 'badge-apl.png', 'Apple Music');
modalContent += createBadgeHTML(album.soundcloud, 'badge-sc.png', 'SoundCloud');
modalContent += `</p>`;
} else {
modalContent += `<p><strong>Album:</strong> ${card.album}</p>`;
}
}
if (card.keywords) {
modalContent += `<p><strong>Keywords:</strong> ${card.keywords.join(", ")}</p>`;
}
if (card.meanings) {
if (card.meanings.light) {
modalContent += `<p><strong>Light Meanings:</strong></p><ul><li>${card.meanings.light.join('</li><li>')}</li></ul>`;
}
if (card.meanings.shadow) {
modalContent += `<p><strong>Shadow Meanings:</strong></p><ul><li>${card.meanings.shadow.join('</li><li>')}</li></ul>`;
}
}
if (card.questions) {
modalContent += `<p><strong>Questions to Ask:</strong></p><ul>`;
card.questions.forEach(question => {
modalContent += `<li>${question}</li>`;
});
modalContent += `</ul>`;
}
if (card.archetype) {
modalContent += `<p><strong>Archetype:</strong> ${card.archetype}</p>`;
}
if (card.affirmation) {
modalContent += `<p><strong>Affirmation:</strong> ${card.affirmation}</p>`;
}
if (card.mythical_spiritual) {
modalContent += `<p><strong>Mythical/Spiritual:</strong> ${card.mythical_spiritual}</p>`;
}
if (card.fortune_telling) {
modalContent += `<p><strong>Fortune Telling:</strong></p><ul>`;
card.fortune_telling.forEach(item => {
modalContent += `<li>${item}</li>`;
});
modalContent += `</ul>`;
}
if (card.elemental) {
modalContent += `<p><strong>Elemental:</strong> ${card.elemental}</p>`;
}
if (card.hebrew_alphabet) {
modalContent += `<p><strong>Hebrew Alphabet:</strong> ${card.hebrew_alphabet}</p>`;
}
if (card.numerology) {
modalContent += `<p><strong>Numerology:</strong> ${card.numerology}</p>`;
}
if (card.astrology) {
modalContent += `<p><strong>Astrology:</strong> ${card.astrology}</p>`;
}
tarotModalBody.innerHTML = modalContent;
tarotModal.show();
}
function showAlbumDetails(album) {
if (!tarotModal || !tarotModalLabel || !tarotModalBody) return;
tarotModalLabel.textContent = album.title;
let modalContent = `
<div class="text-center">
<img src="images/${album.img}" alt="${album.title} cover" class="img-fluid">
<div class="badge-links" style="margin-top: 20px;">`;
// Adding Spotify badge
if (album.spotify) {
modalContent += `
<a href="${album.spotify}" target="_blank">
<img src="images/badge-spot.png" alt="Spotify" style="width: 60px; height: 60px; margin-right: 10px;">
</a>`;
}
// Adding YouTube badge
if (album.youtube) {
modalContent += `
<a href="${album.youtube}" target="_blank">
<img src="images/badge-yt.png" alt="YouTube" style="width: 60px; height: 60px; margin-right: 10px;">
</a>`;
}
// Adding Apple Music badge
if (album.apple) {
modalContent += `
<a href="${album.apple}" target="_blank">
<img src="images/badge-apl.png" alt="Apple Music" style="width: 60px; height: 60px; margin-right: 10px;">
</a>`;
}
// Adding SoundCloud badge
if (album.soundcloud) {
modalContent += `
<a href="${album.soundcloud}" target="_blank">
<img src="images/badge-sc.png" alt="SoundCloud" style="width: 60px; height: 60px; margin-right: 10px;">
</a>`;
}
modalContent += `</div></div>`;
tarotModalBody.innerHTML = modalContent;
tarotModal.show();
}
// Only add modal event listeners if modal exists
if (tarotModal && tarotModalBody) {
$('#tarotModal').on('hidden.bs.modal', function (e) {
tarotModalBody.innerHTML = '';
});
tarotModalBody.addEventListener('click', function(event) {
if (!event.target.closest('iframe')) {
tarotModal.hide();
}
}, { passive: true });
}
function buildAlbumSections(albumData, cardsData) {
if (!tarotGrid) return;
albumData.forEach(album => {
// Create the album section which includes the album and its cards
const albumSection = document.createElement('section');
albumSection.classList.add('album-section');
// Add an ID based on the album title (convert to lowercase, replace spaces/special chars with dashes)
const albumId = album.title
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-') // Replace any non-alphanumeric chars with dash
.replace(/(^-|-$)/g, ''); // Remove leading/trailing dashes
albumSection.id = albumId;
// Create the album container which will only have the album image and title
const albumContainer = createAlbumElement(album);
albumSection.appendChild(albumContainer);
// Create the cards container for this album
const cardsContainer = document.createElement('div');
cardsContainer.classList.add('cards-container');
// Filter and append cards for the current album
const albumCards = cardsData.filter(card => card.album === album.title);
albumCards.forEach(card => {
const cardElement = createCardElement(card);
cardsContainer.appendChild(cardElement);
});
// Append the cards container to the album section
albumSection.appendChild(cardsContainer);
// Append the complete album section to the main grid
tarotGrid.appendChild(albumSection);
});
}
function createAlbumElement(album) {
const albumContainer = document.createElement('div');
albumContainer.classList.add('album-container');
const albumImage = document.createElement('img');
albumImage.src = `images/${album.img}`;
albumImage.alt = `${album.title} cover`;
albumImage.classList.add('album-cover');
albumImage.onclick = () => showAlbumDetails(album);
const albumTitle = document.createElement('h2');
albumTitle.classList.add('album-title');
albumTitle.textContent = album.title;
// Create a div for badges
const badgesDiv = document.createElement('div');
badgesDiv.style.display = 'flex';
badgesDiv.style.justifyContent = 'center';
badgesDiv.style.paddingBottom = '24px';
// Conditionally add each badge if the URL exists
const badges = [
{name: 'spotify', img: 'badge-spot.png', url: album.spotify},
{name: 'youtube', img: 'badge-yt.png', url: album.youtube},
{name: 'apple', img: 'badge-apl.png', url: album.apple},
{name: 'soundcloud', img: 'badge-sc.png', url: album.soundcloud}
];
badges.forEach(badge => {
if (badge.url) {
const link = document.createElement('a');
link.href = badge.url;
link.target = '_blank';
const img = document.createElement('img');
img.src = `images/${badge.img}`;
img.alt = badge.name;
img.style.width = '48px';
img.style.height = '48px';
img.style.margin = '0 12px';
link.appendChild(img);
badgesDiv.appendChild(link);
}
});
albumContainer.appendChild(albumImage);
albumContainer.appendChild(albumTitle);
albumContainer.appendChild(badgesDiv);
return albumContainer;
}
function fetchAndStoreTarotData() {
// Only fetch tarot data if we have a tarot grid to display it in
if (!tarotGrid) return;
fetch("tarot.json")
.then((response) => response.json())
.then((data) => {
tarotDataGlobal = data;
buildAlbumSections(data.albums, data.cards);
scrollToHashSection();
})
.catch((error) => {
console.error("Error fetching tarot data:", error);
});
}
function openRandomCardModal() {
if (tarotDataGlobal) {
const randomIndex = Math.floor(Math.random() * tarotDataGlobal.cards.length);
const randomCard = tarotDataGlobal.cards[randomIndex];
showCardDetails(randomCard);
} else {
console.error('Tarot data not loaded yet');
}
}
// Only add random card button listener if the button exists
const randomCardBtn = document.getElementById('randomCardBtn');
if (randomCardBtn) {
randomCardBtn.addEventListener('click', function() {
openRandomCardModal();
});
}
fetchAndStoreTarotData();
// Add event listener for hash changes
window.addEventListener('hashchange', scrollToHashSection);