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

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

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