From 65c53c7652724fee1ef1df7fd85d981438d7ccca Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 9 Sep 2024 12:25:38 +0800 Subject: feat: Save content in hash --- src/editor.mjs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') 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' const HtmlContainer = document.querySelector(".result-html") const mdeElement = document.querySelector("#tinymde") +const getContentFromHash = () => { + const hashValue = location.hash.substring(1); + window.location.hash = '' + return hashValue.startsWith('text=') + ? decodeURIComponent(hashValue.substring(5)) + : null +} + // Add Editor -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' +const contentFromHash = getContentFromHash() const lastContent = localStorage.getItem('editorContent') +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' + const tinyEditor = new TinyMDE.Editor({ element: 'tinymde', - content: lastContent ? lastContent : defaultContent + content: contentFromHash ?? lastContent ?? defaultContent }); mdeElement.querySelectorAll('span').forEach(e => e.setAttribute('spellcheck', 'false')) @@ -38,8 +48,7 @@ const debugCommand = { title: 'show debug message', innerHTML: `
🤔
`, action: () => { - // FIXME - alert(tinyEditor.getContent()) + window.location.hash = '#text=' + encodeURIComponent(tinyEditor.getContent()) }, hotkey: 'Ctrl-i' } -- cgit v1.2.3-70-g09d2