|
|
@ -15,18 +15,34 @@ use yii\helpers\Html; |
|
|
|
* For example: |
|
|
|
* For example: |
|
|
|
* |
|
|
|
* |
|
|
|
* ```php |
|
|
|
* ```php |
|
|
|
|
|
|
|
* echo Sortable::widget(array( |
|
|
|
|
|
|
|
* 'items' => array( |
|
|
|
|
|
|
|
* '<li>Item 1</li>', |
|
|
|
|
|
|
|
* '<li>Item 2</li>', |
|
|
|
|
|
|
|
* '<li>Item 3</li>', |
|
|
|
|
|
|
|
* ), |
|
|
|
|
|
|
|
* '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( |
|
|
|
* Sortable::begin(array( |
|
|
|
* 'clientOptions' => array( |
|
|
|
* 'clientOptions' => array( |
|
|
|
* 'cursor' => 'move', |
|
|
|
* 'cursor' => 'move', |
|
|
|
* ), |
|
|
|
* ), |
|
|
|
* 'options' => array( |
|
|
|
* 'options' => array( |
|
|
|
* 'tag' => 'ul', |
|
|
|
* 'tag' => 'div', |
|
|
|
* ), |
|
|
|
* ), |
|
|
|
* )); |
|
|
|
* )); |
|
|
|
* |
|
|
|
* |
|
|
|
* echo '<li>Item 1</li>'; |
|
|
|
* echo '<div>Item 1</div>'; |
|
|
|
* echo '<li>Item 2</li>'; |
|
|
|
* echo '<div>Item 2</div>'; |
|
|
|
* echo '<li>Item 3</li>'; |
|
|
|
* echo '<div>Item 3</div>'; |
|
|
|
* |
|
|
|
* |
|
|
|
* Sortable::end(); |
|
|
|
* Sortable::end(); |
|
|
|
* ``` |
|
|
|
* ``` |
|
|
@ -38,13 +54,20 @@ use yii\helpers\Html; |
|
|
|
class Sortable extends Widget |
|
|
|
class Sortable extends Widget |
|
|
|
{ |
|
|
|
{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* @var array list of sortable containers. Each array element represents a single |
|
|
|
|
|
|
|
* sortable container. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public $items = array(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Initializes the widget. |
|
|
|
* Initializes the widget. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function init() |
|
|
|
public function init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
parent::init(); |
|
|
|
parent::init(); |
|
|
|
$options = $this->options; |
|
|
|
$options = $this->options; |
|
|
|
$tag = isset($options['tag']) ? $options['tag'] : 'div'; |
|
|
|
$tag = isset($options['tag']) ? $options['tag'] : 'ul'; |
|
|
|
unset($options['tag']); |
|
|
|
unset($options['tag']); |
|
|
|
echo Html::beginTag($tag, $options) . "\n"; |
|
|
|
echo Html::beginTag($tag, $options) . "\n"; |
|
|
|
} |
|
|
|
} |
|
|
@ -54,7 +77,17 @@ class Sortable extends Widget |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function run() |
|
|
|
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); |
|
|
|
$this->registerWidget('sortable', false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Renders sortable items as specified on [[items]]. |
|
|
|
|
|
|
|
* @return string the rendering result |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public function renderItems() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return implode("\n", $this->items); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|