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.
47 lines
1.2 KiB
47 lines
1.2 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 init() {
|
|
let mdnotesdiv = document.getElementById('mdnotes');
|
|
mdnotesdiv.addEventListener('input', onedit);
|
|
let saveButton = document.getElementById('saveButton');
|
|
saveButton.addEventListener('click', onsave);
|
|
loadButton.addEventListener('click', onload);
|
|
taButton.addEventListener('click', ontextarea);
|
|
|
|
onload();
|
|
}
|
|
|
|
init(); |