theme reorx: remember scroll position
This commit is contained in:
parent
f4ca4cbe46
commit
f8cb8bdf20
|
|
@ -179,7 +179,7 @@ $btnNewData.on('click', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
$btnUploadData.on('click', () => {
|
$btnUploadData.on('click', () => {
|
||||||
if (!confirm('Are you sure to upload an existing CV data? Your current data will be covered.')) return
|
if (!confirm('Are you sure to upload an existing CV data? Your current data will be replaced.')) return
|
||||||
$inputUploadData.trigger('click')
|
$inputUploadData.trigger('click')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -233,7 +233,7 @@ $btnDownloadHTML.on('click', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
$btnLoadSample.on('click', () => {
|
$btnLoadSample.on('click', () => {
|
||||||
if (!confirm('Are you sure to load sample data? Your current data will be covered.')) return
|
if (!confirm('Are you sure to load sample data? Your current data will be replaced.')) return
|
||||||
|
|
||||||
editor.setValue(sampleModule.default)
|
editor.setValue(sampleModule.default)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,42 @@ import {
|
||||||
getCVData,
|
getCVData,
|
||||||
getCVSavedTime,
|
getCVSavedTime,
|
||||||
} from '../lib/store';
|
} from '../lib/store';
|
||||||
import { applyThemeTo } from '../themes';
|
import { renderThemeOn } from '../themes';
|
||||||
import { getCVTitle } from '../themes/data';
|
import { getCVTitle } from '../themes/data';
|
||||||
|
|
||||||
const themeName = 'default'
|
const themeName = 'default'
|
||||||
const elCV = document.querySelector('.cv-container')
|
const elCV = document.querySelector('.cv-container')
|
||||||
|
|
||||||
|
// Save scroll position on page unload
|
||||||
|
const storeKeyScroll = 'scroll-position'
|
||||||
|
const onScroll = () => {
|
||||||
|
localStorage.setItem(storeKeyScroll, JSON.stringify({
|
||||||
|
scrollX: window.scrollX,
|
||||||
|
scrollY: window.scrollY,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
let onScrollTimer
|
||||||
|
window.addEventListener("scroll", () => {
|
||||||
|
if (onScrollTimer) clearTimeout(onScrollTimer)
|
||||||
|
|
||||||
|
onScrollTimer = setTimeout(onScroll, 50);
|
||||||
|
}, false)
|
||||||
|
|
||||||
|
const restoreScrollPosition = () => {
|
||||||
|
const scrollPosition = JSON.parse(localStorage.getItem(storeKeyScroll));
|
||||||
|
if (scrollPosition) {
|
||||||
|
window.scrollTo(scrollPosition.scrollX, scrollPosition.scrollY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render CV
|
||||||
const data = getCVData()
|
const data = getCVData()
|
||||||
if (data) {
|
if (data) {
|
||||||
applyThemeTo(themeName, elCV, data)
|
renderThemeOn(themeName, elCV, data)
|
||||||
// change document title
|
// change document title
|
||||||
document.title = getCVTitle(data)
|
document.title = getCVTitle(data)
|
||||||
|
// restore scroll position
|
||||||
|
restoreScrollPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
const savedTime = getCVSavedTime()
|
const savedTime = getCVSavedTime()
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ export function renderTheme(template, cvData, options) {
|
||||||
|
|
||||||
const cvStyleId = 'cv-style'
|
const cvStyleId = 'cv-style'
|
||||||
|
|
||||||
export function applyThemeTo(name, el, data) {
|
export function renderThemeOn(name, el, data) {
|
||||||
const theme = getTheme(name)
|
const theme = getTheme(name)
|
||||||
el.innerHTML = renderTheme(theme.template, data)
|
el.innerHTML = renderTheme(theme.template, data)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue