From 671e2d0d1a3d09369d02bc4f48f2b8d71d09340a Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Sun, 20 Nov 2022 12:42:51 -0700 Subject: [PATCH] Adding mechanism to change URLs on page state changes --- www/js/main.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/www/js/main.js b/www/js/main.js index b62d9c7..ecb0784 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -7,8 +7,6 @@ $(() => { // A specific path has been set. Display the profile for that person openPerson = path - // CHANGE THE DISPLAY HERE FOR JASON / FLO - // Display content for the relevant person, and hide other content $('.main.not' + openPerson).css({ 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) $('a.openlink').click(function(e) { e.preventDefault(); @@ -98,7 +102,7 @@ $(() => { }) } - // Display the links + // Display the links and change the page URL setTimeout(() => { $('#links-' + openPerson).animate({ height: $('#links-' + openPerson).get(0).scrollHeight @@ -106,6 +110,8 @@ $(() => { duration: 300, queue: true }) + + window.history.pushState({ id: "100" }, '', '/' + openPerson); }, 300) } else { // If a profile is open, close it. @@ -160,6 +166,9 @@ $(() => { } }) } + + // Push a new page URL + window.history.pushState({ id: "100" }, '', '/'); } }) })