mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
docs: location.hash for source code
This commit is contained in:
Vendored
+17
-2
@@ -66,9 +66,8 @@
|
|||||||
preview.renderer.setShowGutter(false);
|
preview.renderer.setShowGutter(false);
|
||||||
preview.renderer.setPadding(20);
|
preview.renderer.setPadding(20);
|
||||||
|
|
||||||
editor.setValue(sourceEl.textContent, 1);
|
editor.setValue(getInitialValue(), 1);
|
||||||
editor.on('change', update);
|
editor.on('change', update);
|
||||||
editor.focus();
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
function createEditor(id, lang) {
|
function createEditor(id, lang) {
|
||||||
@@ -83,8 +82,16 @@
|
|||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getInitialValue() {
|
||||||
|
try {
|
||||||
|
return atou(location.hash.slice(1)) || sourceEl.textContent
|
||||||
|
} catch (e) {}
|
||||||
|
return sourceEl.textContent
|
||||||
|
}
|
||||||
|
|
||||||
async function update() {
|
async function update() {
|
||||||
const tpl = editor.getValue();
|
const tpl = editor.getValue();
|
||||||
|
history.replaceState({}, '', '#' + utoa(tpl));
|
||||||
try {
|
try {
|
||||||
const html = await engine.parseAndRender(tpl);
|
const html = await engine.parseAndRender(tpl);
|
||||||
preview.setValue(html, 1);
|
preview.setValue(html, 1);
|
||||||
@@ -93,6 +100,14 @@
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function atou(str) {
|
||||||
|
return decodeURIComponent(escape(atob(str)))
|
||||||
|
}
|
||||||
|
|
||||||
|
function utoa(str) {
|
||||||
|
return btoa(unescape(encodeURIComponent(str)))
|
||||||
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
|
|||||||
Reference in New Issue
Block a user