This commit is contained in:
ed 2020-05-11 02:07:21 +02:00
parent 2801c04f2e
commit a994e034f7
2 changed files with 16 additions and 4 deletions

View file

@ -45,6 +45,9 @@ html.dark #mt {
background: #f97; background: #f97;
border-radius: .15em; border-radius: .15em;
} }
#save.disabled {
opacity: .4;
}
#helpbox { #helpbox {
display: none; display: none;
position: fixed; position: fixed;

View file

@ -68,6 +68,13 @@ var nlines = 0;
dom_ref.innerHTML = html.join('\n'); dom_ref.innerHTML = html.join('\n');
map_src = genmap(dom_ref); map_src = genmap(dom_ref);
map_pre = genmap(dom_pre); map_pre = genmap(dom_pre);
var sb = document.getElementById('save');
var cl = (sb.getAttribute('class') + '').replace(/ disabled/, "");
if (src == server_md)
cl += ' disabled';
sb.setAttribute('class', cl);
} }
dom_src.oninput(); dom_src.oninput();
})(); })();
@ -158,14 +165,14 @@ redraw = (function () {
function save(e) { function save(e) {
if (e) e.preventDefault(); if (e) e.preventDefault();
var save_btn = document.getElementById("save"), var save_btn = document.getElementById("save"),
save_cls = save_btn.getAttribute('class'); save_cls = save_btn.getAttribute('class') + '';
if (save_cls == 'disabled') { if (save_cls.indexOf('disabled') >= 0) {
alert('there is nothing to save'); alert('there is nothing to save');
return; return;
} }
var force = save_cls == 'force-save'; var force = (save_cls.indexOf('force-save') >= 0);
if (force && !confirm('confirm that you wish to lose the changes made on the server since you opened this document')) { if (force && !confirm('confirm that you wish to lose the changes made on the server since you opened this document')) {
alert('ok, aborted'); alert('ok, aborted');
return; return;
@ -264,6 +271,7 @@ function save_chk() {
last_modified = this.lastmod; last_modified = this.lastmod;
server_md = this.txt; server_md = this.txt;
dom_src.oninput();
var ok = document.createElement('div'); var ok = document.createElement('div');
ok.setAttribute('style', 'font-size:6em;font-family:serif;font-weight:bold;color:#cf6;background:#444;border-radius:.3em;padding:.6em 0;position:fixed;top:30%;left:calc(50% - 2em);width:4em;text-align:center;z-index:9001;transition:opacity 0.2s ease-in-out;opacity:1'); ok.setAttribute('style', 'font-size:6em;font-family:serif;font-weight:bold;color:#cf6;background:#444;border-radius:.3em;padding:.6em 0;position:fixed;top:30%;left:calc(50% - 2em);width:4em;text-align:center;z-index:9001;transition:opacity 0.2s ease-in-out;opacity:1');
@ -348,7 +356,7 @@ function md_header(dedent) {
} }
// hotkeys // hotkeys / toolbar
(function () { (function () {
function keydown(ev) { function keydown(ev) {
ev = ev || window.event; ev = ev || window.event;
@ -371,6 +379,7 @@ function md_header(dedent) {
} }
} }
document.onkeydown = keydown; document.onkeydown = keydown;
document.getElementById('save').onclick = save;
})(); })();