diff options
| author | winter | 2025-01-01 17:41:22 +0000 |
|---|---|---|
| committer | winter | 2025-01-01 17:41:22 +0000 |
| commit | 02a6acd4cfddaecd9075b706fdbdc0396d76d8c3 (patch) | |
| tree | 8b18236ba74c260774350a330798aaaced215882 | |
| parent | 4cd7017da9a37e5b9f38c3f50dd1c904ea41cbcb (diff) | |
stuff
| -rw-r--r-- | Digitigrade/Router.php | 4 | ||||
| -rw-r--r-- | static/language-switch.js | 3 | ||||
| -rw-r--r-- | static/style.css | 5 | ||||
| -rw-r--r-- | templates/navigation_links.php | 12 | ||||
| -rw-r--r-- | templates/skeleton.php | 19 |
5 files changed, 33 insertions, 10 deletions
diff --git a/Digitigrade/Router.php b/Digitigrade/Router.php index e8bea48..0682b76 100644 --- a/Digitigrade/Router.php +++ b/Digitigrade/Router.php @@ -14,6 +14,10 @@ class Router extends Singleton { $this->routes = []; } + public function getCurrentPath(): string { + return $this->requestPath; + } + /** * Processes and sends a response to the current request * @return void diff --git a/static/language-switch.js b/static/language-switch.js new file mode 100644 index 0000000..a357ef0 --- /dev/null +++ b/static/language-switch.js @@ -0,0 +1,3 @@ +addEventListener("languagechange", (e) => { + location.reload(); +}); diff --git a/static/style.css b/static/style.css index 07960ab..15f2665 100644 --- a/static/style.css +++ b/static/style.css @@ -53,12 +53,15 @@ nav { padding: 0; > li { display: inline; - > a { + > .navlink { border-radius: 4px; background: #fff3; padding: 4px 8px; color: white; text-decoration: none; + &.disabled { + opacity: 0.6; + } } } } diff --git a/templates/navigation_links.php b/templates/navigation_links.php new file mode 100644 index 0000000..1540491 --- /dev/null +++ b/templates/navigation_links.php @@ -0,0 +1,12 @@ +<?php +use Digitigrade\Router; +?> +<ul> + <?php foreach ($links as $href => $name): ?> + <?php if (Router::getInstance()->getCurrentPath() == $href): ?> + <li><span class="navlink disabled"><?= $name ?></span></li> + <?php else: ?> + <li><a class="navlink" href="<?= $href ?>"><?= $name ?></a></li> + <?php endif; ?> + <?php endforeach; ?> +</ul>
\ No newline at end of file diff --git a/templates/skeleton.php b/templates/skeleton.php index 94bc2f2..8ac1549 100644 --- a/templates/skeleton.php +++ b/templates/skeleton.php @@ -11,21 +11,22 @@ $user = Digitigrade\Model\UserAccount::findByCurrentSession(); <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:FILL@0..1"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="https://unpkg.com/htmx.org@2.0.4"></script> + <script src="/static/language-switch.js" defer></script> </head> <body hx-boost="true"> <header> <nav> - <ul> - <li><a href="/feed/global"><?= __('timeline.global.shortName') ?></a></li> - <li><a href="/feed/local"><?= __('timeline.local.shortName') ?></a></li> - </ul> + <?php call_template('navigation_links', ['links' => [ + '/feed/global' => __('timeline.global.shortName'), + '/feed/local' => __('timeline.local.shortName'), + ]]); ?> <span id="siteTitle"><?= __('digitigrade') ?></span> - <?php if ($user == null): ?> - <ul> - <li><a href="/login"><?= __('navigation.login') ?></a></li> - </ul> - <?php else: ?> + <?php if ($user == null): + call_template('navigation_links', ['links' => [ + '/login' => __('navigation.login') + ]]); + else: ?> <div> <?php call_template('actor_avatar', ['actor' => $user->actor]) ?> <?= $user->actor->displayName ?> |
