PageRenderTime 67ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/dinhtrung/yiicorecms/
PHP | 89 lines | 24 code | 7 blank | 58 comment | 1 complexity | 7b5b0ad4dacb7f9ec1850e1360b1c71d 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. * CJuiSortable 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. * CJuiSortable makes selected elements sortable by dragging with the mouse.
  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 3217 2011-05-12 23:59:50Z alexander.makarow $
  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. if (isset($this->htmlOptions['id']))
  70. $id = $this->htmlOptions['id'];
  71. else
  72. $this->htmlOptions['id']=$id;
  73. $options=empty($this->options) ? '' : CJavaScript::encode($this->options);
  74. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').sortable({$options});");
  75. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  76. foreach($this->items as $id=>$content)
  77. {
  78. echo strtr($this->itemTemplate,array('{id}'=>$id,'{content}'=>$content))."\n";
  79. }
  80. echo CHtml::closeTag($this->tagName);
  81. }
  82. }