PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/dinhtrung/yiicorecms/
PHP | 84 lines | 22 code | 7 blank | 55 comment | 1 complexity | 2556b531668805891867ad2b6ae52635 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, CC0-1.0, BSD-2-Clause, GPL-2.0, LGPL-2.1, LGPL-3.0
  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-2011 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 3207 2011-05-12 08:05:26Z mdomba $
  39. * @package zii.widgets.jui
  40. * @since 1.1
  41. */
  42. class CJuiSelectable extends CJuiWidget {
  43. /**
  44. * @var array list of selectable items (id=>item content).
  45. * Note that the item contents will not be HTML-encoded.
  46. */
  47. public $items=array();
  48. /**
  49. * @var string the name of the container element that contains all items. Defaults to 'ol'.
  50. */
  51. public $tagName='ol';
  52. /**
  53. * @var string the template that is used to generated every selectable item.
  54. * The token "{content}" in the template will be replaced with the item content,
  55. * while "{id}" will be replaced with the item ID.
  56. */
  57. public $itemTemplate='<li id="{id}">{content}</li>';
  58. /**
  59. * Run this widget.
  60. * This method registers necessary javascript and renders the needed HTML code.
  61. */
  62. public function run(){
  63. $id=$this->getId();
  64. if (isset($this->htmlOptions['id']))
  65. $id = $this->htmlOptions['id'];
  66. else
  67. $this->htmlOptions['id']=$id;
  68. $options=empty($this->options) ? '' : CJavaScript::encode($this->options);
  69. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').selectable({$options});");
  70. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  71. foreach($this->items as $id=>$content)
  72. {
  73. echo strtr($this->itemTemplate,array('{id}'=>$id,'{content}'=>$content))."\n";
  74. }
  75. echo CHtml::closeTag($this->tagName);
  76. }
  77. }