diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-09 12:25:38 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-09 12:28:27 +0800 |
commit | 65c53c7652724fee1ef1df7fd85d981438d7ccca (patch) | |
tree | 7fdfdb29909e50a56c19ffb198ddf90acd5c764f /src/editor.mjs | |
parent | 67dfb052ac88b7fee56ab5399c332b7432ac979f (diff) |
feat: Save content in hash
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index ed2ab25..ba54aa9 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -7,12 +7,22 @@ import { defaultAliasesForRenderer, parseConfigsFromYaml } from 'mapclay' | |||
7 | const HtmlContainer = document.querySelector(".result-html") | 7 | const HtmlContainer = document.querySelector(".result-html") |
8 | const mdeElement = document.querySelector("#tinymde") | 8 | const mdeElement = document.querySelector("#tinymde") |
9 | 9 | ||
10 | const getContentFromHash = () => { | ||
11 | const hashValue = location.hash.substring(1); | ||
12 | window.location.hash = '' | ||
13 | return hashValue.startsWith('text=') | ||
14 | ? decodeURIComponent(hashValue.substring(5)) | ||
15 | : null | ||
16 | } | ||
17 | |||
10 | // Add Editor | 18 | // Add Editor |
11 | const defaultContent = '## Links\n\n- [Go to marker](geo:24,121?id=foo,leaflet&text=normal "Link Test")\n\n```map\nid: foo\nuse: Maplibre\n```\n' | 19 | const contentFromHash = getContentFromHash() |
12 | const lastContent = localStorage.getItem('editorContent') | 20 | const lastContent = localStorage.getItem('editorContent') |
21 | const defaultContent = '## Links\n\n- [Go to marker](geo:24,121?id=foo,leaflet&text=normal "Link Test")\n\n```map\nid: foo\nuse: Maplibre\n```\n' | ||
22 | |||
13 | const tinyEditor = new TinyMDE.Editor({ | 23 | const tinyEditor = new TinyMDE.Editor({ |
14 | element: 'tinymde', | 24 | element: 'tinymde', |
15 | content: lastContent ? lastContent : defaultContent | 25 | content: contentFromHash ?? lastContent ?? defaultContent |
16 | }); | 26 | }); |
17 | mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false')) | 27 | mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false')) |
18 | 28 | ||
@@ -38,8 +48,7 @@ const debugCommand = { | |||
38 | title: 'show debug message', | 48 | title: 'show debug message', |
39 | innerHTML: `<div style="font-size: 16px; line-height: 1.1;">🤔</div>`, | 49 | innerHTML: `<div style="font-size: 16px; line-height: 1.1;">🤔</div>`, |
40 | action: () => { | 50 | action: () => { |
41 | // FIXME | 51 | window.location.hash = '#text=' + encodeURIComponent(tinyEditor.getContent()) |
42 | alert(tinyEditor.getContent()) | ||
43 | }, | 52 | }, |
44 | hotkey: 'Ctrl-i' | 53 | hotkey: 'Ctrl-i' |
45 | } | 54 | } |