From c0ccc40d17903e0b7c11fef21182059257cf79bf Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Mon, 23 Jul 2018 08:49:38 +0300 Subject: [PATCH] changes indicator --- code/static/css/styles.css | 5 ++++- code/static/js/scripts.js | 24 ++++++++++++++++++++++-- code/templates/editor.html | 11 ++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/code/static/css/styles.css b/code/static/css/styles.css index 3953448..4ca224c 100644 --- a/code/static/css/styles.css +++ b/code/static/css/styles.css @@ -291,8 +291,10 @@ tr:nth-child(odd) { } #editor_area { - width: 40vw; + width: 82vw; float: left; + background-color: var(--background-light-color); + border: 2px solid var(--border-color); } #editor_preview { @@ -300,6 +302,7 @@ tr:nth-child(odd) { margin-left: 2vw; float: left; line-height: normal; + display: none; } #editor_preview p { diff --git a/code/static/js/scripts.js b/code/static/js/scripts.js index 17779ca..1e1ef5c 100644 --- a/code/static/js/scripts.js +++ b/code/static/js/scripts.js @@ -151,20 +151,40 @@ function UploadURL() { } -function updateEditorPreview() { +function updateEditor() { var input = document.getElementById("editor_area"); var preview = document.getElementById("editor_preview"); - preview.innerHTML = md.render(input.value); + if (preview.style.display === 'block') { + preview.innerHTML = md.render(input.value); + } + var currentHash = hashCode(input.value); + if (currentHash == editorHash) { + document.getElementById("editor_save").value = "Save "; + } else { + document.getElementById("editor_save").value = "Save*"; + } } + + function previewToggle() { toggler("editor_preview"); if (document.getElementById("editor_preview").style.display === 'block') { document.getElementById("editor_area").style.width = "40vw"; + updateEditor(); } else { document.getElementById("editor_area").style.width = "82vw"; } } +function hashCode(s) { + var h = 0, l = s.length, i = 0; + if ( l > 0 ) + while (i < l) + h = (h << 5) - h + s.charCodeAt(i++) | 0; + return h; +}; + + function changeTitle(newTitle) { document.title = "Flees - " + newTitle; } diff --git a/code/templates/editor.html b/code/templates/editor.html index d3455a6..9883839 100644 --- a/code/templates/editor.html +++ b/code/templates/editor.html @@ -12,13 +12,13 @@ title="File name to write. Must end in .txt to later edit." value="{{ filename | safe }}" onclick="clear_text(this.id,'paste.txt')">
- - Preview + + Preview Cancel
- -
+ +
@@ -29,6 +29,7 @@ var md = new Remarkable({ linkify: true }); - updateEditorPreview(); + var editorHash = hashCode(document.getElementById("editor_area").value); + updateEditor() {% endblock %}