mirror of
https://github.com/placeAtlas/atlas.git
synced 2024-09-27 12:39:18 +02:00
Avoid another update on hash linking, allow code-only period on default
The code-only period is just "".
This commit is contained in:
parent
24f9c397f1
commit
49f0e631cb
3 changed files with 22 additions and 9 deletions
|
@ -43,7 +43,7 @@ function createInfoBlock(entry, isPreview) {
|
|||
else {
|
||||
let targetPeriod = formatPeriod(currentPeriod, currentPeriod, currentVariation)
|
||||
linkElement.href = "#" + entry.id
|
||||
if (targetPeriod !== defaultPeriod) linkElement.href += "/" + targetPeriod
|
||||
if (targetPeriod) linkElement.href += "/" + targetPeriod
|
||||
};
|
||||
const linkNameElement = document.createElement("span");
|
||||
linkNameElement.className = "flex-grow-1 text-break";
|
||||
|
|
|
@ -111,7 +111,15 @@ async function init() {
|
|||
}
|
||||
}
|
||||
|
||||
await updateTime(currentPeriod, currentVariation)
|
||||
const hash = window.location.hash.substring(1)
|
||||
const [ , period] = hash.split('/')
|
||||
|
||||
if (period) {
|
||||
const [ , targetPeriod, targetVariation] = parsePeriod(period)
|
||||
await updateTime(targetPeriod, targetVariation)
|
||||
} else {
|
||||
await updateTime(currentPeriod, currentVariation)
|
||||
}
|
||||
|
||||
//console.log(document.documentElement.clientWidth, document.documentElement.clientHeight);
|
||||
|
||||
|
|
|
@ -156,8 +156,13 @@ async function updateBackground(newPeriod = currentPeriod, newVariation = curren
|
|||
async function updateTime(newPeriod = currentPeriod, newVariation = currentVariation, forcePeriod = false) {
|
||||
document.body.dataset.canvasLoading = ""
|
||||
|
||||
currentPeriod = newPeriod
|
||||
if (!variationsConfig[newVariation]) newVariation = defaultVariation
|
||||
const variationConfig = variationsConfig[newVariation]
|
||||
|
||||
if (newPeriod < 0) newPeriod = 0
|
||||
else if (newPeriod > variationConfig.versions.length - 1) newPeriod = variationConfig.versions.length - 1
|
||||
|
||||
currentPeriod = newPeriod
|
||||
if (currentVariation !== newVariation) {
|
||||
currentVariation = newVariation
|
||||
timelineSlider.max = variationConfig.versions.length - 1;
|
||||
|
@ -245,7 +250,7 @@ function parsePeriod(periodString) {
|
|||
periodString = split[1]
|
||||
}
|
||||
if (periodString.search('-') + 1) {
|
||||
const [start, end] = periodString.split('-').map(i => parseInt(i))
|
||||
let [start, end] = periodString.split('-').map(i => parseInt(i))
|
||||
return [start, end, variation]
|
||||
} else if (codeReference[periodString]) {
|
||||
variation = codeReference[periodString]
|
||||
|
@ -259,11 +264,11 @@ function parsePeriod(periodString) {
|
|||
|
||||
function formatPeriod(start, end, variation) {
|
||||
let periodString
|
||||
if (start === end) periodString = start
|
||||
else periodString = start + "-" + end
|
||||
if (variation !== "default") {
|
||||
if (start === variationsConfig[variation].default) return variationsConfig[variation].code
|
||||
else return variationsConfig[variation].code + ":" + periodString
|
||||
if (start === end) {
|
||||
if (start === variationsConfig[variation].default) periodString = ""
|
||||
else periodString = start
|
||||
}
|
||||
else periodString = start + "-" + end
|
||||
if (variation !== "default") return variationsConfig[variation].code + ":" + periodString
|
||||
return periodString
|
||||
}
|
Loading…
Reference in a new issue