Added wysiwyg markdown editor

master
David Zálešák 4 years ago
parent 46aacf2aaa
commit 3b6cbc143f

File diff suppressed because one or more lines are too long

@ -66,15 +66,18 @@ li::before {
section { section {
grid-area: section; grid-area: section;
margin: 1em 2em; margin: 1em 2em;
display: grid; overflow-y: hidden;
}
#editText {
display: none;
grid-template-columns: auto; grid-template-columns: auto;
grid-template-rows: auto min-content; grid-template-rows: min-content auto min-content min-content;
row-gap: 2em; overflow-y: auto;
height: 100%;
} }
textarea { textarea {
width: 100%;
height: 100%;
resize: none; resize: none;
} }
@ -122,6 +125,7 @@ sub {
display: none; display: none;
justify-items: center; justify-items: center;
align-items: center; align-items: center;
z-index: 5;
} }
.settings { .settings {
@ -130,6 +134,7 @@ sub {
height: 30vh; height: 30vh;
padding: 1.5em; padding: 1.5em;
border: 5px solid #c3c3c3; border: 5px solid #c3c3c3;
z-index: 10;
} }
form { form {

@ -6,8 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CoMato</title> <title>CoMato</title>
<link rel="stylesheet" href="css/style.css"> <link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/simplemde.min.css">
<script src="js/libs/lightning-fs.min.js" type="application/javascript"></script> <script src="js/libs/lightning-fs.min.js" type="application/javascript"></script>
<script src="js/libs/isomorphic-git.js" type="application/javascript"></script> <script src="js/libs/isomorphic-git.js" type="application/javascript"></script>
<script src="js/libs/simplemde.min.js"></script>
<script src="js/model.js" type="application/javascript"></script> <script src="js/model.js" type="application/javascript"></script>
<script src="js/view.js" type="application/javascript"></script> <script src="js/view.js" type="application/javascript"></script>
@ -35,8 +39,10 @@
<section> <section>
<textarea name="" id="" cols="30" rows="10" disabled></textarea> <div id="editText">
<button disabled id="saveBtn">Save</button> <textarea name="" id="editor" cols="30" rows="10" disabled></textarea>
<button disabled id="saveBtn">Save</button>
</div>
</section> </section>
<footer> <footer>

@ -10,7 +10,6 @@ class Controller {
var settingsBtn = document.getElementsByClassName("settingsBtn")[0]; var settingsBtn = document.getElementsByClassName("settingsBtn")[0];
var settingsClose = document.getElementsByClassName("close"); var settingsClose = document.getElementsByClassName("close");
var settingsSubmit = document.getElementById("settingsSubmit"); var settingsSubmit = document.getElementById("settingsSubmit");
var textArea = document.getElementsByTagName("textarea")[0];
var saveBtn = document.getElementById("saveBtn"); var saveBtn = document.getElementById("saveBtn");
cloneBtn.addEventListener("click", this.cloneRep.bind(this)); cloneBtn.addEventListener("click", this.cloneRep.bind(this));
@ -20,17 +19,14 @@ class Controller {
settingsClose[i].addEventListener("click", view.closeSettings.bind(this)); settingsClose[i].addEventListener("click", view.closeSettings.bind(this));
} }
settingsSubmit.addEventListener("click", this.saveSettings.bind(this)); settingsSubmit.addEventListener("click", this.saveSettings.bind(this));
textArea.addEventListener("keyup", this.saveButton.bind(this)); view.simplemde.codemirror.on("change", this.saveButton.bind(this));
saveBtn.addEventListener("click", this.saveFile.bind(this)); saveBtn.addEventListener("click", this.saveFile.bind(this));
} }
saveButton() { saveButton() {
var textArea = document.getElementsByTagName("textarea")[0]; var textArea = this.view.simplemde;
if (textArea.value != this.openedFileValue) {
this.view.showSaveButton(true); this.view.showSaveButton(textArea.value() == this.openedFileValue);
} else {
this.view.showSaveButton(false);
}
} }
wipeFS() { wipeFS() {
@ -99,9 +95,9 @@ class Controller {
} }
saveFile() { saveFile() {
var textArea = document.getElementsByTagName("textarea")[0]; var textArea = this.view.simplemde;
this.model.saveFile(this.openedFile, textArea.value); this.model.saveFile(this.openedFile, textArea.value());
this.openedFileValue = textArea.value; this.openedFileValue = textArea.value();
this.saveButton(); this.saveButton();
this.updateFileStats(); this.updateFileStats();

File diff suppressed because one or more lines are too long

@ -1,5 +1,10 @@
class View { class View {
constructor() {} constructor() {
this.simplemde = new SimpleMDE({
element: document.getElementById("editor"),
spellChecker: false,
});
}
drawDirTree( drawDirTree(
dirtree, dirtree,
@ -57,9 +62,10 @@ class View {
} }
openFile(fileread) { openFile(fileread) {
let textArea = document.getElementsByTagName("textarea")[0]; var editText = document.getElementById("editText");
textArea.disabled = false; editText.style.display = "grid";
textArea.value = fileread;
this.simplemde.value(fileread);
} }
removeDirTree() { removeDirTree() {
@ -107,10 +113,6 @@ class View {
showSaveButton(show) { showSaveButton(show) {
var saveButton = document.getElementById("saveBtn"); var saveButton = document.getElementById("saveBtn");
if (show) { saveButton.disabled = show;
saveButton.disabled = false;
} else {
saveButton.disabled = true;
}
} }
} }