I've patched the bulletmenu plugin to do exactly what you're describing. Apply this patch and then call bulletmenu with "collapse='1'" to see it in action.
If this patch doesn't come through in the forum very well, email me or get me on the IRC channel, I'll upload it somewhere and/or email it to whomever wants to commit it to SVN.
Code: Select all
Index: plugins/function.bulletmenu.php
===================================================================
--- plugins/function.bulletmenu.php (revision 101)
+++ plugins/function.bulletmenu.php (revision 103)
@@ -24,6 +24,8 @@
# getting menu parameters
$showadmin = isset($params["showadmin"]) ? $params["showadmin"] : 1 ;
+ $collapse = isset($params["collapse"]) ? $params["collapse"] : 0 ;
+
$allcontent = ContentManager::GetAllContent();
# defining variables
@@ -32,8 +34,20 @@
$count = 0;
$in_hr = 0;
+
+
if (count($allcontent))
{
+
+ if ($collapse) {
+ # find hierarchy
+ foreach ($allcontent as $onecontent) {
+ if ($gCms->variables['page_id'] == $onecontent->Id()) {
+ $myhier = $onecontent->Hierarchy();
+ }
+ }
+ }
+
$menu .= "<div class=\"bulletmenu\">\n";
foreach ($allcontent as $onecontent)
@@ -51,6 +65,73 @@
}
}
+
+ if ($collapse) {
+ $thishier = $onecontent->Hierarchy();
+ $mypieces = explode(".", $myhier);
+ $thispieces = explode(".", $thishier);
+
+ if (count($mypieces) > $thispieces)
+ $l = count($mypieces);
+ else
+ $l = count($thispieces);
+
+ # root-level is excepted
+ if (count($thispieces) > 1) {
+ $continue = 1;
+ $myh = $mypieces[0];
+ $thish = $thispieces[0];
+ for($i = 1; $i < $l; $i++) {
+
+ if ($myh == $thish) {$continue = 0; continue;}
+ if ($thispieces[$i] != '') $thish .= '.' . $thispieces[$i];
+
+ if ($myh == $thish) {$continue = 0; continue;}
+ if ($mypieces[$i] != '') $myh .= '.' . $mypieces[$i];
+
+ }
+ if ($continue) continue;
+ if (count($thispieces) > count($mypieces)+1) continue;
+ $tt = join('.', array_slice($thispieces,0,count($mypieces)));
+ if (count($thispieces) > count($mypieces) && $myhier != $tt) continue;
+ }
+ }
+
#Now check to make sure we're not too many levels deep if number_of_levels is set
if (isset($params['number_of_levels']))
{
@@ -110,13 +191,16 @@
}
else
{
- $menu .= "<li><a href=\"".$onecontent->GetURL()."\"";
+ $menu .= "<li class=\"bulletmenudepth" . count(explode(".", $onecontent->Hierarchy())). "\"";
+ $menu .= "><a href=\"".$onecontent->GetURL()."\"";
if (isset($gCms->variables['page_id']) && $onecontent->Id() == $gCms->variables['page_id'])
{
$menu .= " class=\"currentpage\"";
+ } else {
+ $menu .= " class=\"bulletmenudepth".count(explode(".", $onecontent->Hierarchy())) . "\"";
}
$menu .= ">".$onecontent->MenuText()."</a>";
- }
+ }
$in_hr = 1;
$last_level = $depth;
}
@@ -148,6 +232,7 @@
<li><em>(optional)</em> <tt>showadmin</tt> - 1/0, whether you want to show or not the admin link.</li>
<li><em>(optional)</em> <tt>start_element</tt> - the hierarchy of your element (ie : 1.2 or 3.5.1 for example). This parameter sets the root of the menu.</li>
<li><em>(optional)</em> <tt>number_of_levels</tt> - an integer, the number of levels you want to show in your menu.</li>
+ <li><em>(optional)</em> <tt>collapse</tt> - 1/0, whether you want the menu to collapse all but the current.</li>
</ul>
</p>