Skip to content

Commit

Permalink
Improve mobile experience
Browse files Browse the repository at this point in the history
  • Loading branch information
xremming committed Dec 11, 2023
1 parent 39a2906 commit 0c2b9c8
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 125 deletions.
10 changes: 5 additions & 5 deletions public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ hr {
background-color: var(--color-background-primary);
}

.hide-toc {
display: none;
}

@media screen and (max-width: 576px) {
.toc {
position: fixed;
margin-top: var(--header-height);
padding-bottom: calc(var(--header-height) + 1rem);
padding-bottom: calc(var(--header-height) + 10rem);
box-shadow: 0 0 16px;
}
}

.hide-toc {
display: none;
}

@media print {
.toc {
display: none;
Expand Down
249 changes: 129 additions & 120 deletions template/index.html
Original file line number Diff line number Diff line change
@@ -1,120 +1,129 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="referrer" content="origin">
<meta http-equiv="Content-Security-Policy" content="{{ .CSP }}">

<link rel="dns-prefetch" href="https://svgs.scryfall.io">
<link rel="preconnect" href="https://svgs.scryfall.io">

<link rel="preload" href="style.css?nonce={{ .Nonce }}" as="style">
<link rel="stylesheet" href="style.css?nonce={{ .Nonce }}">

<title>{{ .Title }}</title>
<meta name="description" content="{{ .Description }}">

<meta property="og:type" content="website">
<meta property="og:url" content="https://rulesraker.com">
<meta property="og:title" content="{{ .Title }}">
<meta property="og:description" content="{{ .Description }}">
<meta property="og:image" content="https://rulesraker.com/card.jpg?nonce={{ .Nonce }}">

<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="{{ .Title }}">
<meta name="twitter:description" content="{{ .Description }}">
<meta name="twitter:image" content="https://rulesraker.com/card.jpg?nonce={{ .Nonce }}">
</head>

<body>
<div class="container">
<nav id="toc" class="toc">
{{ range .Rules }}
{{ if eq .Type "SubRule" }}
{{ continue }}
{{ end }}

{{ if eq .Type "Rule" }}
{{ if and
(or
(startsWith "701." .ID)
(startsWith "702." .ID))
(not (startsWith "701.1" .ID))
(not (startsWith "702.1" .ID))
| not
}}
{{ continue }}
{{ end }}
{{ end }}

{{ $class := printf "toc-%s" (lower .Type) }}
<div class="toc-element {{ $class }}">
<div class="toc-number">{{ .Number }}</div>
<div class="toc-name"><a href="#{{ .ID }}">{{ index .Body 0 }}</a></div>
</div>
{{ end }}
</nav>

<div id="content" class="content">
<header class="header">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" id="toggle-toc" class="toggle-toc-button" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5"/>
</svg>
<input class="search" disabled placeholder="coming soon...">
<div class="buffer"></div>
</header>

<div class="main-container">
<main class="main">
<h2 class="main-heading"><i>Magic: the Gathering</i> Comprehensive Rules</h2>

<header class="rules-header text">
<p>
Changes may have been made to this document since its publication. You can
download the most recent version from the <a href="{{ .RulesURL }}">Magic rules website</a>.
</p>
<p>
These rules are effective as of <time datetime="{{ .EffectiveDate | formatTime "2006-01-02" }}">{{ .EffectiveDate | formatTime "January 2, 2006" }}<time>.
</p>
<p>
Rulesraker is unofficial Fan Content permitted under the Fan Content
Policy. Not approved/endorsed by Wizards. Portions of the materials used
are property of Wizards of the Coast. ©Wizards of the Coast LLC.
</p>
</header>

<article class="rules text">
{{ range .Rules }}
{{ template "rule.html" . }}
{{ end }}
</article>

<hr>

<footer class="credits text">
{{ range .Credits }}
<p>{{ . | newlineToBR }}</p>
{{ end }}
</footer>
</main>
</div>
</div>

</div>

<script nonce="{{ .Nonce }}" async>
window.onload = function() {
var toc = document.querySelector("#toc");
var toggleToc = document.querySelector("#toggle-toc");

toggleToc.addEventListener("click", function() {
console.log("toggle toc");
toc.classList.toggle("hide-toc");
});
};
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="referrer" content="origin">
<meta http-equiv="Content-Security-Policy" content="{{ .CSP }}">

<link rel="dns-prefetch" href="https://svgs.scryfall.io">
<link rel="preconnect" href="https://svgs.scryfall.io">

<link rel="preload" href="style.css?nonce={{ .Nonce }}" as="style">
<link rel="stylesheet" href="style.css?nonce={{ .Nonce }}">

<title>{{ .Title }}</title>
<meta name="description" content="{{ .Description }}">

<meta property="og:type" content="website">
<meta property="og:url" content="https://rulesraker.com">
<meta property="og:title" content="{{ .Title }}">
<meta property="og:description" content="{{ .Description }}">
<meta property="og:image" content="https://rulesraker.com/card.jpg?nonce={{ .Nonce }}">

<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="{{ .Title }}">
<meta name="twitter:description" content="{{ .Description }}">
<meta name="twitter:image" content="https://rulesraker.com/card.jpg?nonce={{ .Nonce }}">
</head>

<body>
<div class="container">
<nav id="toc" class="toc">
{{ range .Rules }}
{{ if eq .Type "SubRule" }}
{{ continue }}
{{ end }}

{{ if eq .Type "Rule" }}
{{ if and
(or
(startsWith "701." .ID)
(startsWith "702." .ID))
(not (startsWith "701.1" .ID))
(not (startsWith "702.1" .ID))
| not
}}
{{ continue }}
{{ end }}
{{ end }}

{{ $class := printf "toc-%s" (lower .Type) }}
<div class="toc-element {{ $class }}">
<div class="toc-number">{{ .Number }}</div>
<div class="toc-name"><a href="#{{ .ID }}">{{ index .Body 0 }}</a></div>
</div>
{{ end }}
</nav>

<div id="content" class="content">
<header class="header">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" id="toggle-toc" class="toggle-toc-button" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5"/>
</svg>
<input class="search" disabled placeholder="coming soon...">
<div class="buffer"></div>
</header>

<div class="main-container">
<main class="main">
<h2 class="main-heading"><i>Magic: the Gathering</i> Comprehensive Rules</h2>

<header class="rules-header text">
<p>
Changes may have been made to this document since its publication. You can
download the most recent version from the <a href="{{ .RulesURL }}">Magic rules website</a>.
</p>
<p>
These rules are effective as of <time datetime="{{ .EffectiveDate | formatTime "2006-01-02" }}">{{ .EffectiveDate | formatTime "January 2, 2006" }}<time>.
</p>
<p>
Rulesraker is unofficial Fan Content permitted under the Fan Content
Policy. Not approved/endorsed by Wizards. Portions of the materials used
are property of Wizards of the Coast. ©Wizards of the Coast LLC.
</p>
</header>

<article class="rules text">
{{ range .Rules }}
{{ template "rule.html" . }}
{{ end }}
</article>

<hr>

<footer class="credits text">
{{ range .Credits }}
<p>{{ . | newlineToBR }}</p>
{{ end }}
</footer>
</main>
</div>
</div>

</div>

<script nonce="{{ .Nonce }}" async>
window.onload = function() {
var isSmallScreen = window.matchMedia("(max-width: 576px)");
var tocEl = document.querySelector("#toc");
var toggleTocEl = document.querySelector("#toggle-toc");

function toggleToc() {
console.log("toggling toc");
tocEl.classList.toggle("hide-toc");
}

tocEl.addEventListener("click", function() {
if (isSmallScreen.matches) {
toggleToc();
}
});

toggleTocEl.addEventListener("click", toggleToc);
};
</script>
</body>
</html>

0 comments on commit 0c2b9c8

Please sign in to comment.