|
|
@ -6,8 +6,6 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
namespace yii\bootstrap; |
|
|
|
namespace yii\bootstrap; |
|
|
|
|
|
|
|
|
|
|
|
use yii\base\InvalidConfigException; |
|
|
|
|
|
|
|
use yii\helpers\Html; |
|
|
|
use yii\helpers\Html; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -61,13 +59,14 @@ class ButtonDropdown extends Widget |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var string the button label |
|
|
|
* @var string the button label |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $label; |
|
|
|
public $label = 'Button'; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var array the HTML attributes of the button. |
|
|
|
* @var array the HTML attributes of the button. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $buttonOptions = array(); |
|
|
|
public $buttonOptions = array(); |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var array list of menu items in the dropdown. Each array element represents a single |
|
|
|
* @var array list of menu items in the dropdown. This will be used to |
|
|
|
|
|
|
|
* set the [[Dropdown::items]] property. Each array element represents a single |
|
|
|
* menu with the following structure: |
|
|
|
* menu with the following structure: |
|
|
|
* |
|
|
|
* |
|
|
|
* - label: string, required, the label of the item link |
|
|
|
* - label: string, required, the label of the item link |
|
|
@ -81,7 +80,7 @@ class ButtonDropdown extends Widget |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $items = array(); |
|
|
|
public $items = array(); |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var boolean whether to display a group or split styled button group. |
|
|
|
* @var boolean whether to display a group of split-styled button group. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $split = false; |
|
|
|
public $split = false; |
|
|
|
/** |
|
|
|
/** |
|
|
@ -93,13 +92,9 @@ class ButtonDropdown extends Widget |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initializes the widget. |
|
|
|
* Initializes the widget. |
|
|
|
* If you override this method, make sure you call the parent implementation first. |
|
|
|
* If you override this method, make sure you call the parent implementation first. |
|
|
|
* @throws InvalidConfigException |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function init() |
|
|
|
public function init() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($this->label === null) { |
|
|
|
|
|
|
|
throw new InvalidConfigException("The 'label' option is required."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parent::init(); |
|
|
|
parent::init(); |
|
|
|
$this->addCssClass($this->options, 'btn-group'); |
|
|
|
$this->addCssClass($this->options, 'btn-group'); |
|
|
|
} |
|
|
|
} |
|
|
@ -111,7 +106,7 @@ class ButtonDropdown extends Widget |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo Html::beginTag('div', $this->options) . "\n"; |
|
|
|
echo Html::beginTag('div', $this->options) . "\n"; |
|
|
|
echo $this->renderButton() . "\n"; |
|
|
|
echo $this->renderButton() . "\n"; |
|
|
|
echo $this->renderItems() . "\n"; |
|
|
|
echo $this->renderDropdown() . "\n"; |
|
|
|
echo Html::endTag('div') . "\n"; |
|
|
|
echo Html::endTag('div') . "\n"; |
|
|
|
$this->registerPlugin('button'); |
|
|
|
$this->registerPlugin('button'); |
|
|
|
} |
|
|
|
} |
|
|
@ -123,7 +118,6 @@ class ButtonDropdown extends Widget |
|
|
|
protected function renderButton() |
|
|
|
protected function renderButton() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->addCssClass($this->buttonOptions, 'btn'); |
|
|
|
$this->addCssClass($this->buttonOptions, 'btn'); |
|
|
|
$splitButton = ''; |
|
|
|
|
|
|
|
if ($this->split) { |
|
|
|
if ($this->split) { |
|
|
|
$tag = 'button'; |
|
|
|
$tag = 'button'; |
|
|
|
$options = $this->buttonOptions; |
|
|
|
$options = $this->buttonOptions; |
|
|
@ -133,8 +127,7 @@ class ButtonDropdown extends Widget |
|
|
|
'label' => '<span class="caret"></span>', |
|
|
|
'label' => '<span class="caret"></span>', |
|
|
|
'encodeLabel' => false, |
|
|
|
'encodeLabel' => false, |
|
|
|
'options' => $this->buttonOptions, |
|
|
|
'options' => $this->buttonOptions, |
|
|
|
) |
|
|
|
)); |
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
$tag = 'a'; |
|
|
|
$tag = 'a'; |
|
|
|
$this->label .= ' <span class="caret"></span>'; |
|
|
|
$this->label .= ' <span class="caret"></span>'; |
|
|
@ -144,6 +137,7 @@ class ButtonDropdown extends Widget |
|
|
|
} |
|
|
|
} |
|
|
|
$this->addCssClass($options, 'dropdown-toggle'); |
|
|
|
$this->addCssClass($options, 'dropdown-toggle'); |
|
|
|
$options['data-toggle'] = 'dropdown'; |
|
|
|
$options['data-toggle'] = 'dropdown'; |
|
|
|
|
|
|
|
$splitButton = ''; |
|
|
|
} |
|
|
|
} |
|
|
|
return Button::widget(array( |
|
|
|
return Button::widget(array( |
|
|
|
'tagName' => $tag, |
|
|
|
'tagName' => $tag, |
|
|
@ -157,11 +151,8 @@ class ButtonDropdown extends Widget |
|
|
|
* Generates the dropdown menu as specified on [[items]]. |
|
|
|
* Generates the dropdown menu as specified on [[items]]. |
|
|
|
* @return string the rendering result. |
|
|
|
* @return string the rendering result. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected function renderItems() |
|
|
|
protected function renderDropdown() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (is_string($this->items)) { |
|
|
|
|
|
|
|
return $this->items; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$config = array('items' => $this->items, 'clientOptions' => false); |
|
|
|
$config = array('items' => $this->items, 'clientOptions' => false); |
|
|
|
return Dropdown::widget($config); |
|
|
|
return Dropdown::widget($config); |
|
|
|
} |
|
|
|
} |
|
|
|