active menu

This commit is contained in:
Kavalar 2024-09-04 14:35:29 +03:00
parent 1f34860cfd
commit 68bf73e764
4 changed files with 37 additions and 15 deletions

View File

@ -72,6 +72,14 @@ class Request
return $this->host; return $this->host;
} }
/**
* @return false|array|int|string|null
*/
public static function getUrlPath(): false|array|int|string|null
{
return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
}
/** /**
* Возвращает true если шифрование https, иначе false. * Возвращает true если шифрование https, иначе false.

View File

@ -47,6 +47,20 @@ class Menu extends Model
return false; return false;
} }
public static function hasActiveChild(int $id): bool
{
$child = self::getChild($id);
if (!$child->isEmpty()){
foreach ($child as $item){
if ($item->url === \kernel\Request::getUrlPath()){
return true;
}
}
}
return false;
}
/** /**
* @return string[] * @return string[]
*/ */

View File

@ -1,11 +1,11 @@
(function($) { (function ($) {
"use strict"; "use strict";
var fullHeight = function() { var fullHeight = function () {
$('.js-fullheight').css('height', $(window).height()); $('.js-fullheight').css('height', $(window).height());
$(window).resize(function(){ $(window).resize(function () {
$('.js-fullheight').css('height', $(window).height()); $('.js-fullheight').css('height', $(window).height());
}); });

View File

@ -9,16 +9,16 @@
if ($child): ?> if ($child): ?>
<li> <li>
<a href="#item<?=$item->id?>" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"><?= $item->label ?></a> <a href="#item<?=$item->id?>" data-toggle="collapse" aria-expanded="false" class="dropdown-toggle"><?= $item->label ?></a>
<ul class="collapse list-unstyled" id="item<?=$item->id?>"> <ul class="collapse list-unstyled <?= \kernel\models\Menu::hasActiveChild($item->id) ? "show" : "" ?>" id="item<?=$item->id?>">
<?php foreach ($child as $subitem): ?> <?php foreach ($child as $subitem): ?>
<li> <li class="<?= $subitem->url === \kernel\Request::getUrlPath() ? "active" : "" ?>">
<a href="<?= $subitem->url ?>"><?= $subitem->label ?></a> <a href="<?= $subitem->url ?>"><?= $subitem->label ?></a>
</li> </li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
</li> </li>
<?php else: ?> <?php else: ?>
<li> <li class="<?= $item->url === \kernel\Request::getUrlPath() ? "active" : "" ?>">
<a href="<?= $item->url ?>"><?= $item->label ?></a> <a href="<?= $item->url ?>"><?= $item->label ?></a>
</li> </li>
<?php endif; ?> <?php endif; ?>