diff --git a/src/editor/main.js b/src/editor/main.js index 127d6bd..bb17b13 100644 --- a/src/editor/main.js +++ b/src/editor/main.js @@ -179,7 +179,7 @@ $btnNewData.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') }) @@ -233,7 +233,7 @@ $btnDownloadHTML.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) }) diff --git a/src/preview/main.js b/src/preview/main.js index 40189b4..1c40b77 100644 --- a/src/preview/main.js +++ b/src/preview/main.js @@ -4,17 +4,42 @@ import { getCVData, getCVSavedTime, } from '../lib/store'; -import { applyThemeTo } from '../themes'; +import { renderThemeOn } from '../themes'; import { getCVTitle } from '../themes/data'; const themeName = 'default' 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() if (data) { - applyThemeTo(themeName, elCV, data) + renderThemeOn(themeName, elCV, data) // change document title document.title = getCVTitle(data) + // restore scroll position + restoreScrollPosition() } const savedTime = getCVSavedTime() diff --git a/src/themes/index.js b/src/themes/index.js index 576842d..8ed124c 100644 --- a/src/themes/index.js +++ b/src/themes/index.js @@ -36,7 +36,7 @@ export function renderTheme(template, cvData, options) { const cvStyleId = 'cv-style' -export function applyThemeTo(name, el, data) { +export function renderThemeOn(name, el, data) { const theme = getTheme(name) el.innerHTML = renderTheme(theme.template, data)