summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Spragg <adam@spra.gg>2018-06-25 15:24:19 +0100
committerAdam Spragg <adam@spra.gg>2018-06-25 15:24:19 +0100
commit8637cf6add0b5be32dd58992e94d23ff1e80966c (patch)
treec4f93cc011b681cf9ce12d097aef665d0071556d
parent6fb76294b98d81fb707445770dd57f0fb356deb9 (diff)
Simplify hiding navigation items slightly
The code is now a bit longer, but it's also a bit clearer. The resulting HTML is also clearer.
-rw-r--r--html/@include.php13
-rw-r--r--html/style/main.css4
2 files changed, 13 insertions, 4 deletions
diff --git a/html/@include.php b/html/@include.php
index 2cf50d3..3966ec0 100644
--- a/html/@include.php
+++ b/html/@include.php
@@ -26,11 +26,16 @@ function site_head($title) {
function site_navitem($url, $text, $hide = false) {
$selected = $url == $_SERVER['REQUEST_URI'];
- $hbeg = $hide && !$selected ? '!--' : '';
- $hend = $hide && !$selected ? '--' : '';
- $sel = $selected ? ' class="selected"' : '';
+ $classes = [];
+ if ($selected) {
+ $classes[] = "selected";
+ }
+ if ($hide && !$selected) {
+ $classes[] = "hidden";
+ }
+ $classes = count($classes) > 0 ? (" class=\"" . implode(" ", $classes) . "\"") : "";
- return "<{$hbeg}li{$sel}><a href=\"{$url}\">{$text}</a></li{$hend}>";
+ return "<li{$classes}><a href=\"{$url}\">{$text}</a></li>";
}
/// Get the standard page header elements for the site
diff --git a/html/style/main.css b/html/style/main.css
index 1c6f46b..d277de1 100644
--- a/html/style/main.css
+++ b/html/style/main.css
@@ -30,6 +30,10 @@ a:visited {
color: inherit;
}
+.hidden {
+ display: none;
+}
+
/* * * Header * * */
body > header {
padding-top: 1px; /* Don't allow child element top margins to extend out of the header element */