PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/ashie1287/headfirst
PHP | 86 lines | 21 code | 7 blank | 58 comment | 0 complexity | 0041bbccd901f7cfef661300be8ec360 MD5 | raw file
Possible License(s): BSD-2-Clause, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * CJuiSortable 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. * CJuiSortable displays an accordion widget.
  13. *
  14. * CJuiSortable encapsulates the {@link http://jqueryui.com/demos/sortable/ JUI Sortable}
  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.CJuiSortable', array(
  20. * 'items'=>array(
  21. * 'id1'=>'Item 1',
  22. * 'id2'=>'Item 2',
  23. * 'id3'=>'Item 3',
  24. * ),
  25. * // additional javascript options for the accordion 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 Sortable plugin. Please refer to
  34. * the {@link http://jqueryui.com/demos/sortable/ JUI Sortable} documentation
  35. * for possible options (name-value pairs).
  36. *
  37. * If you are using javascript code anywhere in the code, please add "js:" at the
  38. * start of the js code definition and Yii will use this string as js code.
  39. *
  40. * @author Sebastian Thierer <sebathi@gmail.com>
  41. * @version $Id: CJuiSortable.php 2326 2010-08-20 17:02:07Z qiang.xue $
  42. * @package zii.widgets.jui
  43. * @since 1.1
  44. */
  45. class CJuiSortable extends CJuiWidget
  46. {
  47. /**
  48. * @var array list of sortable items (id=>item content).
  49. * Note that the item contents will not be HTML-encoded.
  50. */
  51. public $items=array();
  52. /**
  53. * @var string the name of the container element that contains all items. Defaults to 'ul'.
  54. */
  55. public $tagName='ul';
  56. /**
  57. * @var string the template that is used to generated every sortable item.
  58. * The token "{content}" in the template will be replaced with the item content,
  59. * while "{id}" be replaced with the item ID.
  60. */
  61. public $itemTemplate='<li id="{id}">{content}</li>';
  62. /**
  63. * Run this widget.
  64. * This method registers necessary javascript and renders the needed HTML code.
  65. */
  66. public function run()
  67. {
  68. $id=$this->getId();
  69. $this->htmlOptions['id']=$id;
  70. $options=empty($this->options) ? '' : CJavaScript::encode($this->options);
  71. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').sortable({$options});");
  72. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  73. foreach($this->items as $id=>$content)
  74. {
  75. echo strtr($this->itemTemplate,array('{id}'=>$id,'{content}'=>$content))."\n";
  76. }
  77. echo CHtml::closeTag($this->tagName);
  78. }
  79. }