Skip to content

Commit c180787

Browse files
committed
Let AI implement a feature go get individual URLs for each day. Approach: Hash fragments
1 parent 2ee0be3 commit c180787

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

js/main2.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@
277277
self._hidePreviewTitle();
278278
self._hideContent();
279279

280+
// Clear URL hash
281+
window.history.pushState(null, null, window.location.pathname + window.location.search);
282+
280283
// Show the main container
281284
anime({
282285
targets: self.el,
@@ -366,6 +369,9 @@
366369
self.isOpen = true;
367370
self.currentDayIdx = instance.number;
368371

372+
// Update URL hash
373+
window.history.pushState(null, null, '#day-' + (instance.number + 1));
374+
369375
// Hide the main container
370376
anime({
371377
targets: self.el,
@@ -680,14 +686,47 @@
680686
contents = contentEl.querySelectorAll('.content__block'),
681687
backCtrl = contentEl.querySelector('.btn-back'),
682688
contentNumber = contentEl.querySelector('.content__number'),
683-
isMobile = mobilecheck();
689+
isMobile = mobilecheck(),
690+
calendarInstance;
684691

685692
function init() {
686693
layout();
694+
checkURLHash();
695+
696+
// Listen for hash changes (browser back/forward)
697+
window.addEventListener('hashchange', function() {
698+
var hash = window.location.hash;
699+
if (!hash || hash === '') {
700+
// No hash means go back to calendar
701+
if (calendarInstance && calendarInstance.isOpen) {
702+
backCtrl.click();
703+
}
704+
} else {
705+
// Hash exists, open that day
706+
checkURLHash();
707+
}
708+
});
709+
}
710+
711+
// Function to check URL hash and open corresponding day
712+
function checkURLHash() {
713+
var hash = window.location.hash;
714+
if (hash && hash.startsWith('#day-')) {
715+
var dayNumber = parseInt(hash.replace('#day-', '')) - 1; // Convert to 0-based index
716+
if (calendarInstance && dayNumber >= 0 && dayNumber < calendarInstance.days.length) {
717+
var day = calendarInstance.days[dayNumber];
718+
if (day.isActive) {
719+
// Small delay to ensure everything is initialized
720+
setTimeout(function() {
721+
day.cube.click();
722+
}, 100);
723+
}
724+
}
725+
}
687726
}
688727

689728
function layout() {
690-
new Calendar(calendarEl);
729+
calendarInstance = new Calendar(calendarEl);
691730
// If settings.snow === true then create the canvas element for the snow effect.
692731
if( settings.snow ) {
693732
var snow = new Snow();

0 commit comments

Comments
 (0)