diff --git a/docs/themes/navy/source/js/main.js b/docs/themes/navy/source/js/main.js index 30643c110..4bdebe6ca 100644 --- a/docs/themes/navy/source/js/main.js +++ b/docs/themes/navy/source/js/main.js @@ -66,9 +66,8 @@ preview.renderer.setShowGutter(false); preview.renderer.setPadding(20); - editor.setValue(sourceEl.textContent, 1); + editor.setValue(getInitialValue(), 1); editor.on('change', update); - editor.focus(); update(); function createEditor(id, lang) { @@ -83,8 +82,16 @@ return editor; } + function getInitialValue() { + try { + return atou(location.hash.slice(1)) || sourceEl.textContent + } catch (e) {} + return sourceEl.textContent + } + async function update() { const tpl = editor.getValue(); + history.replaceState({}, '', '#' + utoa(tpl)); try { const html = await engine.parseAndRender(tpl); preview.setValue(html, 1); @@ -93,6 +100,14 @@ throw err; } } + + function atou(str) { + return decodeURIComponent(escape(atob(str))) + } + + function utoa(str) { + return btoa(unescape(encodeURIComponent(str))) + } }()); if ('serviceWorker' in navigator) { diff --git a/docs/themes/navy/source/js/playground.js b/docs/themes/navy/source/js/playground.js deleted file mode 100644 index e69de29bb..000000000