summaryrefslogtreecommitdiff
path: root/Blog/Components/Pages/Note.razor.js
diff options
context:
space:
mode:
Diffstat (limited to 'Blog/Components/Pages/Note.razor.js')
-rw-r--r--Blog/Components/Pages/Note.razor.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/Blog/Components/Pages/Note.razor.js b/Blog/Components/Pages/Note.razor.js
new file mode 100644
index 0000000..3d47d23
--- /dev/null
+++ b/Blog/Components/Pages/Note.razor.js
@@ -0,0 +1,33 @@
1import { getById, debounce, writeError, resetLog } from "/common.module.js";
2import lzString from "/lz-string.module.js";
3
4let input = undefined;
5export function onLoad() {
6 input = getById("input");
7 input.addEventListener("input", debounce(() => {
8 if (input.value === '') {
9 window.location.hash = ''
10 }
11 else {
12 window.location.hash = '#' + lzString.compressToEncodedURIComponent(input.value);
13 }
14 resetLog();
15 }, 10))
16
17 window.addEventListener('hashchange', loadState);
18 loadState();
19}
20
21export function onUpdate() {
22 loadState();
23}
24
25function loadState() {
26 if (window.location.hash !== '') {
27 input.value = lzString.decompressFromEncodedURIComponent(window.location.hash.substring(1));
28 if (input.value === '') {
29 //Hash but no content?
30 writeError("Failed to load note from url.")
31 }
32 }
33} \ No newline at end of file