add pushState stuff for single.js
This commit is contained in:
parent
36ed5063ef
commit
d6f7995f4b
1 changed files with 21 additions and 1 deletions
|
@ -46,9 +46,26 @@ function setImage(id, src, href, cw) {
|
|||
mainlink.href = href;
|
||||
}
|
||||
|
||||
function activateButton(button) {
|
||||
function activateButton(button, doPush = true) {
|
||||
setImage(button.id, button.value,
|
||||
button.dataset.link, button.dataset.warning);
|
||||
|
||||
if (doPush) history.pushState(null, '', '#' + button.id);
|
||||
}
|
||||
|
||||
function useFragment() {
|
||||
let button = document.querySelector('#alts input');
|
||||
|
||||
let frag = document.location.hash.replace(/^#/, '');
|
||||
if (frag) {
|
||||
let button0 = document.getElementById(frag);
|
||||
if (button0) button = button0;
|
||||
}
|
||||
|
||||
if (button) {
|
||||
button.checked = true;
|
||||
activateButton(button, false);
|
||||
}
|
||||
}
|
||||
|
||||
function setup() {
|
||||
|
@ -61,6 +78,9 @@ function setup() {
|
|||
}
|
||||
|
||||
addCWListeners(document.getElementById('cw'));
|
||||
|
||||
window.addEventListener('popstate', useFragment);
|
||||
useFragment();
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', setup);
|
||||
|
|
Loading…
Reference in a new issue