use the new toast in md-editor

This commit is contained in:
ed 2021-07-26 19:20:36 +02:00
parent 7671d791fa
commit f3dc6a217b
8 changed files with 97 additions and 104 deletions

View file

@ -65,7 +65,7 @@ body {
border-color: #8e4; border-color: #8e4;
} }
#toast.warn { #toast.warn {
background: #a70; background: #970;
border-color: #fc0; border-color: #fc0;
} }
#toast.err { #toast.err {

View file

@ -8,20 +8,52 @@ html, body {
font-family: sans-serif; font-family: sans-serif;
line-height: 1.5em; line-height: 1.5em;
} }
#tt { #tt, #toast {
position: fixed; position: fixed;
max-width: 34em; max-width: 34em;
background: #222; background: #222;
border: 0 solid #777; border: 0 solid #777;
box-shadow: 0 .2em .5em #222;
border-radius: .4em;
z-index: 9001;
}
#tt {
overflow: hidden; overflow: hidden;
margin-top: 1em; margin-top: 1em;
padding: 0 1.3em; padding: 0 1.3em;
height: 0; height: 0;
opacity: .1; opacity: .1;
transition: opacity 0.14s, height 0.14s, padding 0.14s; transition: opacity 0.14s, height 0.14s, padding 0.14s;
box-shadow: 0 .2em .5em #222; }
border-radius: .4em; #toast {
z-index: 9001; top: 1.4em;
right: -1em;
padding: 1em 1.3em;
border-width: .4em 0;
transform: translateX(100%);
transition: all .3s cubic-bezier(.2, 1.2, .5, 1);
text-shadow: 1px 1px 0 #000;
color: #fff;
}
#toast.vis {
right: 1.3em;
transform: unset;
}
#toast.inf {
background: #07a;
border-color: #0be;
}
#toast.ok {
background: #4a0;
border-color: #8e4;
}
#toast.warn {
background: #970;
border-color: #fc0;
}
#toast.err {
background: #b00;
border-color: #f00;
} }
#tt.b { #tt.b {
padding: 0 2em; padding: 0 2em;
@ -49,6 +81,24 @@ html, body {
#tt em { #tt em {
color: #f6a; color: #f6a;
} }
html.light #tt {
background: #fff;
border-color: #888 #000 #777 #000;
}
html.light #tt,
html.light #toast {
box-shadow: 0 .3em 1em rgba(0,0,0,0.4);
}
html.light #tt code {
background: #060;
color: #fff;
}
html.light #tt em {
color: #d38;
}
#mtw { #mtw {
display: none; display: none;
} }

View file

@ -131,18 +131,18 @@ var md_opt = {
}; };
(function () { (function () {
var btn = document.getElementById("lightswitch"); var l = localStorage,
var toggle = function (e) { drk = l.getItem('lightmode') != 1,
if (e) e.preventDefault(); btn = document.getElementById("lightswitch"),
var dark = !document.documentElement.getAttribute("class"); f = function (e) {
document.documentElement.setAttribute("class", dark ? "dark" : ""); if (e) { e.preventDefault(); drk = !drk; }
btn.innerHTML = "go " + (dark ? "light" : "dark"); document.documentElement.setAttribute("class", drk? "dark":"light");
if (window.localStorage) btn.innerHTML = "go " + (drk ? "light":"dark");
localStorage.setItem('lightmode', dark ? 0 : 1); l.setItem('lightmode', drk? 0:1);
}; };
btn.onclick = toggle;
if (window.localStorage && localStorage.getItem('lightmode') != 1) btn.onclick = f;
toggle(); f();
})(); })();
</script> </script>

View file

@ -84,13 +84,10 @@ html.dark #save.force-save {
#save.disabled { #save.disabled {
opacity: .4; opacity: .4;
} }
#helpbox, #helpbox {
#toast {
background: #f7f7f7; background: #f7f7f7;
border-radius: .4em; border-radius: .4em;
z-index: 9001; z-index: 9001;
}
#helpbox {
display: none; display: none;
position: fixed; position: fixed;
padding: 2em; padding: 2em;
@ -107,19 +104,7 @@ html.dark #save.force-save {
} }
html.dark #helpbox { html.dark #helpbox {
box-shadow: 0 .5em 2em #444; box-shadow: 0 .5em 2em #444;
}
html.dark #helpbox,
html.dark #toast {
background: #222; background: #222;
border: 1px solid #079; border: 1px solid #079;
border-width: 1px 0; border-width: 1px 0;
} }
#toast {
font-weight: bold;
text-align: center;
padding: .6em 0;
position: fixed;
top: 30%;
transition: opacity 0.2s ease-in-out;
opacity: 1;
}

View file

