The above solutions only works if the number and structure of the menu links remain the same. The problem is whenever you'd add a link the level number of the top most ul changes. Whenever the top most ul number changes, your css that targets a ul class with that number breaks:
Here is a solution that fixes this problem:
In the first function we output the UL class when the UL is created.
function YOURTHEME_menu_tree__menu_secondary_menu($variables) {
global $cur_level_menu_secondary_menu;
$class = ($cur_level_menu_secondary_menu == 1) ? 'secondary-menu' : 'secondary-menu--submenu';
$output = '<ul class="' . $class . ' ' . 'secondary-menu--' . $cur_level_menu_secondary_menu . '">' . $variables['tree'] . '</ul>';
$cur_level_menu_secondary_menu--;
return $output;
}
In the second function we save the current depth in a global variable $cur_level_menu_secondary_menu
.
function YOURTHEME_menu_link__menu_secondary_menu(array $variables) {
$element = $variables['element'];
global $cur_level_menu_secondary_menu;
$cur_level_menu_secondary_menu = $element['#original_link']['depth'];
$sub_menu = $element['#below'] ? drupal_render($element['#below']) : '';
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . '</li>';
}
Thus the top most UL will always have the number 1.
<ul class="secondary-menu secondary-menu--1">
<li>Menu Link</li>
<ul class="secondary-menu--submenu secondary-menu--2">
<li>Menu Link</li>
<li>Menu Link</li>
<ul class = "secondary-menu-submenu secondary-menu--3">
<li>Menu Link</li>
</ul>
<li>Menu Link</li>
</ul>
<li>Menu Link</li>
</ul>
css pseudo codes
?