Jump to content


[DEV]


  • You cannot reply to this topic
4 replies to this topic

#1 Mukke

    Etomite Forum Newbie

  • Member
  • 47 posts

Posted 01 February 2008 - 02:49 PM

Snippet: CoolMenuPro
Required: CoolMenuPro
nice script to build a javascript menu
only vertical allignment atm
my goal is to build in all cool menu pro samples


Thx to Ralph for making even more confusing but i got most my errors out talking to him :)


v0.3 changes:
- oops forgot the link, added now
- also made a horizontal menu

v0.2 changes:
- correct displaying colors
- several small typo's in the loop

and here's the script:
chunk {{CoolMenuPro}} (should be placed in header)
/*
Cool Menu Pro 4 Etomite
v0.3
@author: Ruben Decleyn
@email:   webmaster@mukke.org
*/


$id = isset($id) ? $id : $etomite->documentIdentifier;
$sortby = "menuindex";
$sortdir = "ASC";
$fields = "id, pagetitle, description, parent, alias";
$arrange = isset($arrange) ? $arange : "vertical";


function recursiveLoop($id,$sortby, $sortdir, $fields,$etomite)
{
	$temp = "";
	$children = $etomite->getActiveChildren($id, $sortby, $sortdir, $fields);
	foreach($children as $child)
	{		
		$temp .= '{code:"'.$child['pagetitle'].'", url:"[~'.$child['id'].'~]",'."\n";
		if($etomite->getActiveChildren($child['id'], $sortby, $sortdir, $fields))
		{
			$temp .= "sub:[{},"."\n";
			$temp .= recursiveLoop($child['id'],$sortby, $sortdir, $fields,$etomite);
			$temp .= "],"."\n";
		}
		$len = strlen($temp);
		$temp = substr($temp,0,$len-2);
		$temp .= "},"."\n";
	}
	$len = strlen($temp);
	$temp = substr($temp,0,$len-2);
	return $temp;
}



$output = "
var STYLE_0 =
{
	borderWidth:1,
	borderColor:'#666666',
	backgroundColor:[ 'black', '#B6BDD2' ],
	backgroundClass:[ 'clsCMOn', 'clsCMOver' ],
	size:[ 22, 100 ],
	/*1{*/itemoff:[ '+previousItem-1px', 0 ]/*1}*/,
	/*2{*/leveloff:[ 0, '+parentItem-1px' ]/*2}*/
};
var MENU_ITEMS = [
	{pos:'relative', /*3{*/style:STYLE_0/*3}*/, blankImage:'assets/images/b.gif'},
"."\n";

$output .= recursiveLoop($id,$sortby, $sortdir, $fields,$etomite);
$output .= "]"."\n";
$output .= '
var menu1 = new COOLjsMenuPRO("menu1", MENU_ITEMS);
menu1.initTop();'."\n";

return $output;

Edited by Mukke, 01 February 2008 - 04:52 PM.


#2 Mukke

    Etomite Forum Newbie

  • Member
  • 47 posts

Posted 01 February 2008 - 04:51 PM

updated to v0.3

#3 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 01 February 2008 - 06:08 PM

You need to add the if($children = $etomite->getActiveChildren($id, $sortby, $sortdir, $fields)) control block to the outer query as well to account for the main query not returning results, wrapped around the whole foreach() structure... B)

#4 Mukke

    Etomite Forum Newbie

  • Member
  • 47 posts

Posted 03 February 2008 - 08:23 PM

yeh maybe
but if there is no page, there will also be no menu
and if there are 0 elements returned the foreach won't loop anyway

#5 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 03 February 2008 - 09:32 PM

View PostMukke, on Feb 3 2008, 03:23 PM, said:

yeh maybe
but if there is no page, there will also be no menu
and if there are 0 elements returned the foreach won't loop anyway


If foreach() cannot complete at least one iteration it will throw an error... You really need a conditional logic check, trust me... I've written enough code without one and ended up having to add one later on to know...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users