summaryrefslogtreecommitdiff
path: root/resources/js/writing_index.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/writing_index.js')
-rw-r--r--resources/js/writing_index.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/resources/js/writing_index.js b/resources/js/writing_index.js
new file mode 100644
index 0000000..b8a2ed1
--- /dev/null
+++ b/resources/js/writing_index.js
@@ -0,0 +1,59 @@
+
+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];
+
+}
+
+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);
+}; \ No newline at end of file