Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for long dropdown submenu #14300

Closed
wants to merge 8 commits into from
9 changes: 9 additions & 0 deletions _build/data/transport.core.system_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,15 @@
'area' => 'manager',
'editedon' => null,
), '', true, true);
$settings['topmenu_submenu_max_items']= $xpdo->newObject('modSystemSetting');
$settings['topmenu_submenu_max_items']->fromArray(array (
'key' => 'topmenu_submenu_max_items',
'value' => '',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'manager',
'editedon' => null,
), '', true, true);
$settings['tree_default_sort']= $xpdo->newObject('modSystemSetting');
$settings['tree_default_sort']->fromArray(array (
'key' => 'tree_default_sort',
Expand Down
1 change: 1 addition & 0 deletions _build/templates/default/sass/_colors-and-vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ $navbarBg: $lighterGray; // unused
$navbarHover: $softGray; // unused
$navbarDrop: $navbarBg; // unused
$navbarText: $white;
$navbarDropArrowColor: rgb(96,114,124);
$navbarBorder: #2F4150;
$subnavBg: #2B3948;
$subnavBgHover: #3E5268;
Expand Down
26 changes: 21 additions & 5 deletions _build/templates/default/sass/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,31 @@
}
}

#modx-navbar .top {
#modx-navbar .top,
#modx-navbar .right {
padding-right: 15px;

&:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid rgb(96,114,124);
position: absolute;
content: ' ';
right: 12px;
top: 26px;
}
}

#modx-navbar .top:after {
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid $navbarDropArrowColor;
top: 26px;
}

#modx-navbar .right:after {
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
border-left: 5px solid $navbarDropArrowColor;
top: calc(50% - 5px);
}

#modx-user-menu li.top > a,
#modx-topnav li.top > a {
cursor: default;
Expand Down Expand Up @@ -178,6 +189,11 @@
padding-left: 0;
position: absolute; left: 270px; top: -1px;
z-index: 24;

&.more {
top: unset;
bottom: -1px;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions core/lexicon/en/setting.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,9 @@
$_lang['setting_topmenu_show_descriptions'] = 'Show Descriptions in Top Menu';
$_lang['setting_topmenu_show_descriptions_desc'] = 'If set to \'No\', MODX will hide the descriptions from top menu items in the manager.';

$_lang['setting_topmenu_submenu_max_items'] = 'Maximum items in the drop-down lists of the top menu bar';
$_lang['setting_topmenu_submenu_max_items_desc'] = 'The maximum number of items displayed in the drop-down lists of the top menu bar. The remaining items will be hidden in the "More" item.';

$_lang['setting_tree_default_sort'] = 'Resource Tree Default Sort Field';
$_lang['setting_tree_default_sort_desc'] = 'The default sort field for the Resource tree when loading the manager.';

Expand Down
1 change: 1 addition & 0 deletions core/lexicon/en/topmenu.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
$_lang['media_desc'] = 'Update Media and Media Sources';
$_lang['messages'] = 'Messages';
$_lang['messages_desc'] = 'View and send messages';
$_lang['more'] = 'More';
$_lang['namespaces'] = 'Namespaces';
$_lang['namespaces_desc'] = 'Distinguish between Add-on settings';
$_lang['new_document'] = 'New Document';
Expand Down
30 changes: 26 additions & 4 deletions manager/controllers/default/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public function __construct(modManagerController &$controller)
$this->controller =& $controller;
$this->modx =& $controller->modx;
$this->showDescriptions = (boolean) $this->modx->getOption('topmenu_show_descriptions', null, true);
$this->mainNavParent = (string) $this->modx->getOption('main_nav_parent', null, 'topnav', true);
$this->subMenuMaxItems = (int) $this->modx->getOption('topmenu_submenu_max_items', null, 0, true);
}

/**
Expand All @@ -77,7 +79,7 @@ public function render()
$mainNav = $this->modx->smarty->getTemplateVars('navb');
if (empty($mainNav)) {
$this->buildMenu(
$this->modx->getOption('main_nav_parent', null, 'topnav', true),
$this->mainNavParent,
'navb'
);
}
Expand Down Expand Up @@ -194,7 +196,7 @@ public function buildMenu($name, $placeholder)

if (!empty($menu['children'])) {
$menuTpl .= '<ul class="modx-subnav">'."\n";
$this->processSubMenus($menuTpl, $menu['children']);
$this->processSubMenus($menuTpl, $menu['children'], ($name == $this->mainNavParent ? $this->subMenuMaxItems : 0));
$menuTpl .= '</ul>'."\n";
}
$menuTpl .= '</li>'."\n";
Expand Down Expand Up @@ -303,10 +305,16 @@ public function hasPermission($perms)
*
* @return void
*/
public function processSubMenus(&$output, array $menus = array())
public function processSubMenus(&$output, array $menus = array(), $maxItems = false)
{
//$output .= '<ul class="modx-subnav">'."\n";

$moreMenu = '';
if ($maxItems && count($menus) > $maxItems) {
$moreMenu = array_slice($menus, $maxItems);
$menus = array_slice($menus, 0, $maxItems);
}

foreach ($menus as $menu) {
if (!$this->hasPermission($menu['permissions'])) {
continue;
Expand All @@ -328,9 +336,16 @@ public function processSubMenus(&$output, array $menus = array())
if (!empty($menu['handler'])) {
$attributes .= ' onclick="{literal} '.str_replace('"','\'',$menu['handler']).'{/literal} "';
}
$smTpl .= '<a'.$attributes.'>'.$menu['text'].$description.'</a>'."\n";

$hasChildren = false;
$classes = '';
if (!empty($menu['children'])) {
$hasChildren = true;
$classes = ' class="right"';
}
$smTpl .= '<a'.$attributes.$classes.'>'.$menu['text'].$description.'</a>'."\n";

if ($hasChildren) {
$smTpl .= '<ul class="modx-subsubnav">'."\n";
$this->processSubMenus($smTpl, $menu['children']);
JoshuaLuckers marked this conversation as resolved.
Show resolved Hide resolved
$smTpl .= '</ul>'."\n";
Expand All @@ -340,6 +355,13 @@ public function processSubMenus(&$output, array $menus = array())
$this->childrenCt++;
}

if (!empty($moreMenu)) {
$output .= '<li><a class="right">'.$this->modx->lexicon('more').'</a>'."\n";
$output .= '<ul class="modx-subsubnav more">'."\n";
$this->processSubMenus($output, $moreMenu);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maximum amount of items should also apply here.

$output .= '</ul>'."\n";
}

//$output .= '</ul>'."\n";
}

Expand Down