Zikula_Template_Plugins
[ class tree: Zikula_Template_Plugins ] [ index: Zikula_Template_Plugins ] [ all elements ]

Source for file block.pnformtabbedpanelset.php

Documentation is available at block.pnformtabbedpanelset.php

  1. <?php
  2. /**
  3.  * Tabbed panel set
  4.  *
  5.  * @copyright (c) 2006, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: block.pnformtabbedpanelset.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Jorn Wildt
  10.  * @package Zikula_Template_Plugins
  11.  * @subpackage Blocks
  12.  */
  13.  
  14. /**
  15.  * Tabbed panel set
  16.  *
  17.  * This plugin is used to create a set of panels with their own tabs for selection.
  18.  * The actual visibility management is handled in JavaScript by setting the CSS styling
  19.  * attribute "display" to "hidden" or not hidden. Default styling of the tabs is rather rudimentary
  20.  * but can be improved a lot with the techniques found at www.alistapart.com.
  21.  * Usage:
  22.  * <code>
  23.  * <!--[pnformtabbedpanelset]-->
  24.  *   <!--[pnformtabbedpanel title="Tab A"]-->
  25.  *     ... content of first tab ...
  26.  *   <!--[/pnformtabbedpanel]-->
  27.  *   <!--[pnformtabbedpanel title="Tab B"]-->
  28.  *     ... content of second tab ...
  29.  *   <!--[/pnformtabbedpanel]-->
  30.  * <!--[/pnformtabbedpanelset]-->
  31.  * </code>
  32.  * You can place any pnForms plugins inside the individual panels. The tabs
  33.  * require some special styling which is handled by the styles in system/pnForm/pnstyle/style.css.
  34.  * If you want to override this styling then either copy the styles to another stylesheet in the
  35.  * templates directory or change the cssClass attribute to something different than the default
  36.  * class name.
  37.  *
  38.  * @package pnForm
  39.  * @subpackage Plugins
  40.  */
  41. {
  42.     /**
  43.      * CSS class name for styling
  44.      * @var string 
  45.      */
  46.     var $cssClass = 'linktabs';
  47.  
  48.     /**
  49.      * Currently selected tab
  50.      * @var int 
  51.      */
  52.     var $selectedIndex = 1;
  53.  
  54.     /**
  55.      * Registered tab titles
  56.      * @var string-array 
  57.      * @internal
  58.      */
  59.     var $titles = array();
  60.  
  61.     /**
  62.      * Internal tab index counter
  63.      * @var int 
  64.      */
  65.     var $registeredTabIndex = 1;
  66.  
  67.  
  68.     function getFilename()
  69.     {
  70.         return __FILE__// FIXME: may be found in smarty's data???
  71.     }
  72.  
  73.  
  74.     function renderContent(&$render$content)
  75.     {
  76.         // Beware - working on 1-based offset!
  77.  
  78.         static $first true;
  79.         if ($first)
  80.         {
  81.             PageUtil::addVar('javascript''system/pnForm/pnjavascript/pnform_tabbedpanelset.js');
  82.             PageUtil::AddVar('stylesheet'ThemeUtil::getModuleStylesheet('pnForm'));
  83.         }
  84.  
  85.         $first false;
  86.  
  87.         $idHtml $this->getIdHtml();
  88.  
  89.         $html "<div class=\"{$this->cssClass}\"{$idHtml}><ul><li>&nbsp;</li>\n";
  90.  
  91.         for ($i=1, $titleCount=count($this->titles); $i<=$titleCount; ++$i)
  92.         {
  93.             $title = $this->titles[$i-1];
  94.  
  95.             $cssClass = 'linktab';
  96.             $selected = ($i == $this->selectedIndex);
  97.  
  98.             $title = $render->pnFormTranslateForDisplay($title);
  99.  
  100.             if ($selected)
  101.             {
  102.                 $cssClass .= ' selected';
  103.             }
  104.  
  105.             $link = "<a href=\"#\" onclick=\"return pnFormTabbedPanelSet.handleTabClick($i,$titleCount,'{$this->id}')\">$title</a>";
  106.  
  107.             $html .= "<li id=\"{$this->id}Tab_{$i}\" class=\"$cssClass\">$link</li><li>&nbsp;</li>\n";
  108.         }
  109.  
  110.         $html .= "</ul></div><div style=\"clear: both\"></div>\n";
  111.  
  112.         $html .= "<input type=\"hidden\" name=\"{$this->id}SelectedIndex\" id=\"{$this->id}SelectedIndex\" value=\"{$this->selectedIndex}\"/>\n";
  113.  
  114.         return $html . $content;
  115.     }
  116.  
  117.  
  118.     // Called by child panels to register themselves
  119.     function registerTabbedPanel(&$render, &$panel, $title)
  120.     {
  121.         $panel->panelSetId = $this->id;
  122.         if (!$render->pnFormIsPostBack())
  123.         {
  124.             $panel->index = $this->registeredTabIndex++;
  125.             $this->titles[] = $title;
  126.         }
  127.         $panel->selected = ($this->selectedIndex == $panel->index);
  128.     }
  129.  
  130.  
  131.     function decode(&$render)
  132.     {
  133.         $this->selectedIndex = (int)FormUtil::getPassedValue("{$this->id}SelectedIndex", 1);
  134.     }
  135. }
  136.  
  137.  
  138. function smarty_block_pnformtabbedpanelset($params, $content, &$render)
  139. {
  140.     return $render->pnFormRegisterBlock('pnFormTabbedPanelSet', $params, $content);

Documentation generated on Fri, 18 Jul 2008 21:43:12 +0200 by phpDocumentor 1.4.1