From a994e034f70973d31e6c5471bf69a30052797003 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 11 May 2020 02:07:21 +0200 Subject: [PATCH] lol wow --- copyparty/web/md2.css | 3 +++ copyparty/web/md2.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/copyparty/web/md2.css b/copyparty/web/md2.css index 35e26e01..c0239c3c 100644 --- a/copyparty/web/md2.css +++ b/copyparty/web/md2.css @@ -45,6 +45,9 @@ html.dark #mt { background: #f97; border-radius: .15em; } +#save.disabled { + opacity: .4; +} #helpbox { display: none; position: fixed; diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js index 730ba1a0..f93b9296 100644 --- a/copyparty/web/md2.js +++ b/copyparty/web/md2.js @@ -68,6 +68,13 @@ var nlines = 0; dom_ref.innerHTML = html.join('\n'); map_src = genmap(dom_ref); 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(); })(); @@ -158,14 +165,14 @@ redraw = (function () { function save(e) { if (e) e.preventDefault(); 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'); 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')) { alert('ok, aborted'); return; @@ -264,6 +271,7 @@ function save_chk() { last_modified = this.lastmod; server_md = this.txt; + dom_src.oninput(); 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'); @@ -348,7 +356,7 @@ function md_header(dedent) { } -// hotkeys +// hotkeys / toolbar (function () { function keydown(ev) { ev = ev || window.event; @@ -371,6 +379,7 @@ function md_header(dedent) { } } document.onkeydown = keydown; + document.getElementById('save').onclick = save; })();