Adding mechanism to change URLs on page state changes

This commit is contained in:
Jason Williams 2022-11-20 12:42:51 -07:00
parent 78d49c9bc0
commit 671e2d0d1a

View File

@ -7,8 +7,6 @@ $(() => {
// A specific path has been set. Display the profile for that person // A specific path has been set. Display the profile for that person
openPerson = path openPerson = path
// CHANGE THE DISPLAY HERE FOR JASON / FLO
// Display content for the relevant person, and hide other content // Display content for the relevant person, and hide other content
$('.main.not' + openPerson).css({ $('.main.not' + openPerson).css({
width: 0, width: 0,
@ -32,6 +30,12 @@ $(() => {
}) })
} }
// Listen for pop states
window.onpopstate = function(event) {
path = window.location.pathname.replace(/\//g, '')
//alert(path)
};
// Handle clicks on profile links (by doing nothing) // Handle clicks on profile links (by doing nothing)
$('a.openlink').click(function(e) { $('a.openlink').click(function(e) {
e.preventDefault(); e.preventDefault();
@ -98,7 +102,7 @@ $(() => {
}) })
} }
// Display the links // Display the links and change the page URL
setTimeout(() => { setTimeout(() => {
$('#links-' + openPerson).animate({ $('#links-' + openPerson).animate({
height: $('#links-' + openPerson).get(0).scrollHeight height: $('#links-' + openPerson).get(0).scrollHeight
@ -106,6 +110,8 @@ $(() => {
duration: 300, duration: 300,
queue: true queue: true
}) })
window.history.pushState({ id: "100" }, '', '/' + openPerson);
}, 300) }, 300)
} else { } else {
// If a profile is open, close it. // If a profile is open, close it.
@ -160,6 +166,9 @@ $(() => {
} }
}) })
} }
// Push a new page URL
window.history.pushState({ id: "100" }, '', '/');
} }
}) })
}) })