From 489633b38216ff71427d8613b0fe9ca446b24ddc Mon Sep 17 00:00:00 2001 From: Alexander Kochetov Date: Sun, 26 May 2013 02:43:24 +0400 Subject: [PATCH] Introducing items --- framework/yii/jui/Sortable.php | 45 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/framework/yii/jui/Sortable.php b/framework/yii/jui/Sortable.php index 1d75cc6..2263461 100644 --- a/framework/yii/jui/Sortable.php +++ b/framework/yii/jui/Sortable.php @@ -15,18 +15,34 @@ use yii\helpers\Html; * For example: * * ```php + * echo Sortable::widget(array( + * 'items' => array( + * '
  • Item 1
  • ', + * '
  • Item 2
  • ', + * '
  • Item 3
  • ', + * ), + * 'clientOptions' => array( + * 'cursor' => 'move', + * ), + * )); + * ``` + * + * The following example will show the content enclosed between the [[begin()]] + * and [[end()]] calls within the sortable widget: + * + * ```php * Sortable::begin(array( * 'clientOptions' => array( * 'cursor' => 'move', * ), * 'options' => array( - * 'tag' => 'ul', + * 'tag' => 'div', * ), * )); * - * echo '
  • Item 1
  • '; - * echo '
  • Item 2
  • '; - * echo '
  • Item 3
  • '; + * echo '
    Item 1
    '; + * echo '
    Item 2
    '; + * echo '
    Item 3
    '; * * Sortable::end(); * ``` @@ -38,13 +54,20 @@ use yii\helpers\Html; class Sortable extends Widget { /** + * @var array list of sortable containers. Each array element represents a single + * sortable container. + */ + public $items = array(); + + + /** * Initializes the widget. */ public function init() { parent::init(); $options = $this->options; - $tag = isset($options['tag']) ? $options['tag'] : 'div'; + $tag = isset($options['tag']) ? $options['tag'] : 'ul'; unset($options['tag']); echo Html::beginTag($tag, $options) . "\n"; } @@ -54,7 +77,17 @@ class Sortable extends Widget */ public function run() { - echo Html::endTag(isset($this->options['tag']) ? $this->options['tag'] : 'div') . "\n"; + echo $this->renderItems() . "\n"; + echo Html::endTag(isset($this->options['tag']) ? $this->options['tag'] : 'ul') . "\n"; $this->registerWidget('sortable', false); } + + /** + * Renders sortable items as specified on [[items]]. + * @return string the rendering result + */ + public function renderItems() + { + return implode("\n", $this->items); + } }