|
277 | 277 | self._hidePreviewTitle(); |
278 | 278 | self._hideContent(); |
279 | 279 |
|
| 280 | + // Clear URL hash |
| 281 | + window.history.pushState(null, null, window.location.pathname + window.location.search); |
| 282 | + |
280 | 283 | // Show the main container |
281 | 284 | anime({ |
282 | 285 | targets: self.el, |
|
366 | 369 | self.isOpen = true; |
367 | 370 | self.currentDayIdx = instance.number; |
368 | 371 |
|
| 372 | + // Update URL hash |
| 373 | + window.history.pushState(null, null, '#day-' + (instance.number + 1)); |
| 374 | + |
369 | 375 | // Hide the main container |
370 | 376 | anime({ |
371 | 377 | targets: self.el, |
|
680 | 686 | contents = contentEl.querySelectorAll('.content__block'), |
681 | 687 | backCtrl = contentEl.querySelector('.btn-back'), |
682 | 688 | contentNumber = contentEl.querySelector('.content__number'), |
683 | | - isMobile = mobilecheck(); |
| 689 | + isMobile = mobilecheck(), |
| 690 | + calendarInstance; |
684 | 691 |
|
685 | 692 | function init() { |
686 | 693 | 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 | + } |
687 | 726 | } |
688 | 727 |
|
689 | 728 | function layout() { |
690 | | - new Calendar(calendarEl); |
| 729 | + calendarInstance = new Calendar(calendarEl); |
691 | 730 | // If settings.snow === true then create the canvas element for the snow effect. |
692 | 731 | if( settings.snow ) { |
693 | 732 | var snow = new Snow(); |
|
0 commit comments