Fix menu link targets

master
Harald Wolff 2021-11-17 13:21:22 +01:00
parent 4ec0366a5f
commit b3b73deef4
4 changed files with 33 additions and 8 deletions

View File

@ -14,13 +14,15 @@ use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
$id = '';
if ($tagId = $params->get('tag_id', ''))
{
$id = ' id="' . $tagId . '"';
}
?><nav class="navbar navbar-expand-lg">
?>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid float-end float-sm-none">
<button class="navbar-toggler navbar-toggler-right" type="button" data-bs-toggle="collapse" data-bs-target="#navbar<?php echo $module->id; ?>" aria-controls="navbar<?php echo $module->id; ?>" aria-expanded="false" aria-label="<?php echo Text::_('MOD_MENU_TOGGLE'); ?>">
<span class="bi-list fs-2" aria-hidden="true"></span>
@ -29,7 +31,7 @@ if ($tagId = $params->get('tag_id', ''))
<ul<?php echo $id; ?> class="navbar-nav me-auto <?php echo $class_sfx; ?>">
<?php foreach ($list as $i => &$item)
{
if (count($item->tree) == 1) {
if ($item->level == $params['startLevel']) {
require ModuleHelper::getLayoutPath('mod_menu', 'item');
}
}

View File

@ -1 +1 @@
<a id="mi-<?=$item->id;?>" class="<?=$mi_class;?>" <?=$aattributes;?> data-bs-toggle="dropdown" aria-expanded="false"><?=$item->title;?></a>
<a id="mi-<?=$item->id;?>" class="<?=$mi_class;?>" <?=$aattributes;?><?php if ($hasChildren): ?> data-bs-toggle="dropdown" aria-expanded="false"<?php endif; ?>><?=$item->title;?></a>

View File

@ -1 +1,7 @@
<?php if ($hasChildren): ?><span id="mi-<?=$item->id;?>" class="<?=$mi_class;?>" <?=$aattributes;?> data-bs-toggle="dropdown" aria-expanded="false"><?php endif; ?><a class="nav-link d-inline" href="<?=$item->flink;?>"><?=$item->title;?></a><?php if ($hasChildren): ?></span><?php endif; ?>
<?php if ($hasChildren): ?><span id="mi-<?=$item->id;?>" class="<?=$mi_class;?>" data-bs-toggle="dropdown" aria-expanded="false"><?php endif;?>
<a class="nav-link" href="<?=$item->flink;?>"<?php
foreach ($attributes as $name => &$value){
echo ' ' . $name . '="' . $value. '"';
}
?>><?=$item->title;?></a>
<?php if ($hasChildren): ?></span><?php endif; ?>

View File

@ -2,13 +2,13 @@
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\HTML\HTMLHelper;
$hasChildren = $item->hasChildren();
$hasChildren = $item->hasChildren() && ($item->level < $params['endLevel']);
$hasParent = $item->hasParent();
$itemParams = $item->getParams();
$class = 'item-' . $item->id;
$mi_class = 'nav-link';
$aattributes = '';
$attributes = array();
if ($hasParent)
{
@ -22,7 +22,7 @@ use Joomla\CMS\HTML\HTMLHelper;
{
$class .= " dropdown";
$mi_class .= " dropdown-toggle";
$aattributes .= ' role="button"';
$attributes["role"] = 'button';
}
if ($item->type === 'separator')
{
@ -38,6 +38,23 @@ use Joomla\CMS\HTML\HTMLHelper;
$class .= ' current';
}
if ($item->browserNav == 1)
{
$attributes['target'] = '_blank';
$attributes['rel'] = 'noopener noreferrer';
if ($item->anchor_rel == 'nofollow')
{
$attributes['rel'] .= ' nofollow';
}
}
elseif ($item->browserNav == 2)
{
$options = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,' . $params->get('window_open');
$attributes['onclick'] = "window.open(this.href, 'targetWindow', '" . $options . "'); return false;";
}
echo '<li class="' . $class . '">';
switch ($item->type) :
@ -55,7 +72,7 @@ use Joomla\CMS\HTML\HTMLHelper;
break;
endswitch;
if ($item->hasChildren())
if ($hasChildren)
{
echo '<ul class="dropdown-menu" aria-labelledby="mi-'.$item->id.'">';