aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2024-09-09 15:00:20 +0800
committerHsieh Chin Fan <pham@topo.tw>2024-09-10 17:20:55 +0800
commit3241ce124ba02e79a01231dbd2efd08e2d181b30 (patch)
treedcb458f47e61ce76db864cfd051da69f77246474 /src
parentf8abda510b0d83b8f7d6168fc7ab8ecabf41ca99 (diff)
feat: Update editor content by hash
Diffstat (limited to 'src')
-rw-r--r--src/editor.mjs11
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'
7const HtmlContainer = document.querySelector(".result-html") 7const HtmlContainer = document.querySelector(".result-html")
8const mdeElement = document.querySelector("#tinymde") 8const mdeElement = document.querySelector("#tinymde")
9 9
10const getContentFromHash = () => { 10const 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
19const contentFromHash = getContentFromHash() 19const contentFromHash = getContentFromHash(true)
20const lastContent = localStorage.getItem('editorContent') 20const lastContent = localStorage.getItem('editorContent')
21const 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' 21const 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});
27mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false')) 27mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false'))
28 28
29onhashchange = () => {
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
31const mapCommand = { 36const mapCommand = {