PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_TreeMenu » Bug #2392

Nodes open expanded on mulitiple menus

Details

Submitted2004-09-24 15:57 UTC
Fromtanlis_dsl at yahoo dot com
Assignedrichard
StatusClosed
PackageHTML_TreeMenu
PHP Version4.3.6
OSMac OSX
Roadmaps1.2.1

Comments

[2004-09-24 15:57 UTC] tanlis_dsl at yahoo dot com

Description:
------------
Having more than one menu will cause the same node
indice I open on the first menu to also be open on the
second menu.

ie,

Menu 1
Cars
- Ford
- Toyota

Motorcycles
- Honda
- Kawasaki

If I open the Cars node and click Ford which takes me to
another page with a menu it will show up as below.

Menu 2
Ford
- Mustang
- GT
- Cobra
- Explorer
- F150

The Mustang node is automatically opened by the
resetBranches javascript function because the cookie is
stored with node1 being open.

Reproduce code:
---------------
Page 1:
$menu = new HTML_TreeMenu();
$node = new HTML_TreeNode(array("text" => "Cars", "link" => "test.php?type=cars"));
$cnode = &$node->addItem(new HTML_TreeNode(array("text" => "Ford", "link" => "test.php?ctype=Ford")));
$cnode = &$node->addItem(new HTML_TreeNode(array("text" => "Toyota", "link" => "test.php?ctype=Toyota")));

$menu->addItem($node);

$node = new HTML_TreeNode(array("text" => "MotorCycles", "link" => "test.php?type=motorcycles"));
$cnode = &$node->addItem(new HTML_TreeNode(array("text" => "Honda", "link" => "test.php?ctype=Honda")));
$cnode = &$node->addItem(new HTML_TreeNode(array("text" => "Kawasaki", "link" => "test.php?ctype=Kawasaki")));

$menu->addItem($node);

Page 2:
$menu = new HTML_TreeMenu();
$node = new HTML_TreeNode(array("text" => "Mustang", "link" => "test.php?ctype=mustang"));
$cnode = &$node->addItem(new HTML_TreeNode(array("text" => "GT", "link" => "test.php?ctype=GT")));
$cnode = &$node->addItem(new HTML_TreeNode(array("text" => "Cobra", "link" => "test.php?ctype=Cobra")));

$menu->addItem($node);

$node = new HTML_TreeNode(array("text" => "Explorer", "link" => "test.php?type=explorer"));

$menu->addItem($node);

$node = new HTML_TreeNode(array("text" => "F150", "link" => "test.php?type=f150"));

$menu->addItem($node);

Expected result:
----------------
All menus should be separate and not expanded unless
specificed in the php code

If a node is opened on one menu, the corresponding node
on a second menu should not be opened as well.

Possible solution would be to provide an optional
identifier on creation of the menu as currently
objTreeMenu_1 is the default name of the first menu on a
page.

[2004-09-24 17:13 UTC] tanlis_dsl at yahoo dot com

Here is a patch that will allow a name to be passed in
the constructor of the menu. This allows the states of
each menu to be separate throughout a site.

Index: TreeMenu.php
========================================================
===========
RCS file: /repository/pear/HTML_TreeMenu/TreeMenu.php,v
retrieving revision 1.18
diff -u -r1.18 TreeMenu.php
--- TreeMenu.php 20 Dec 2003 13:10:59 -0000
1.18
+++ TreeMenu.php 24 Sep 2004 17:09:11 -0000
@@ -70,13 +70,20 @@
var $items;

/**
+ * Name of menu
+ * @var string
+ */
+ var $menuName;
+
+ /**
* Constructor
+ * Sets the name of the menu to objTreeMenu_ by
default if one is not supplied.
*
* @access public
*/
- function HTML_TreeMenu()
+ function HTML_TreeMenu($mname = "objTreeMenu_")
{
- // Not much to do here :(
+ $this->menuName = $mname;
}

/**
@@ -616,7 +623,7 @@
function toHTML()
{
static $count = 0;
- $menuObj = 'objTreeMenu_' . ++$count;
+ $menuObj = $this->menu->menuName .
++$count;

$html = "\n";
$html .= '<script language="javascript"
type="text/javascript">' . "\n\t";