Re: PEAR HTML_Menu

From: Date: Mon, 07 Jun 2010 23:34:56 +0000
Subject: Re: PEAR HTML_Menu
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-30608@lists.php.net to get a copy of this message
Thanks for the answer. Unfortunately I needed to tackle this w/out CSS selectors or JS, or I totally would have taken the route you suggested. What I ended up doing was subclassing the HTML_Menu_DirectTreeRenderer and overridding the finishMenu method. now I just pass in the new subclass for the renderer and the new method looks like this: function finishMenu($level) { parent::finishMenu($level); // $this->_id is now set via the class constructor if (!is_null($this->_id)) { $dom = new DOMDocument(); $dom->loadHTML($this->_html); $uls = $dom->getElementsByTagName('ul'); $ul = $uls->item(0); $ul->lastChild->setAttribute('id', $this->_id); // Prevent tags and doctype from being added to the HTML // string automatically. $this->_html = substr($dom->saveXML( $dom->getElemebtsByTagName('ul')->item(0) ), 0); } } Thanks, Jamie K. On Mon, Jun 7, 2010 at 6:56 PM, Richard Quadling <rquadling@gmail.com>wrote: > On 7 June 2010 16:51, Jamie Kahgee <jamie.kahgee@gmail.com> wrote: > > If I wanted to apply an id/class to the last parent item in a menu - is > it > > possible w/out modifying this script? > > > > I'm using the HTML_Menu_DirectTreeRenderer and need a marker on the last > > <li> in the main list > > > > ie: > > > > <ul> > > <li>Menu item 1 > > <ul> > > <li>Menu item 1.1</li> > > <li>Menu item 1.2</li> > > </ul> > > </li> > > <li* id="lastli"*>Menu item 2</li> <-- need to add class here > > </ul> > > > > > > > > Thanks, > > Jamie K. > > > > You could use JavaScript ... > > $$('ul li').last().id = 'lastli' > > Maybe. > > (Using prototype.js for that). > > But I'm not 100% sure on what order the CSS selectors would give up the > list. > > Maybe ... > > $$('ul').first().select('li').last() > > > > -- > ----- > Richard Quadling > "Standing on the shoulders of some very clever giants!" > EE : http://www.experts-exchange.com/M_248814.html > EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp > Zend Certified Engineer : > http://zend.com/zce.php?c=ZEND002498&r=213474731 > ZOPA : http://uk.zopa.com/member/RQuadling >

« previous php.pear.general (#30608) next »