From 68bf73e76404e8eb6bbd2f686e5f6a5c7c756ccf Mon Sep 17 00:00:00 2001 From: Kavalar Date: Wed, 4 Sep 2024 14:35:29 +0300 Subject: [PATCH] active menu --- kernel/Request.php | 8 ++++++++ kernel/models/Menu.php | 14 ++++++++++++++ resources/default/js/main.js | 24 ++++++++++++------------ views/widgets/admin/menu.php | 6 +++--- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/kernel/Request.php b/kernel/Request.php index 8bdab2c..970fe57 100644 --- a/kernel/Request.php +++ b/kernel/Request.php @@ -72,6 +72,14 @@ class Request 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. diff --git a/kernel/models/Menu.php b/kernel/models/Menu.php index a1a92cc..1eb9482 100644 --- a/kernel/models/Menu.php +++ b/kernel/models/Menu.php @@ -47,6 +47,20 @@ class Menu extends Model 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[] */ diff --git a/resources/default/js/main.js b/resources/default/js/main.js index eaeed9e..57b5240 100644 --- a/resources/default/js/main.js +++ b/resources/default/js/main.js @@ -1,19 +1,19 @@ -(function($) { +(function ($) { - "use strict"; + "use strict"; - var fullHeight = function() { + var fullHeight = function () { - $('.js-fullheight').css('height', $(window).height()); - $(window).resize(function(){ - $('.js-fullheight').css('height', $(window).height()); - }); + $('.js-fullheight').css('height', $(window).height()); + $(window).resize(function () { + $('.js-fullheight').css('height', $(window).height()); + }); - }; - fullHeight(); + }; + fullHeight(); - $('#sidebarCollapse').on('click', function () { - $('#sidebar').toggleClass('active'); - }); + $('#sidebarCollapse').on('click', function () { + $('#sidebar').toggleClass('active'); + }); })(jQuery); diff --git a/views/widgets/admin/menu.php b/views/widgets/admin/menu.php index cfb08cb..78eeebd 100644 --- a/views/widgets/admin/menu.php +++ b/views/widgets/admin/menu.php @@ -9,16 +9,16 @@ if ($child): ?>
  • -