Commit 512a9bd1 by Alexander Kochetov

clientOptions and clientEvents

parent 6ca204a0
...@@ -79,7 +79,7 @@ class Alert extends Widget ...@@ -79,7 +79,7 @@ class Alert extends Widget
$this->initOptions(); $this->initOptions();
echo Html::beginTag('div', $this->htmlOptions) . "\n"; echo Html::beginTag('div', $this->options) . "\n";
echo $this->renderBodyBegin() . "\n"; echo $this->renderBodyBegin() . "\n";
} }
...@@ -136,11 +136,11 @@ class Alert extends Widget ...@@ -136,11 +136,11 @@ class Alert extends Widget
*/ */
protected function initOptions() protected function initOptions()
{ {
$this->htmlOptions = array_merge(array( $this->options = array_merge(array(
'class' => 'fade in', 'class' => 'fade in',
), $this->htmlOptions); ), $this->options);
$this->addCssClass($this->htmlOptions, 'alert'); $this->addCssClass($this->options, 'alert');
if ($this->closeButton !== null) { if ($this->closeButton !== null) {
$this->closeButton = array_merge(array( $this->closeButton = array_merge(array(
......
...@@ -105,7 +105,7 @@ class Modal extends Widget ...@@ -105,7 +105,7 @@ class Modal extends Widget
$this->initOptions(); $this->initOptions();
echo $this->renderToggleButton() . "\n"; echo $this->renderToggleButton() . "\n";
echo Html::beginTag('div', $this->htmlOptions) . "\n"; echo Html::beginTag('div', $this->options) . "\n";
echo $this->renderHeader() . "\n"; echo $this->renderHeader() . "\n";
echo $this->renderBodyBegin() . "\n"; echo $this->renderBodyBegin() . "\n";
} }
...@@ -212,14 +212,14 @@ class Modal extends Widget ...@@ -212,14 +212,14 @@ class Modal extends Widget
*/ */
protected function initOptions() protected function initOptions()
{ {
$this->htmlOptions = array_merge(array( $this->options = array_merge(array(
'class' => 'modal hide', 'class' => 'modal hide',
), $this->htmlOptions); ), $this->options);
$this->addCssClass($this->htmlOptions, 'modal'); $this->addCssClass($this->options, 'modal');
$this->options = array_merge(array( $this->clientOptions = array_merge(array(
'show' => false, 'show' => false,
), $this->options); ), $this->clientOptions);
if ($this->closeButton !== null) { if ($this->closeButton !== null) {
$this->closeButton = array_merge(array( $this->closeButton = array_merge(array(
...@@ -234,7 +234,7 @@ class Modal extends Widget ...@@ -234,7 +234,7 @@ class Modal extends Widget
'data-toggle' => 'modal', 'data-toggle' => 'modal',
), $this->toggleButton); ), $this->toggleButton);
if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) { if (!isset($this->toggleButton['data-target']) && !isset($this->toggleButton['href'])) {
$this->toggleButton['data-target'] = '#' . $this->htmlOptions['id']; $this->toggleButton['data-target'] = '#' . $this->options['id'];
} }
} }
} }
......
...@@ -21,7 +21,7 @@ use yii\helpers\Html; ...@@ -21,7 +21,7 @@ use yii\helpers\Html;
* echo TypeAhead::widget(array( * echo TypeAhead::widget(array(
* 'model' => $model, * 'model' => $model,
* 'attribute' => 'country', * 'attribute' => 'country',
* 'options' => array( * 'clientOptions' => array(
* 'source' => array('USA', 'ESP'), * 'source' => array('USA', 'ESP'),
* ), * ),
* )); * ));
...@@ -32,7 +32,7 @@ use yii\helpers\Html; ...@@ -32,7 +32,7 @@ use yii\helpers\Html;
* ```php * ```php
* echo TypeAhead::widget(array( * echo TypeAhead::widget(array(
* 'name' => 'country', * 'name' => 'country',
* 'options' => array( * 'cloentOptions' => array(
* 'source' => array('USA', 'ESP'), * 'source' => array('USA', 'ESP'),
* ), * ),
* )); * ));
...@@ -82,9 +82,9 @@ class TypeAhead extends Widget ...@@ -82,9 +82,9 @@ class TypeAhead extends Widget
public function renderField() public function renderField()
{ {
if ($this->model instanceof Model && $this->attribute !== null) { if ($this->model instanceof Model && $this->attribute !== null) {
return Html::activeTextInput($this->model, $this->attribute, $this->htmlOptions); return Html::activeTextInput($this->model, $this->attribute, $this->options);
} elseif ($this->name !== null) { } elseif ($this->name !== null) {
return Html::textInput($this->name, $this->value, $this->htmlOptions); return Html::textInput($this->name, $this->value, $this->options);
} else { } else {
throw new InvalidConfigException("Either 'name' or 'model' and 'attribute' properties must be specified."); throw new InvalidConfigException("Either 'name' or 'model' and 'attribute' properties must be specified.");
} }
......
...@@ -28,21 +28,21 @@ class Widget extends \yii\base\Widget ...@@ -28,21 +28,21 @@ class Widget extends \yii\base\Widget
/** /**
* @var array the HTML attributes for the widget container tag. * @var array the HTML attributes for the widget container tag.
*/ */
public $htmlOptions = array(); public $options = array();
/** /**
* @var array the options for the underlying Bootstrap JS plugin. * @var array the options for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible options. * Please refer to the corresponding Bootstrap plugin Web page for possible options.
* For example, [this page](http://twitter.github.io/bootstrap/javascript.html#modals) shows * For example, [this page](http://twitter.github.io/bootstrap/javascript.html#modals) shows
* how to use the "Modal" plugin and the supported options (e.g. "remote"). * how to use the "Modal" plugin and the supported options (e.g. "remote").
*/ */
public $options = array(); public $clientOptions = array();
/** /**
* @var array the event handlers for the underlying Bootstrap JS plugin. * @var array the event handlers for the underlying Bootstrap JS plugin.
* Please refer to the corresponding Bootstrap plugin Web page for possible events. * Please refer to the corresponding Bootstrap plugin Web page for possible events.
* For example, [this page](http://twitter.github.io/bootstrap/javascript.html#modals) shows * For example, [this page](http://twitter.github.io/bootstrap/javascript.html#modals) shows
* how to use the "Modal" plugin and the supported events (e.g. "shown"). * how to use the "Modal" plugin and the supported events (e.g. "shown").
*/ */
public $events = array(); public $clientEvents = array();
/** /**
...@@ -53,8 +53,8 @@ class Widget extends \yii\base\Widget ...@@ -53,8 +53,8 @@ class Widget extends \yii\base\Widget
public function init() public function init()
{ {
parent::init(); parent::init();
if (!isset($this->options['id'])) { if (!isset($this->clientOptions['id'])) {
$this->options['id'] = $this->getId(); $this->clientOptions['id'] = $this->getId();
} }
} }
...@@ -64,20 +64,20 @@ class Widget extends \yii\base\Widget ...@@ -64,20 +64,20 @@ class Widget extends \yii\base\Widget
*/ */
protected function registerPlugin($name) protected function registerPlugin($name)
{ {
$id = $this->options['id']; $id = $this->clientOptions['id'];
$view = $this->getView(); $view = $this->getView();
$view->registerAssetBundle(static::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap'); $view->registerAssetBundle(static::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap');
$view->registerAssetBundle("yii/bootstrap/$name"); $view->registerAssetBundle("yii/bootstrap/$name");
if ($this->options !== false) { if ($this->clientOptions !== false) {
$options = empty($this->options) ? '' : Json::encode($this->options); $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "jQuery('#$id').$name($options);"; $js = "jQuery('#$id').$name($options);";
$view->registerJs($js); $view->registerJs($js);
} }
if (!empty($this->events)) { if (!empty($this->clientEvents)) {
$js = array(); $js = array();
foreach ($this->events as $event => $handler) { foreach ($this->clientEvents as $event => $handler) {
$js[] = "jQuery('#$id').on('$event', $handler);"; $js[] = "jQuery('#$id').on('$event', $handler);";
} }
$view->registerJs(implode("\n", $js)); $view->registerJs(implode("\n", $js));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment