diff options
-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 = { |