diff options
author | Thedro Neely <thedroneely@gmail.com> | 2018-11-18 19:40:35 -0500 |
---|---|---|
committer | Thedro Neely <thedroneely@gmail.com> | 2018-11-18 19:40:35 -0500 |
commit | 25c93f376c0cce76204600a654a504929b14602d (patch) | |
tree | d83a88d60c68d40ad7b864417df636a0de1004ab /model | |
parent | 1384deefbf2ac03ffa52ef67cd1fbfe879fee0e7 (diff) | |
download | edwinmattiacci.com-25c93f376c0cce76204600a654a504929b14602d.tar.gz edwinmattiacci.com-25c93f376c0cce76204600a654a504929b14602d.tar.bz2 edwinmattiacci.com-25c93f376c0cce76204600a654a504929b14602d.zip |
model/Navigator: Refactor navigator class
Diffstat (limited to 'model')
-rw-r--r-- | model/Navigator.php | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/model/Navigator.php b/model/Navigator.php index a8150e9..d146c13 100644 --- a/model/Navigator.php +++ b/model/Navigator.php @@ -29,7 +29,8 @@ function navBar() } $navbar = [ - $location => ['link' => $uri], //Hidden link shown in mobile responsive mode. + //Hidden link shown in mobile responsive mode. + $location => ['link' => $uri], 'Home' => ['link' => '/'], 'Posts' => ['link' => '/posts/'], 'Feedback' => ['link' => '/feedback/'], @@ -39,13 +40,6 @@ function navBar() foreach ($navbar as $title => $route) { $append =''; - // Bad css coding results in this... - // Due to the strpos check method for which page is active, - // "Home" is always active because "/" is always in - // the request uri. Run a seperate check for the home - // page and continue with the looped check. Will refactor - // to make the exception the rule. - if ($title === 'Home') { if ($route['link'] === $_SERVER['REQUEST_URI']) { echo '<a class="active" href="/">Home</a>'; @@ -78,9 +72,24 @@ function navBarPost() foreach ($navbar as $title => $route) { $append =''; - if ($route['uri'] === $_SERVER['REQUEST_URI']) { - $append = 'class="active" '; + + if ($_SERVER['REQUEST_URI'] === '/' + && $_SERVER['REQUEST_URI'] === $route['uri'] + ) { + $append = 'active'; + } + + if (!empty(trim($route['uri'], '/')) + && strpos( + trim($_SERVER['REQUEST_URI'], '/'), + trim($route['uri'], '/') + ) !== false + ) { + $append = 'active'; }; - echo str_repeat("\t", 4) . '<a ' . $append . 'href="' . $route['uri'] . '" ' . 'onclick="closeNav()"' . '>' . $title . '</a>' . "\n"; + + echo str_repeat("\t", 4) . '<a class="' . $append . '" ' + . 'href="' . $route['uri'] . '" ' . 'onclick="closeNav()"' + . '>' . $title . '</a>' . "\n"; } } |