toast close-handle

This commit is contained in:
ed 2021-07-27 10:05:53 +02:00
parent a362ee2246
commit e0f1cb94a5
4 changed files with 63 additions and 4 deletions

View file

@ -52,26 +52,52 @@ body {
text-shadow: 1px 1px 0 #000; text-shadow: 1px 1px 0 #000;
color: #fff; color: #fff;
} }
#toastc {
position: relative;
left: -2.35em;
margin: 0 -1.05em;
padding: .5em .8em;
border-radius: .3em 0 0 .3em;
color: #000;
text-shadow: none;
opacity: 0;
transition: all .3s cubic-bezier(.2, 1.2, .5, 1);
}
#toast.vis { #toast.vis {
right: 1.3em; right: 1.3em;
transform: unset; transform: unset;
} }
#toast.vis #toastc {
opacity: 1;
}
#toast.inf { #toast.inf {
background: #07a; background: #07a;
border-color: #0be; border-color: #0be;
} }
#toast.inf #toastc {
background: #0be;
}
#toast.ok { #toast.ok {
background: #4a0; background: #4a0;
border-color: #8e4; border-color: #8e4;
} }
#toast.ok #toastc {
background: #8e4;
}
#toast.warn { #toast.warn {
background: #970; background: #970;
border-color: #fc0; border-color: #fc0;
} }
#toast.warn #toastc {
background: #fc0;
}
#toast.err { #toast.err {
background: #900; background: #900;
border-color: #d06; border-color: #d06;
} }
#toast.err #toastc {
background: #d06;
}
#tt.b { #tt.b {
padding: 0 2em; padding: 0 2em;
border-radius: .5em; border-radius: .5em;

View file

@ -35,26 +35,53 @@ html, body {
text-shadow: 1px 1px 0 #000; text-shadow: 1px 1px 0 #000;
color: #fff; color: #fff;
} }
#toastc {
position: relative;
left: -2.35em;
margin: 0 -1.05em;
padding: .5em .8em;
border-radius: .3em 0 0 .3em;
color: #000;
text-shadow: none;
opacity: 0;
transition: all .3s cubic-bezier(.2, 1.2, .5, 1);
}
#toast.vis { #toast.vis {
right: 1.3em; right: 1.3em;
transform: unset; transform: unset;
} }
#toast.vis #toastc {
opacity: 1;
}
#toast.inf { #toast.inf {
background: #07a; background: #07a;
border-color: #0be; border-color: #0be;
} }
#toast.inf #toastc {
background: #0be;
}
#toast.ok { #toast.ok {
background: #4a0; background: #4a0;
border-color: #8e4; border-color: #8e4;
} }
#toast.ok #toastc {
background: #8e4;
}
#toast.warn { #toast.warn {
background: #970; background: #970;
border-color: #fc0; border-color: #fc0;
} }
#toast.warn #toastc {
background: #fc0;
}
#toast.err { #toast.err {
background: #900; background: #900;
border-color: #d06; border-color: #d06;
} }
#toast.err #toastc {
background: #d06;
};
}
#tt.b { #tt.b {
padding: 0 2em; padding: 0 2em;
border-radius: .5em; border-radius: .5em;

View file

@ -291,7 +291,7 @@ function Modpoll() {
"Press F5 or CTRL-R to refresh the page,<br />" + "Press F5 or CTRL-R to refresh the page,<br />" +
"replacing your document with the server copy.", "replacing your document with the server copy.",
"You can click this message to ignore and contnue." "You can close this message to ignore and contnue."
]; ];
return toast.warn(0, "<p>" + msg.join('</p>\n<p>') + '</p>'); return toast.warn(0, "<p>" + msg.join('</p>\n<p>') + '</p>');
} }

View file

@ -656,7 +656,8 @@ var toast = (function () {
obj.setAttribute('id', 'toast'); obj.setAttribute('id', 'toast');
document.body.appendChild(obj);; document.body.appendChild(obj);;
r.hide = function () { r.hide = function (e) {
ev(e);
clearTimeout(te); clearTimeout(te);
clmod(obj, 'vis'); clmod(obj, 'vis');
r.visible = false; r.visible = false;
@ -667,8 +668,14 @@ var toast = (function () {
if (ms) if (ms)
te = setTimeout(r.hide, ms * 1000); te = setTimeout(r.hide, ms * 1000);
obj.innerHTML = txt.replace(/\n/g, '<br />\n'); var html = '', hp = txt.split(/(?=<.?pre>)/i);
for (var a = 0; a < hp.length; a++)
html += hp[a].startsWith('<pre>') ? hp[a] :
hp[a].replace(/<br ?.?>\n/g, '\n').replace(/\n<br ?.?>/g, '\n').replace(/\n/g, '<br />\n');
obj.innerHTML = '<a href="#" id="toastc">x</a>' + html;
obj.className = cl + ' vis'; obj.className = cl + ' vis';
ebi('toastc').onclick = r.hide;
r.visible = true; r.visible = true;
}; };
@ -685,6 +692,5 @@ var toast = (function () {
r.show('err', ms, txt); r.show('err', ms, txt);
}; };
obj.onclick = r.hide;
return r; return r;
})(); })();