collapseable menus

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
brownrl
Forum Members
Forum Members
Posts: 74
Joined: Thu Sep 23, 2004 11:06 am

collapseable menus

Post by brownrl »

Is there away already to have lets say a bulletmenu for the navigation menu.

This menu when click would look exactly the same except the section that was cliked then would have its children displayed?

like this:

Code: Select all

item 1
item 2
item 3


item 2 is clicked

next page then looks like.

Code: Select all

item 1
item 2
  sub_item1
  sub_item2
item 3

Thanks in advance..
Rob
Greg
Power Poster
Power Poster
Posts: 598
Joined: Sun Sep 26, 2004 6:15 pm
Location: Saskatchewan - Canada

collapseable menus

Post by Greg »

Like this one ...

Switch Menu

I am using this on one of my websites, works very well and is very minimal amount of code.
Greg
User avatar
sjg
Power Poster
Power Poster
Posts: 310
Joined: Thu Jan 27, 2005 5:11 pm
Location: Los Angeles, CA

Re: collapseable menus

Post by sjg »

brownrl wrote:Is there away already to have lets say a bulletmenu for the navigation menu.

This menu when click would look exactly the same except the section that was cliked then would have its children displayed?

like this:

Code: Select all

item 1
item 2
item 3


item 2 is clicked

next page then looks like.

Code: Select all

item 1
item 2
  sub_item1
  sub_item2
item 3

Thanks in advance..
Rob
I don't know if you're still looking, but I just uploaded an alpha version of a module to the Wiki that includes functionality like this.
Many modules available from the http://dev.cmsmadesimple.org
The CMS Made Simple Developer Cookbook is now available from Packt Publishers!
Greg
Power Poster
Power Poster
Posts: 598
Joined: Sun Sep 26, 2004 6:15 pm
Location: Saskatchewan - Canada

collapseable menus

Post by Greg »

I have the switch menu code working but the javascript conflicts with javascript from phplayers if it is installed. So you can have either the switch menu or the phplayers menu working on your site but not both at the same time!!
Greg
thetmz

collapseable menus

Post by thetmz »

Greg,
Have u implemented switch menu to work as phplayers works? I mean when u add smth in content management it appears on the switch menu?
if yes, could u paste the code..

thx in advance.
ntro

Patch to bulletmenu

Post by ntro »

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>
 
jptechnical
Forum Members
Forum Members
Posts: 131
Joined: Wed Jan 12, 2005 12:18 am

collapseable menus

Post by jptechnical »

I apologize for my ignorance... but how do I patch what I have with what you have? Is is supposed to be merged with the original? Or does it replace it?

thanks.
Krol

collapseable menus

Post by Krol »

Hi!

I still can't get how to patch the bulletmenu. Can someone experienced please help on this?

Krol
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

collapseable menus

Post by Ted »

This functionality is also in the bulletmenu version released with 0.9.
Anonymous

collapseable menus

Post by Anonymous »

wishy wrote:This functionality is also in the bulletmenu version released with 0.9.
This is good!
But can I make Section Headers clickable, too?
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

collapseable menus

Post by Ted »

I didn't think of that... I'll have to come up with a fix somehow. Thanks.
Post Reply

Return to “Tips and Tricks”