Auto menu item intercepting

Explanations

Simple function designed to set a function to all menu items.

Code snippet

class Example extends P4A {
 
        function Acopiadora() {
            parent::p4a();
            $this->build("P4A_menu", "menu");
 
            ...
            /*Add all the items and subitems that you need*/
            ...
            $this->attachEvents($this->menu, "onClick", "menuClick");
            ...
        }
 
        function menuClick()
        {
            $this->openMask($this->active_object->getName());
        }
 
        function attachEvents ( $root, $event = "onClick", $function)
        {
            if ( $root == NULL || !strlen($function))
                return;
 
            if ( $root->hasItems() )
            {
                $root->items->reset();
                while($item = $root->items->nextItem()) $this->attachEvents($item, $event, $function);
            }
            else
            {
                $this->intercept($root, $event, $function);
            }
        }
 
 
}

User's comments

2007-07-24: It works for me and it simplyfies my code

 
intercept-events-in-entire-menu.txt · Last modified: 2007/07/24 06:29 by ign
 
Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki