mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Modificaciones
This commit is contained in:
32
ci4/app/Helpers/menu_helper.php
Normal file
32
ci4/app/Helpers/menu_helper.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('active_route')) {
|
||||
/**
|
||||
* Devuelve 'active' si la ruta actual coincide con la proporcionada.
|
||||
*
|
||||
* @param string $routeName Nombre de la ruta definida en route_to().
|
||||
* @return string
|
||||
*/
|
||||
function active_route(string $routeName): string
|
||||
{
|
||||
try {
|
||||
return current_url() === route_to($routeName) ? 'active' : '';
|
||||
} catch (\Exception $e) {
|
||||
return ''; // Por si la ruta no existe o lanza error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('active_uri_starts_with')) {
|
||||
/**
|
||||
* Devuelve 'open active' si uri_string() comienza con el prefijo dado.
|
||||
* Útil para marcar menús padres.
|
||||
*
|
||||
* @param string $prefix Prefijo del URI, como 'config', 'catalogo', etc.
|
||||
* @return string
|
||||
*/
|
||||
function active_uri_starts_with(string $prefix): string
|
||||
{
|
||||
return str_starts_with(uri_string(), $prefix) ? 'open active' : '';
|
||||
}
|
||||
}
|
||||
@ -424,12 +424,14 @@ $picture = "/assets/img/default-user.png";
|
||||
tempAnchor.href = href;
|
||||
const linkPath = tempAnchor.pathname;
|
||||
|
||||
// Comparación exacta de ruta
|
||||
if (browserUrl === linkPath) {
|
||||
// Corrección: coincide si es igual o si browserUrl empieza con el linkPath + '/'
|
||||
if (browserUrl === linkPath || browserUrl.startsWith(linkPath + '/')) {
|
||||
const menuItem = link.closest('.menu-item');
|
||||
menuItem.classList.add('active');
|
||||
if (menuItem) {
|
||||
menuItem.classList.add('active');
|
||||
}
|
||||
|
||||
const parent = menuItem.closest('.menu-sub');
|
||||
const parent = menuItem?.closest('.menu-sub');
|
||||
if (parent) {
|
||||
const parentItem = parent.closest('.menu-item');
|
||||
if (parentItem) {
|
||||
|
||||
Reference in New Issue
Block a user