Skip to content

Commit

Permalink
feat: add save state after close popup
Browse files Browse the repository at this point in the history
  • Loading branch information
RezenkovD committed Aug 14, 2023
1 parent ce36607 commit ce0b6ed
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vr_club_site/templates/site/js/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ document.addEventListener("DOMContentLoaded", function () {
var popupScrollPosition;
function openPopup(day, month, year) {
popupScrollPosition = window.scrollY;
const state = { popupOpen: true, day: day, month: month, year: year };
history.pushState(state, null, ''); // Збереження стану в історії браузера
const dateDiv = document.querySelector('.booking-date');
const monthsNames = [
"січня",
Expand Down Expand Up @@ -159,13 +161,14 @@ function closePopup() {
popup.style.display = 'none';
body.style.overflow = 'auto';
window.scrollTo(0, popupScrollPosition);
history.pushState(null, null, '');
}

window.addEventListener('popstate', function(event) {
var state = event.state;

if (state && state.popupOpen) {
openPopup(day, month, year);
openPopup(state.day, state.month, state.year);
} else {
closePopup();
}
Expand Down

0 comments on commit ce0b6ed

Please sign in to comment.