You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CheezeNotes/static/modules/mdnotes.js

56 lines
1.4 KiB

import { getStartPositionInLine, setStartPositionInLine } from './position.js';
import { formatLine, load, save } from './md.js';
function ontextarea(e) {
let ta = document.getElementById('ta');
if (ta.style.display == 'none') {
ta.style.display = 'inline';
} else {
ta.style.display = 'none';
}
}
function onsave(e) {
save(document.getElementById('ta'), document.getElementById('mdnotes'));
}
function onload(e) {
load(document.getElementById('ta'), document.getElementById('mdnotes'));
}
function onedit(e) {
let ret = getStartPositionInLine();
let line = ret[0];
let position = ret[1];
if (line.innerText == '\n') {
line.className = 'mdnotes_line';
return;
}
let newline = formatLine(line.innerText);
line.parentNode.replaceChild(newline, line);
setStartPositionInLine(newline, position);
}
function onkeyup(e) {
if (e.key == 'Escape') {
e.preventDefault();
document.getElementById('mdnotes').blur();
return false;
}
}
function init() {
let mdnotesdiv = document.getElementById('mdnotes');
mdnotesdiv.addEventListener('input', onedit);
mdnotesdiv.addEventListener('keyup', onkeyup);
let saveButton = document.getElementById('saveButton');
saveButton.addEventListener('click', onsave);
loadButton.addEventListener('click', onload);
taButton.addEventListener('click', ontextarea);
onload();
}
init();