mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 12:20:40 -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.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) {
|
||||
|
||||
Reference in New Issue
Block a user