make the warning dialog a <dialog>

This commit is contained in:
rhiannon morris 2024-08-05 23:36:30 +02:00
parent 5e64e9ea1b
commit 43af72aa4d
3 changed files with 97 additions and 122 deletions

View file

@ -17,27 +17,15 @@ script (Just _) = [b|<script src=/script/nsfw-warning.js type=module></script>|]
dialog :: Maybe What -> Builder dialog :: Maybe What -> Builder
dialog Nothing = "" dialog Nothing = ""
dialog (Just what) = [b|@0 dialog (Just what) = [b|@0
<div class=dialog id=nsfw-dialog> <dialog id=nsfw-dialog>
<div class=dialog-inner>
<h1>cw: lewd art</h1> <h1>cw: lewd art</h1>
<img src=/style/stop_hand.svg>
<img class=dialog-icon src=/style/stop_hand.svg> <div> you must be an adult to view $what. no minors! </div>
<form>
<div class=dialog-message>
<p>
$what contains pornographic content that is
<strong>not suitable for minors</strong>.
<p>
by continuing, you are confirming that you are at least
<strong>eighteen years old</strong>.
</div>
<div class=dialog-buttons>
<button id=nsfw-yes class=yes>i am an adult</button> <button id=nsfw-yes class=yes>i am an adult</button>
<a href=//crouton.net referrerpolicy=no-referrer> <a href=//crouton.net referrerpolicy=no-referrer>
<button id=nsfw-no class=no>i am not</button> <button id=nsfw-no class=no>i am not</button>
</a> </a>
</div> </form>
</div> </dialog>
</div>
|] |]

View file

@ -1,21 +1,17 @@
const nsfwOk = 'nsfw-ok'; const nsfwOk = 'nsfw-ok';
const dialog = document.getElementById('nsfw-dialog')! as HTMLDialogElement;
function dismiss() {
const dialog = document.getElementById('nsfw-dialog')!;
dialog.parentElement!.removeChild(dialog);
}
function yes() { function yes() {
localStorage.setItem(nsfwOk, '1'); localStorage.setItem(nsfwOk, '1');
dismiss(); dialog.close();
} }
function setup() { function setup() {
if (localStorage.getItem(nsfwOk)) { if (!localStorage.getItem(nsfwOk)) {
dismiss(); (dialog.querySelector('#nsfw-yes') as HTMLElement).onclick = yes;
} else {
document.getElementById('nsfw-yes')!.onclick = yes;
// nsfw-no is a normal link // nsfw-no is a normal link
dialog.showModal();
} }
} }

View file

@ -1,30 +1,22 @@
.dialog { dialog {
position: fixed; &[open] {
top: 0; left: 0; &::backdrop {
width: 100vw; height: 100vh;
margin: 0;
z-index: 1000;
background: hsl(340deg, 35%, 15%, 90%); background: hsl(340deg, 35%, 15%, 90%);
color: var(--text-col); mix-blend-mode: multiply;
display: grid;
} }
~ .page { filter: blur(15px); }
.dialog ~ .page {
filter: blur(15px);
}
.dialog-inner {
place-self: center; place-self: center;
display: grid; display: grid;
grid-template: grid-template:
"header header" "icon header"
"icon text" "icon text"
"buttons buttons" "icon buttons"
/ 1fr 3fr; / 1fr 3fr;
grid-gap: 0.5em; gap: 0.5em 1.5em;
align-items: center; place-items: center;
place-content: center;
min-height: 20vh; min-height: 20vh;
max-width: 30em; max-width: 30em;
@ -33,42 +25,40 @@
background: var(--background); background: var(--background);
border: var(--border); border: var(--border);
border-radius: var(--border-radius); border-radius: var(--border-radius);
box-shadow: 0 0 50px #fff6;
} }
.dialog h1 { color: var(--text-col);
h1 {
margin: 0; margin: 0;
grid-area: header; grid-area: header;
justify-self: center;
} }
.dialog-icon { img {
height: 3em;
width: 3em;
grid-area: icon; grid-area: icon;
justify-self: center;
} }
.dialog-message { div {
grid-area: text; grid-area: text;
justify-self: start; text-align: center;
font-size: 125%; font-size: 125%;
} }
.dialog-buttons { form {
grid-area: buttons; grid-area: buttons;
justify-self: center;
display: flex; display: flex;
justify-content: center; justify-content: center;
margin-top: 1em; margin-top: 1em;
}
.dialog-buttons > * { > * {
margin: 0 1em; margin: 0 1em;
} }
}
.dialog button { button {
border: none; border: none;
border-radius: 0.75em; border-radius: 0.75em;
padding: 0.5em 1em; padding: 0.5em 1em;
@ -81,31 +71,32 @@
position: relative; position: relative;
cursor: pointer; cursor: pointer;
}
.dialog button a { a {
inset: 0; inset: 0;
width: max-content; width: max-content;
text-decoration: none; text-decoration: none;
} }
}
.dialog .yes { .yes {
background: hsl(100deg, 70%, 80%); background: hsl(100deg, 70%, 80%);
} }
.dialog .no { .no {
background: hsl(5deg, 70%, 80%); background: hsl(5deg, 70%, 80%);
} }
.dialog p { p {
text-align: left; text-align: left;
-ms-hyphens: none; -ms-hyphens: none;
hyphens: none; hyphens: none;
} }
.dialog strong { strong {
font-weight: 800; font-weight: 800;
} }
}
@media (pointer: coarse) { @media (pointer: coarse) {
button { button {