PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/yii/framework/zii/widgets/jui/CJuiAccordion.php

https://github.com/ashie1287/headfirst
PHP | 91 lines | 23 code | 5 blank | 63 comment | 0 complexity | 895bd12e3ac414b30ce1f56592698221 MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * CJuiAccordion class file.
  4. *
  5. * @author Sebastian Thierer <sebathi@gmail.com>
  6. * @author Qiang XUe <qiang.xue@gmail.com>
  7. * @link http://www.yiiframework.com/
  8. * @copyright Copyright &copy; 2008-2010 Yii Software LLC
  9. * @license http://www.yiiframework.com/license/
  10. */
  11. Yii::import('zii.widgets.jui.CJuiWidget');
  12. /**
  13. * CJuiAccordion displays an accordion widget.
  14. *
  15. * CJuiAccordion encapsulates the {@link http://jqueryui.com/demos/accordion/ JUI Accordion}
  16. * plugin.
  17. *
  18. * To use this widget, you may insert the following code in a view:
  19. * <pre>
  20. * $this->widget('zii.widgets.jui.CJuiAccordion', array(
  21. * 'panels'=>array(
  22. * 'panel 1'=>'content for panel 1',
  23. * 'panel 2'=>'content for panel 2',
  24. * // panel 3 contains the content rendered by a partial view
  25. * 'panel 3'=>$this->renderPartial('_partial',null,true),
  26. * ),
  27. * // additional javascript options for the accordion plugin
  28. * 'options'=>array(
  29. * 'animated'=>'bounceslide',
  30. * ),
  31. * ));
  32. * </pre>
  33. *
  34. * By configuring the {@link options} property, you may specify the options
  35. * that need to be passed to the JUI accordion plugin. Please refer to
  36. * the {@link http://jqueryui.com/demos/accordion/ JUI Accordion} documentation
  37. * for possible options (name-value pairs).
  38. *
  39. * @author Sebastian Thierer <sebathi@gmail.com>
  40. * @author Qiang XUe <qiang.xue@gmail.com>
  41. * @version $Id: CJuiAccordion.php 2326 2010-08-20 17:02:07Z qiang.xue $
  42. * @package zii.widgets.jui
  43. * @since 1.1
  44. */
  45. class CJuiAccordion extends CJuiWidget
  46. {
  47. /**
  48. * @var array list of panels (panel title=>panel content).
  49. * Note that neither panel title nor panel content will be HTML-encoded.
  50. */
  51. public $panels=array();
  52. /**
  53. * @var string the name of the container element that contains all panels. Defaults to 'div'.
  54. */
  55. public $tagName='div';
  56. /**
  57. * @var string the template that is used to generated every panel header.
  58. * The token "{title}" in the template will be replaced with the panel title.
  59. * Note that if you make change to this template, you may also need to adjust
  60. * the 'header' setting in {@link options}.
  61. */
  62. public $headerTemplate='<h3><a href="#">{title}</a></h3>';
  63. /**
  64. * @var string the template that is used to generated every panel content.
  65. * The token "{content}" in the template will be replaced with the panel content.
  66. */
  67. public $contentTemplate='<div>{content}</div>';
  68. /**
  69. * Run this widget.
  70. * This method registers necessary javascript and renders the needed HTML code.
  71. */
  72. public function run()
  73. {
  74. $id=$this->getId();
  75. $this->htmlOptions['id']=$id;
  76. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  77. foreach($this->panels as $title=>$content)
  78. {
  79. echo strtr($this->headerTemplate,array('{title}'=>$title))."\n";
  80. echo strtr($this->contentTemplate,array('{content}'=>$content))."\n";
  81. }
  82. echo CHtml::closeTag($this->tagName);
  83. $options=empty($this->options) ? '' : CJavaScript::encode($this->options);
  84. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').accordion($options);");
  85. }
  86. }