From f3dc6a217b7c1cb036bcff9ae2d873bd46837857 Mon Sep 17 00:00:00 2001
From: ed
Date: Mon, 26 Jul 2021 19:20:36 +0200
Subject: [PATCH] use the new toast in md-editor
---
copyparty/web/browser.css | 4 +--
copyparty/web/md.css | 58 ++++++++++++++++++++++++++++++++++++---
copyparty/web/md.html | 24 ++++++++--------
copyparty/web/md2.css | 17 +-----------
copyparty/web/md2.js | 55 +++++--------------------------------
copyparty/web/mde.html | 19 ++++++-------
copyparty/web/splash.html | 2 +-
copyparty/web/util.js | 22 +++++++--------
8 files changed, 97 insertions(+), 104 deletions(-)
diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css
index 8421c5ab..f3e477ad 100644
--- a/copyparty/web/browser.css
+++ b/copyparty/web/browser.css
@@ -65,7 +65,7 @@ body {
border-color: #8e4;
}
#toast.warn {
- background: #a70;
+ background: #970;
border-color: #fc0;
}
#toast.err {
@@ -1033,7 +1033,7 @@ html.light #tt {
}
html.light #tt,
html.light #toast {
- box-shadow: 0 .3em 1em rgba(0,0,0,0.4);
+ box-shadow: 0 .3em 1em rgba(0,0,0,0.4);
}
html.light #tt code {
background: #060;
diff --git a/copyparty/web/md.css b/copyparty/web/md.css
index 2dcf0e00..6d13194c 100644
--- a/copyparty/web/md.css
+++ b/copyparty/web/md.css
@@ -8,20 +8,52 @@ html, body {
font-family: sans-serif;
line-height: 1.5em;
}
-#tt {
+#tt, #toast {
position: fixed;
max-width: 34em;
background: #222;
border: 0 solid #777;
+ box-shadow: 0 .2em .5em #222;
+ border-radius: .4em;
+ z-index: 9001;
+}
+#tt {
overflow: hidden;
margin-top: 1em;
padding: 0 1.3em;
height: 0;
opacity: .1;
transition: opacity 0.14s, height 0.14s, padding 0.14s;
- box-shadow: 0 .2em .5em #222;
- border-radius: .4em;
- z-index: 9001;
+}
+#toast {
+ 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 {
padding: 0 2em;
@@ -49,6 +81,24 @@ html, body {
#tt em {
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 {
display: none;
}
diff --git a/copyparty/web/md.html b/copyparty/web/md.html
index ae085441..9a41aa58 100644
--- a/copyparty/web/md.html
+++ b/copyparty/web/md.html
@@ -131,18 +131,18 @@ var md_opt = {
};
(function () {
- var btn = document.getElementById("lightswitch");
- var toggle = function (e) {
- if (e) e.preventDefault();
- var dark = !document.documentElement.getAttribute("class");
- document.documentElement.setAttribute("class", dark ? "dark" : "");
- btn.innerHTML = "go " + (dark ? "light" : "dark");
- if (window.localStorage)
- localStorage.setItem('lightmode', dark ? 0 : 1);
- };
- btn.onclick = toggle;
- if (window.localStorage && localStorage.getItem('lightmode') != 1)
- toggle();
+ var l = localStorage,
+ drk = l.getItem('lightmode') != 1,
+ btn = document.getElementById("lightswitch"),
+ f = function (e) {
+if (e) { e.preventDefault(); drk = !drk; }
+document.documentElement.setAttribute("class", drk? "dark":"light");
+btn.innerHTML = "go " + (drk ? "light":"dark");
+l.setItem('lightmode', drk? 0:1);
+ };
+
+ btn.onclick = f;
+ f();
})();
diff --git a/copyparty/web/md2.css b/copyparty/web/md2.css
index 91519cc9..25ad7942 100644
--- a/copyparty/web/md2.css
+++ b/copyparty/web/md2.css
@@ -84,13 +84,10 @@ html.dark #save.force-save {
#save.disabled {
opacity: .4;
}
-#helpbox,
-#toast {
+#helpbox {
background: #f7f7f7;
border-radius: .4em;
z-index: 9001;
-}
-#helpbox {
display: none;
position: fixed;
padding: 2em;
@@ -107,19 +104,7 @@ html.dark #save.force-save {
}
html.dark #helpbox {
box-shadow: 0 .5em 2em #444;
-}
-html.dark #helpbox,
-html.dark #toast {
background: #222;
border: 1px solid #079;
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;
-}
diff --git a/copyparty/web/md2.js b/copyparty/web/md2.js
index a4cb7d34..68f63375 100644
--- a/copyparty/web/md2.js
+++ b/copyparty/web/md2.js
@@ -236,7 +236,7 @@ function Modpoll() {
var skip = null;
- if (ebi('toast'))
+ if (toast.visible)
skip = 'toast';
else if (this.skip_one)
@@ -293,8 +293,7 @@ function Modpoll() {
"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",
- 36, "
" + msg.join('
\n') + '
'); + return toast.warn(0, "" + msg.join('
\n') + '
'); } console.log('modpoll eq'); @@ -323,16 +322,12 @@ function save(e) { var save_btn = ebi("save"), save_cls = save_btn.getAttribute('class') + ''; - if (save_cls.indexOf('disabled') >= 0) { - toast(true, ";font-size:2em;color:#c90", 9, "no changes"); - return; - } + if (save_cls.indexOf('disabled') >= 0) + return toast.inf(2000, "no changes"); 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; - } + if (force && !confirm('confirm that you wish to lose the changes made on the server since you opened this document')) + return alert('ok, aborted'); var txt = dom_src.value; @@ -443,46 +438,10 @@ function savechk_cb() { last_modified = this.lastmod; server_md = this.txt; draw_md(); - toast(true, ";font-size:6em;font-family:serif;color:#9b4", 4, - 'OK✔️' + this.ntry + ''); - + toast.ok(2000, 'save OK' + (this.ntry ? '