diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-09-09 15:00:20 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-09-10 17:20:55 +0800 |
commit | 3241ce124ba02e79a01231dbd2efd08e2d181b30 (patch) | |
tree | dcb458f47e61ce76db864cfd051da69f77246474 /src/editor.mjs | |
parent | f8abda510b0d83b8f7d6168fc7ab8ecabf41ca99 (diff) |
feat: Update editor content by hash
Diffstat (limited to 'src/editor.mjs')
-rw-r--r-- | src/editor.mjs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 04b4125..31229db 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -7,16 +7,16 @@ 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 = () => { | 10 | const getContentFromHash = (cleanHash = false) => { |
11 | const hashValue = location.hash.substring(1); | 11 | const hashValue = location.hash.substring(1); |
12 | window.location.hash = '' | 12 | if (cleanHash) window.location.hash = '' |
13 | return hashValue.startsWith('text=') | 13 | return hashValue.startsWith('text=') |
14 | ? decodeURIComponent(hashValue.substring(5)) | 14 | ? decodeURIComponent(hashValue.substring(5)) |
15 | : null | 15 | : null |
16 | } | 16 | } |
17 | 17 | ||
18 | // Add Editor | 18 | // Add Editor |
19 | const contentFromHash = getContentFromHash() | 19 | const contentFromHash = getContentFromHash(true) |
20 | 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' | 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 | 22 | ||
@@ -26,6 +26,11 @@ const tinyEditor = new TinyMDE.Editor({ | |||
26 | }); | 26 | }); |
27 | mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false')) | 27 | mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false')) |
28 | 28 | ||
29 | onhashchange = () => { | ||
30 | const contentFromHash = getContentFromHash() | ||
31 | if (contentFromHash) tinyEditor.setContent(contentFromHash) | ||
32 | } | ||
33 | |||
29 | // Add command bar for editor | 34 | // Add command bar for editor |
30 | // Use this command to render maps and geoLinks | 35 | // Use this command to render maps and geoLinks |
31 | const mapCommand = { | 36 | const mapCommand = { |