Phundament-Components
[ class tree: Phundament-Components ] [ index: Phundament-Components ] [ all elements ]

Source for file LCssDropDownMenu.php

Documentation is available at LCssDropDownMenu.php

  1. <?php
  2. /**
  3.  * LCssDropDownMenu class file
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the BSD License.
  7.  *
  8.  * Copyright(c) 2004 by Scott Fuelberth.
  9.  * Copyright(c) 2006 by Tobias Munk.
  10.  *
  11.  * The latest version of PRADO can be obtained from:
  12.  * {@link http://prado.sourceforge.net/}
  13.  *
  14.  * =================================================
  15.  * NOTICE: This works now with assets, working with
  16.  * custom files, like in v2 need to be reimplemented.
  17.  * =================================================
  18.  *
  19.  * Changes: Ported to v3, this component can hook up to LVirtualNodes and
  20.  * LPageService for a changeable custom, non-nardcoded navigation.
  21.  *
  22.  * @author Scott Fuelberth <skot@bastardcat.org>, Tobias Munk <webmaster@lithron.de>
  23.  * @version $Revision: 633 $  $Date: 2007-02-25 02:10:18 +0100 (Sun, 25 Feb 2007) $
  24.  * @package Phundament.Components
  25.  * @subpackage WebControls
  26.  * @todo reimplement
  27.  */
  28.  
  29. /**
  30.  * LCssDropDownMenu class file class
  31.  *
  32.  * LCssDropDownMenu class file displays a css driven menu on a Web page. You can set the alignment of the menu
  33.  * through the <b>Horizontal</b> property.
  34.  * If you do not have your own menu styling with themes, you may setUseStylingAsset to true.
  35.  *
  36.  * Example: <code><com:TCssDropDownMenu Horizontal="false" /></code>
  37.  *
  38.  * Namespace: Lithron.Web.UI.WebControls
  39.  *
  40.  * Properties
  41.  * - <b>Horizontal</b>, boolean, kept in viewstate
  42.  *   <br>Sets the alignment of the menu, true = horizontal and false = vertical.
  43.  * - <b>CssHorizontalFile</b>, string, kept in view state
  44.  *   <br>Sets the css file to be used for horizontal menus
  45.  * - <b>CssVerticalFile</b>, string, kept in view state
  46.  *   <br>Sets the css file to be used for vertical menus
  47.  * - <b>CssDirectory</b>, string, kept in view state
  48.  *   <br>Sets the css file directory
  49.  * - <b>JsDirectory</b>, string, kept in view state
  50.  *   <br>Set the javascript directory
  51.  * - <b>JsFile</b>, string, kept in view state
  52.  *   <br>Set the javascript filename
  53.  * - <b>TopParentNodeCssClass</b>, string, kept in view state
  54.  *   <br>Set the css class name of the top most TCssDropDownMenuNode
  55.  * - <b>ParentNodeCssClass<b>, string, kept in view state
  56.  *   <br>Set the css class name of parent (nodes with children nodes) TCssDropDownMenuNodes
  57.  * - <b>NodeCssClass</b>, string, kept in view state
  58.  *   <br>Set the node css class name of ending TCssDropDownMenuNodes
  59.  * - <b>DisabledCssClass</b>, string kept in view state
  60.  *      <br>Set the node css class name of disabled TCssDropDownMenuNodes
  61.  *
  62.  * Note, that the default css files need to be located under the root of your site unders js/cssdropdownmenu/css with
  63.  * cssdropdownmenu-horizontal.css and cssdropdownmenu-vertical.css controlling the aligments.  There is also a small
  64.  * javascript file for IE non-support of the virtual tage hover.  Based off the work of Son of Suckerfish by
  65.  * Patrick Griffiths and Dan Webb, see http://www.htmldog.com/articles/suckerfish/dropdowns/
  66.  *
  67.  * @package System.Web.UI.WebControls
  68.  * @subpackage Navigation
  69.  */
  70. class LCssDropDownMenu extends TWebControl
  71. {
  72.     protected function getTagName()
  73.     {
  74.         return 'ul';
  75.     }
  76.  
  77.     /**
  78.      * Adds attributes related to a hyperlink element to renderer.
  79.      * @param THtmlWriter the writer used for the rendering purpose
  80.      */
  81.     protected function addAttributesToRender($writer)
  82.     {
  83.         parent::addAttributesToRender($writer);
  84.         //$writer->addAttribute('style',"width:100%;clear:both;background-color:red;margin-right:0px");
  85.         /*
  86.  
  87.  
  88.         $isEnabled=$this->getEnabled(true);
  89.         if($this->getEnabled() && !$isEnabled)
  90.             $writer->addAttribute('disabled','disabled');
  91.         parent::addAttributesToRender($writer);
  92.         if(($url=$this->getNavigateUrl())!=='' && $isEnabled)
  93.             $writer->addAttribute('href',$url);
  94.         if(($target=$this->getTarget())!=='')
  95.             $writer->addAttribute('target',$target);
  96.         */
  97.     }
  98.  
  99.     /**
  100.      * Renders the menu, and itinitialize top parent nodes css.
  101.      * @return void 
  102.      */
  103.     function render($writer)
  104.     {
  105.         #Prado :: trace("Begin Menu render", 'System.Lithron.LPageService');
  106.         $body $this->getControls();
  107.         foreach ($body as $item)
  108.         {
  109.             if ($item instanceof LCssDropDownMenuNode)
  110.             {
  111.                 //$this->setCssClass(" parent");
  112.                 $item->setTopParent(true);
  113.                 $item->setTopParentNodeCssClass($this->getTopParentNodeCssClass());
  114.                 $item->setParentNodeCssClass($this->getParentNodeCssClass());
  115.                 $item->setNodeCssClass($this->getNodeCssClass());
  116.                 $item->setDisabledNodeCssClass($this->getDisabledCssClass());
  117.             }
  118.         }
  119.         #Prado :: trace("End Menu render", 'System.Lithron.LPageService');
  120.         parent :: render($writer);
  121.     }
  122.  
  123.  
  124.  
  125.     /**
  126.      * @return string the disabled menu node css class
  127.      *  the css class name
  128.      */
  129.     function getDisabledCssClass()
  130.     {
  131.         return $this->getViewState('DisabledCssClass''');
  132.     }
  133.  
  134.     /**
  135.      * @param string the menu alignment
  136.      *  css class name
  137.      */
  138.     function setDisabledCssClass($value)
  139.     {
  140.         $this->setViewState('DisabledCssClass'$value'');
  141.     }
  142.  
  143.     /**
  144.      * @return boolean the menu alignment
  145.      *  true means a horizontal menu, false means a vertical menu
  146.      */
  147.     function getHorizontal()
  148.     {
  149.         return $this->getViewState('Horizontal''');
  150.     }
  151.  
  152.     /**
  153.      * @param boolean the menu alignment
  154.      *  true means a horizontal menu, false means a vertical menu
  155.      */
  156.     function setHorizontal($value)
  157.     {
  158.         $this->setViewState('Horizontal'TPropertyValue::ensureBoolean($value));
  159.     }
  160.  
  161.     /**
  162.      * @return string the name of the css horizontal file
  163.      */
  164.     function getCssHorizontalFile()
  165.     {
  166.         return $this->getViewState('CssHorizontalFile');
  167.     }
  168.  
  169.     /**
  170.      * @param boolean the name of the css horizontal file
  171.      */
  172.     function setCssHorizontalFile($value)
  173.     {
  174.         $this->setViewState('CssHorizontalFile'$value);
  175.     }
  176.  
  177.     /**
  178.      * @return string the name of the css vertical file
  179.      */
  180.     function getCssVerticalFile()
  181.     {
  182.         return $this->getViewState('CssVerticalFile');
  183.     }
  184.  
  185.     /**
  186.      * @param boolean the name of the css vertical file
  187.      */
  188.     function setCssVerticalFile($value)
  189.     {
  190.         $this->setViewState('CssVerticalFile'$value'');
  191.     }
  192.  
  193.     /**
  194.      * @return string the name of the css directory
  195.      */
  196.     function getCssDirectory()
  197.     {
  198.         return $this->getViewState('CssDirectory''js/cssdropdownmenu/css');
  199.     }
  200.  
  201.     /**
  202.      * @param boolean the name of the css directory
  203.      */
  204.     function setCssDirectory($value)
  205.     {
  206.         $this->setViewState('CssDirectory'$value'js/cssdropdownmenu/css');
  207.     }
  208.  
  209.     /**
  210.      * @return string the name of the js directory
  211.      */
  212.     function getJsDirectory()
  213.     {
  214.         return $this->getViewState('JsDirectory''js/cssdropdownmenu');
  215.     }
  216.  
  217.     /**
  218.      * @param boolean the name of the js directory
  219.      */
  220.     function setJsDirectory($value)
  221.     {
  222.         $this->setViewState('JsDirectory'$value'js/cssdropdownmenu');
  223.     }
  224.  
  225.     /**
  226.      * @return string the name of the js file
  227.      */
  228.     function getJsFile()
  229.     {
  230.         return $this->getViewState('JsFile''cssdropdownmenu.js');
  231.     }
  232.  
  233.     /**
  234.      * @param boolean the name of the js file
  235.      */
  236.     function setJsFile($value)
  237.     {
  238.         $this->setViewState('JsFile'$value'cssdropdownmenu.js');
  239.     }
  240.  
  241.     /**
  242.      * @return string the top level parent node css class name
  243.      */
  244.     function getTopParentNodeCssClass()
  245.     {
  246.         return $this->getViewState('TopParentNodeCssClass''');
  247.     }
  248.  
  249.     /**
  250.      * @param string the top level parent node css class name
  251.      */
  252.     function setTopParentNodeCssClass($value)
  253.     {
  254.         $this->setViewState('TopParentNodeCssClass'$value'');
  255.     }
  256.  
  257.     /**
  258.      * @return string the parent node css class name
  259.      */
  260.     function getParentNodeCssClass()
  261.     {
  262.         return $this->getViewState('ParentNodeCssClass''');
  263.     }
  264.  
  265.     /**
  266.      * @param string the parent node css class name
  267.      */
  268.     function setParentNodeCssClass($value)
  269.     {
  270.         $this->setViewState('ParentNodeCssClass'$value'');
  271.     }
  272.  
  273.     /**
  274.      * @return string the node css class name
  275.      */
  276.     function getNodeCssClass()
  277.     {
  278.         return $this->getViewState('NodeCssClass''');
  279.     }
  280.  
  281.     /**
  282.      * @param string the node css class name
  283.      */
  284.     function setNodeCssClass($value)
  285.     {
  286.         $this->setViewState('NodeCssClass'$value'');
  287.     }
  288.  
  289.     /**
  290.      * @param boolean the name of the css horizontal asset
  291.      */
  292.     function setCssHorizontalAsset($value)
  293.     {
  294.         $this->setViewState('CssHorizontalAsset'$value);
  295.     }
  296.     /**
  297.      * @return string the name of the css horizontal asset
  298.      */
  299.     function getCssHorizontalAsset()
  300.     {
  301.         $asset $this->getViewState('CssHorizontalAsset''LCssDropDownMenu/horizontal.css');
  302.         return $this->publishAsset($asset);
  303.         #$this->setViewState('JsAsset',$value);
  304.     }
  305.  
  306.     /**
  307.      * @param boolean the name of the css vertical asset
  308.      */
  309.     function setCssVerticalAsset($value)
  310.     {
  311.         $this->setViewState('CssVerticalAsset'$value);
  312.     }
  313.  
  314.     /**
  315.      * @return string the name of the css vertical asset
  316.      */
  317.     function getCssVerticalAsset()
  318.     {
  319.         $asset $this->getViewState('CssVerticalAsset''LCssDropDownMenu/vertical.css');
  320.         return $this->publishAsset($asset);
  321.         #$this->setViewState('JsAsset',$value);
  322.     }
  323.  
  324.     /**
  325.      * @param boolean the name of the js asset
  326.      */
  327.     function setJsAsset($value)
  328.     {
  329.         $this->setViewState('JsAsset'$value);
  330.     }
  331.  
  332.     /**
  333.      * @return string the name of the js asset
  334.      */
  335.     function getJsAsset()
  336.     {
  337.         $asset $this->getViewState('JsAsset''LCssDropDownMenu/script.js');
  338.         return $this->publishAsset($asset);
  339.         #$this->setViewState('JsAsset',$value);
  340.     }
  341.  
  342.     /**
  343.      * @param boolean the name of the js asset
  344.      */
  345.     function setUseStylingAsset($value)
  346.     {
  347.         $this->setViewState('UseStylingAsset'TPropertyValue::ensureBoolean($value));
  348.     }
  349.  
  350.     /**
  351.      * @return string the name of the js asset
  352.      */
  353.     function getUseStylingAsset()
  354.     {
  355.         return $this->getViewState('UseStylingAsset'false);
  356.     }
  357.  
  358.  
  359.     /**
  360.      * Menu initialization
  361.      * @return void 
  362.      */
  363.     function onLoad($param)
  364.     {
  365.         #Prado :: trace("Initializing TCssDropDownMenu ...", 'Lithron.LCssDrownDownMenu');
  366.         parent :: onLoad($param);
  367.  
  368.         $this->publishAsset('LCssDropDownMenu/rightarrow.gif')// TODO
  369.         $scriptMgr $this->getPage()->getClientScript();
  370.         if ($this->getUseStylingAsset(=== true$scriptMgr->registerStyleSheetFile('LCssDropDownMenu:Styling'$this->publishAsset("assets/LCssDropDownMenu.css"));
  371.         $scriptMgr->registerStyleSheetFile('LCssDropDownMenu:Shared'$this->publishAsset("LCssDropDownMenu/shared.css"));
  372.         #Prado :: trace("Registering menu CSS file", 'Lithron.LCssDrownDownMenu');
  373.         $scriptMgr->registerScriptFile('LCssDropDownMenu:Js'$this->getJsAsset());
  374.         #Prado :: trace("Registering menu JS file", 'Lithron.LCssDrownDownMenu');
  375.         if ($this->getHorizontal())
  376.         {
  377.             $this->setCssClass("menuS menuH");
  378.             $cssFile $this->getCssHorizontalAsset();
  379.             $scriptMgr->registerStyleSheetFile('LCssDropDownMenu:Horizontal'$cssFile);
  380.  
  381.         else
  382.         {
  383.             $this->setCssClass("menuS menuV");
  384.             $cssFile $this->getCssVerticalAsset();
  385.             $scriptMgr->registerStyleSheetFile('LCssDropDownMenu:Vertical'$cssFile);
  386.         }
  387.  
  388.         #Prado :: trace("TCssDropDownMenu onLoad finished", 'Lithron.LCssDrownDownMenu');
  389.     }
  390.  
  391. }
  392. ?>

Documentation generated on Sun, 25 Feb 2007 16:10:08 +0100 by phpDocumentor 1.3.1