diff options
Diffstat (limited to 'resources/js/writing_index.js')
| -rw-r--r-- | resources/js/writing_index.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/resources/js/writing_index.js b/resources/js/writing_index.js new file mode 100644 index 0000000..de3159d --- /dev/null +++ b/resources/js/writing_index.js @@ -0,0 +1,78 @@ +let dom = {}; + +$(function() { + initDOM(); + + + marked.setOptions({ + breaks: true, + sanitize: true + }) + + dom.inputText.oninput = ()=>{ + dom.contentPreview.innerHTML = marked.parse(dom.inputText.value); + }; + + let restoredContent = localStorage.getItem('writing_draft_content'); + if (restoredContent != null){ + if (localStorage.getItem('writing_draft_expiration') < Date.now()){ + localStorage.removeItem('writing_draft_content'); + localStorage.removeItem('writing_draft_expiration'); + } else { + dom.inputText.value = restoredContent; + dom.contentPreview.innerHTML = marked.parse(dom.inputText.value); + } + } + + //periodically save the contents to client to prevent data loss + const intervalId = setInterval(() => { + const content = dom.inputText.value; + localStorage.setItem('writing_draft_content', content); + localStorage.setItem('writing_draft_expiration', Date.now() + 1000*3600*96); + }, 5000); + +}); + +function initDOM(){ + dom.filterMethod = $('#filter_method')[0]; + dom.sortMethod = $('#sort_method')[0]; + dom.sortMethod.onchange = sortContentList; + dom.filterMethod.onchange = filterContentList; +} + +function performReplace(){ + + + // Save current state to history for undo + editorHistory.push(dom.inputText.value); + + // Perform the replacement + const regex = new RegExp(dom.findStr.value, dom.toggleMultiline.checked ? 'gm' : 'g'); + dom.inputText.value = dom.inputText.value.replace(regex, dom.replaceStr.value); + dom.contentPreview.innerHTML = marked.parse(dom.inputText.value); + + + editorHistory.push(dom.inputText.value); + + dom.inputText.value = dom.inputText.value.replace(regex, dom.replaceStr.value); + dom.contentPreview.innerHTML = marked.parse(dom.inputText.value); +}; + +function sortContentList(){ + const sortMethod = dom.sortMethod.value; + console.log(sortMethod); + switch (sorthMethod){ + case 'date': + break; + case 'title': + break; + case 'author': + break; + case 'category': + break; + default: + break; + } +} + +function filterContentList(){}
\ No newline at end of file |
