Expanded navigation by default
-
16-10-2019 - |
Question
I use the Sidebar Navigation Menu Professional for Magento by CODNITIVE and I am trying to make it expanded by default. Particularly I need a solution to make just the first list item expanded by default. Here is the code:
<script type="text/javascript" language="javascript">
//<![CDATA[
Codnitive = {
expandMenu: function(parent)
{
var mode = parent.getElementsByTagName("ul")[0].getAttribute("expanded");
(mode == 1) ? Codnitive.collapse(parent) : Codnitive.expand(parent);
},
expand: function(parent)
{
parent.getElementsByTagName("ul")[0].style.display = "block";
parent.getElementsByTagName("span")[0].style.backgroundPosition = "right center";
parent.getElementsByTagName("ul")[0].setAttribute("expanded", "1");
},
collapse: function(parent)
{
parent.getElementsByTagName("ul")[0].style.display = "none";
parent.getElementsByTagName("span")[0].style.backgroundPosition = "left center";
parent.getElementsByTagName("ul")[0].setAttribute("expanded", "0");
}
};
//]]>
</script>
In another forum there was the suggestion to use:
Codnitive.expand(document.getElementById('the-menu-parent-element-id'));
Where exactly should I write this code to make it work? Sorry, but I am not familiar with js.
Solution 2
Should add this condition in line 280:
if ($category->getId() == '35') {
$expanded = 1;
}
In this way the category with ID 35 will be expanded by default. There is still another little problem - the "plus" sign remains but it should be "minus" for collapsing the category.
OTHER TIPS
I'd rather edit CODNITIVE's Navigation.php in app/code/community/codnitive/sidenav/block/
on about line 289 there should be
if ($height == 0) {
$extraStyle = ' display:none;';
}
if you remove display:none it should be visible. You can also add a condition using the $level variable.
Just have a look at the code it's quite straightforward in my opinion.