diff options
-rw-r--r-- | src/editor.mjs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/editor.mjs b/src/editor.mjs index 866237a..f0b4af0 100644 --- a/src/editor.mjs +++ b/src/editor.mjs | |||
@@ -7,6 +7,7 @@ import { shiftByWindow } from './utils.mjs' | |||
7 | 7 | ||
8 | // Set up Containers {{{ | 8 | // Set up Containers {{{ |
9 | 9 | ||
10 | const url = new URL(window.location) | ||
10 | const context = document.querySelector('[data-mode]') | 11 | const context = document.querySelector('[data-mode]') |
11 | const dumbyContainer = document.querySelector('.DumbyMap') | 12 | const dumbyContainer = document.querySelector('.DumbyMap') |
12 | const textArea = document.querySelector('.editor textarea') | 13 | const textArea = document.querySelector('.editor textarea') |
@@ -134,6 +135,7 @@ const editor = new EasyMDE({ | |||
134 | action: () => { | 135 | action: () => { |
135 | const state = { content: editor.value() } | 136 | const state = { content: editor.value() } |
136 | window.location.hash = encodeURIComponent(JSON.stringify(state)) | 137 | window.location.hash = encodeURIComponent(JSON.stringify(state)) |
138 | window.location.search = '' | ||
137 | navigator.clipboard.writeText(window.location.href) | 139 | navigator.clipboard.writeText(window.location.href) |
138 | window.alert('URL updated in address bar, you can save current page as bookmark') | 140 | window.alert('URL updated in address bar, you can save current page as bookmark') |
139 | } | 141 | } |
@@ -239,17 +241,19 @@ const getContentFromHash = hash => { | |||
239 | const state = getStateFromHash(hash) | 241 | const state = getStateFromHash(hash) |
240 | return state.content | 242 | return state.content |
241 | } | 243 | } |
244 | const contentFromHash = getContentFromHash(window.location.hash) | ||
242 | 245 | ||
243 | const initialState = getStateFromHash(window.location.hash) | 246 | if (url.searchParams.get('content') === 'tutorial') { |
244 | window.location.hash = '' | 247 | console.log('tutorial') |
245 | const contentFromHash = initialState.content | 248 | editor.value(defaultContent) |
246 | 249 | } else if (contentFromHash) { | |
247 | // Seems like autosave would overwrite initialValue, set content from hash here | 250 | // Seems like autosave would overwrite initialValue, set content from hash here |
248 | if (contentFromHash) { | ||
249 | editor.cleanup() | 251 | editor.cleanup() |
250 | editor.value(contentFromHash) | 252 | editor.value(contentFromHash) |
251 | } | 253 | } |
252 | 254 | ||
255 | window.location.hash = '' | ||
256 | |||
253 | // }}} | 257 | // }}} |
254 | // Set up logic about editor content {{{ | 258 | // Set up logic about editor content {{{ |
255 | 259 | ||