Skip to content

Commit e2a2ae5

Browse files
committed
Very basic history
1 parent ea35cff commit e2a2ae5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

assets/js/main.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,17 @@ function scrollTop() {
457457
document.getElementById("right-side").scrollIntoView({ behavior: "smooth", block: "start", inline: "nearest" })
458458
}
459459

460-
function navigateTo(step) {
460+
window.addEventListener("popstate", (event) => {
461+
let step = (event.state && event.state.step) || 1
462+
navigateTo(step, true)
463+
});
464+
465+
466+
function navigateTo(step, nohistory) {
467+
if (!nohistory) {
468+
history.pushState({step: step}, "step " + step, "?step=" + step);
469+
}
470+
461471
const tab = new bootstrap.Tab(document.querySelector(`#step-${step}-tab`));
462472
tab.show();
463473
scrollTop();
@@ -496,15 +506,23 @@ function navigateTo(step) {
496506
}
497507
}
498508

499-
function secondpage() {
509+
function getPostcodeValues() {
500510
const zipValue = elements.searchInput.value.split(" ")[0].trim();
501511
const cityValue = elements.searchInput.value.split(" ")[1]
502512
? elements.searchInput.value.substr(
503513
elements.searchInput.value.indexOf(" ") + 1
504514
)
505515
: "";
516+
return {
517+
zip: zipValue,
518+
city: cityValue
519+
}
520+
}
521+
522+
function secondpage() {
523+
const data = getPostcodeValues()
506524

507-
if (zipValue.length >= 5 && is_valid_datalist_value(zipValue, cityValue)) {
525+
if (data.zip.length >= 5 && is_valid_datalist_value(data.zip, data.city)) {
508526
navigateTo(2);
509527
}
510528
}

0 commit comments

Comments
 (0)