@ -236,7 +236,7 @@ function Modpoll() {
var skip = null; var skip = null;
if (ebi('toast')) if (toast.visible)
skip = 'toast'; skip = 'toast';
else if (this.skip_one) else if (this.skip_one)
@ -293,8 +293,7 @@ function Modpoll() {
"You can click this message to ignore and contnue." "You can click this message to ignore and contnue."
]; ];
return toast(false, "box-shadow:0 1em 2em rgba(64,64,64,0.8);font-weight:normal", return toast.warn(0, "<p>" + msg.join('</p>\n<p>') + '</p>');
36, "<p>" + msg.join('</p>\n<p>') + '</p>');
} }
console.log('modpoll eq'); console.log('modpoll eq');
@ -323,16 +322,12 @@ function save(e) {
var save_btn = ebi("save"), var save_btn = ebi("save"),
save_cls = save_btn.getAttribute('class') + ''; save_cls = save_btn.getAttribute('class') + '';
if (save_cls.indexOf('disabled') >= 0) { if (save_cls.indexOf('disabled') >= 0)
toast(true, ";font-size:2em;color:#c90", 9, "no changes"); return toast.inf(2000, "no changes");
return;
}
var force = (save_cls.indexOf('force-save') >= 0); 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'); return alert('ok, aborted');
return;
}
var txt = dom_src.value; var txt = dom_src.value;
@ -443,46 +438,10 @@ function savechk_cb() {
last_modified = this.lastmod; last_modified = this.lastmod;
server_md = this.txt; server_md = this.txt;
draw_md(); draw_md();
toast(true, ";font-size:6em;font-family:serif;color:#9b4", 4, toast.ok(2000, 'save OK' + (this.ntry ? '<br />attempt ' + this.ntry : ''));
'OK✔<span style="font-size:.2em;color:#999;position:absolute">' + this.ntry + '</span>');
modpoll.disabled = false; modpoll.disabled = false;
} }
function toast(autoclose, style, width, msg) {
var ok = ebi("toast");
if (ok)
ok.parentNode.removeChild(ok);
style = "width:" + width + "em;left:calc(50% - " + (width / 2) + "em);" + style;
ok = mknod('div');
ok.setAttribute('id', 'toast');
ok.setAttribute('style', style);
ok.innerHTML = msg;
var parent = ebi('m');
document.documentElement.appendChild(ok);
var hide = function (delay) {
delay = delay || 0;
setTimeout(function () {
ok.style.opacity = 0;
}, delay);
setTimeout(function () {
if (ok.parentNode)
ok.parentNode.removeChild(ok);
}, delay + 250);
}
ok.onclick = function () {
hide(0);
};
if (autoclose)
hide(500);
}
// firefox bug: initial selection offset isn't cleared properly through js // firefox bug: initial selection offset isn't cleared properly through js
var ff_clearsel = (function () { var ff_clearsel = (function () {

View file

@ -30,16 +30,15 @@ var md_opt = {
}; };
var lightswitch = (function () { var lightswitch = (function () {
var fun = function () { var l = localStorage,
var dark = !document.documentElement.getAttribute("class"); drk = l.getItem('lightmode') != 1,
document.documentElement.setAttribute("class", dark ? "dark" : ""); f = function (e) {
if (window.localStorage) if (e) drk = !drk;
localStorage.setItem('lightmode', dark ? 0 : 1); document.documentElement.setAttribute("class", drk? "dark":"light");
l.setItem('lightmode', drk? 0:1);
}; };
if (window.localStorage && localStorage.getItem('lightmode') != 1) f();
fun(); return f;
return fun;
})(); })();
</script> </script>

View file

@ -68,7 +68,7 @@
</div> </div>
<script> <script>
if (window.localStorage && localStorage.getItem('lightmode') != 1) if (localStorage.getItem('lightmode') != 1)
document.documentElement.setAttribute("class", "dark"); document.documentElement.setAttribute("class", "dark");
</script> </script>

View file

@ -447,20 +447,15 @@ function jcp(obj) {
function sread(key) { function sread(key) {
if (window.localStorage)
return localStorage.getItem(key); return localStorage.getItem(key);
return null;
} }
function swrite(key, val) { function swrite(key, val) {
if (window.localStorage) {
if (val === undefined || val === null) if (val === undefined || val === null)
localStorage.removeItem(key); localStorage.removeItem(key);
else else
localStorage.setItem(key, val); localStorage.setItem(key, val);
} }
}
function jread(key, fb) { function jread(key, fb) {
var str = sread(key); var str = sread(key);
@ -643,6 +638,7 @@ var tt = (function () {
var toast = (function () { var toast = (function () {
var r = {}, var r = {},
te = null, te = null,
visible = false,
obj = mknod('div'); obj = mknod('div');
obj.setAttribute('id', 'toast'); obj.setAttribute('id', 'toast');
@ -652,13 +648,17 @@ var toast = (function () {
r.hide = function () { r.hide = function () {
clearTimeout(te); clearTimeout(te);
clmod(obj, 'vis'); clmod(obj, 'vis');
r.visible = false;
}; };
r.show = function (cl, ms, txt) { r.show = function (cl, ms, txt) {
clearTimeout(te); clearTimeout(te);
if (ms)
te = setTimeout(r.hide, ms); te = setTimeout(r.hide, ms);
obj.innerHTML = txt; obj.innerHTML = txt;
obj.className = cl + ' vis'; obj.className = cl + ' vis';
r.visible = true;
}; };
r.ok = function (ms, txt) { r.ok = function (ms, txt) {