You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.5 KiB
110 lines
2.5 KiB
12 years ago
|
<?php
|
||
|
/**
|
||
|
* @link http://www.yiiframework.com/
|
||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||
|
* @license http://www.yiiframework.com/license/
|
||
|
*/
|
||
|
|
||
|
namespace yii\bootstrap;
|
||
|
|
||
12 years ago
|
use yii\helpers\Html;
|
||
12 years ago
|
|
||
|
/**
|
||
|
* ButtonDropdown renders a group or split button dropdown bootstrap component.
|
||
|
*
|
||
|
* For example,
|
||
|
*
|
||
|
* ```php
|
||
|
* // a button group using Dropdown widget
|
||
11 years ago
|
* echo ButtonDropdown::widget([
|
||
12 years ago
|
* 'label' => 'Action',
|
||
11 years ago
|
* 'dropdown' => [
|
||
|
* 'items' => [
|
||
|
* ['label' => 'DropdownA', 'url' => '/'],
|
||
|
* ['label' => 'DropdownB', 'url' => '#'],
|
||
|
* ],
|
||
|
* ],
|
||
|
* ]);
|
||
12 years ago
|
* ```
|
||
|
* @see http://twitter.github.io/bootstrap/javascript.html#buttons
|
||
|
* @see http://twitter.github.io/bootstrap/components.html#buttonDropdowns
|
||
|
* @author Antonio Ramirez <amigo.cobos@gmail.com>
|
||
|
* @since 2.0
|
||
|
*/
|
||
|
class ButtonDropdown extends Widget
|
||
|
{
|
||
|
/**
|
||
|
* @var string the button label
|
||
|
*/
|
||
12 years ago
|
public $label = 'Button';
|
||
12 years ago
|
/**
|
||
|
* @var array the HTML attributes of the button.
|
||
|
*/
|
||
11 years ago
|
public $options = [];
|
||
12 years ago
|
/**
|
||
12 years ago
|
* @var array the configuration array for [[Dropdown]].
|
||
12 years ago
|
*/
|
||
11 years ago
|
public $dropdown = [];
|
||
12 years ago
|
/**
|
||
12 years ago
|
* @var boolean whether to display a group of split-styled button group.
|
||
12 years ago
|
*/
|
||
|
public $split = false;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Renders the widget.
|
||
|
*/
|
||
|
public function run()
|
||
|
{
|
||
12 years ago
|
echo $this->renderButton() . "\n" . $this->renderDropdown();
|
||
12 years ago
|
$this->registerPlugin('button');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Generates the button dropdown.
|
||
|
* @return string the rendering result.
|
||
|
*/
|
||
|
protected function renderButton()
|
||
|
{
|
||
12 years ago
|
Html::addCssClass($this->options, 'btn');
|
||
12 years ago
|
if ($this->split) {
|
||
|
$tag = 'button';
|
||
12 years ago
|
$options = $this->options;
|
||
|
$this->options['data-toggle'] = 'dropdown';
|
||
|
Html::addCssClass($this->options, 'dropdown-toggle');
|
||
11 years ago
|
$splitButton = Button::widget([
|
||
12 years ago
|
'label' => '<span class="caret"></span>',
|
||
|
'encodeLabel' => false,
|
||
12 years ago
|
'options' => $this->options,
|
||
11 years ago
|
]);
|
||
12 years ago
|
} else {
|
||
|
$tag = 'a';
|
||
|
$this->label .= ' <span class="caret"></span>';
|
||
12 years ago
|
$options = $this->options;
|
||
12 years ago
|
if (!isset($options['href'])) {
|
||
|
$options['href'] = '#';
|
||
|
}
|
||
12 years ago
|
Html::addCssClass($options, 'dropdown-toggle');
|
||
12 years ago
|
$options['data-toggle'] = 'dropdown';
|
||
12 years ago
|
$splitButton = '';
|
||
12 years ago
|
}
|
||
11 years ago
|
return Button::widget([
|
||
12 years ago
|
'tagName' => $tag,
|
||
|
'label' => $this->label,
|
||
|
'options' => $options,
|
||
|
'encodeLabel' => false,
|
||
11 years ago
|
]) . "\n" . $splitButton;
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* Generates the dropdown menu.
|
||
12 years ago
|
* @return string the rendering result.
|
||
|
*/
|
||
12 years ago
|
protected function renderDropdown()
|
||
12 years ago
|
{
|
||
12 years ago
|
$config = $this->dropdown;
|
||
|
$config['clientOptions'] = false;
|
||
12 years ago
|
return Dropdown::widget($config);
|
||
|
}
|
||
12 years ago
|
}
|