Commit b6b3e7fd by Qiang Xue

Merge pull request #352 from creocoder/bootstrap-refactoring

`yii\bootstrap\*` another refactioring
parents b317c082 c5e93efd
...@@ -217,9 +217,9 @@ class Modal extends Widget ...@@ -217,9 +217,9 @@ class Modal extends Widget
), $this->options); ), $this->options);
$this->addCssClass($this->options, 'modal'); $this->addCssClass($this->options, 'modal');
$this->pluginOptions = array_merge(array( $this->clientOptions = array_merge(array(
'show' => false, 'show' => false,
), $this->pluginOptions); ), $this->clientOptions);
if ($this->closeButton !== null) { if ($this->closeButton !== null) {
$this->closeButton = array_merge(array( $this->closeButton = array_merge(array(
......
...@@ -19,10 +19,9 @@ use yii\helpers\Html; ...@@ -19,10 +19,9 @@ use yii\helpers\Html;
* *
* ```php * ```php
* echo TypeAhead::widget(array( * echo TypeAhead::widget(array(
* 'form' => $form,
* 'model' => $model, * 'model' => $model,
* 'attribute' => 'country', * 'attribute' => 'country',
* 'pluginOptions' => array( * 'clientOptions' => array(
* 'source' => array('USA', 'ESP'), * 'source' => array('USA', 'ESP'),
* ), * ),
* )); * ));
...@@ -33,7 +32,7 @@ use yii\helpers\Html; ...@@ -33,7 +32,7 @@ use yii\helpers\Html;
* ```php * ```php
* echo TypeAhead::widget(array( * echo TypeAhead::widget(array(
* 'name' => 'country', * 'name' => 'country',
* 'pluginOptions' => array( * 'cloentOptions' => array(
* 'source' => array('USA', 'ESP'), * 'source' => array('USA', 'ESP'),
* ), * ),
* )); * ));
...@@ -77,8 +76,8 @@ class TypeAhead extends Widget ...@@ -77,8 +76,8 @@ class TypeAhead extends Widget
* If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to * If [[model]] is null or not from an [[Model]] instance, then the field will be rendered according to
* the [[name]] attribute. * the [[name]] attribute.
* @return string the rendering result * @return string the rendering result
* @throws InvalidConfigException when none of the required attributes are set to render the textInput. That is, * @throws InvalidConfigException when none of the required attributes are set to render the textInput.
* if [[model]] and [[attribute]] are not set, then [[name]] is required. * That is, if [[model]] and [[attribute]] are not set, then [[name]] is required.
*/ */
public function renderField() public function renderField()
{ {
...@@ -87,7 +86,7 @@ class TypeAhead extends Widget ...@@ -87,7 +86,7 @@ class TypeAhead extends Widget
} elseif ($this->name !== null) { } elseif ($this->name !== null) {
return Html::textInput($this->name, $this->value, $this->options); 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.");
} }
} }
} }
...@@ -35,14 +35,14 @@ class Widget extends \yii\base\Widget ...@@ -35,14 +35,14 @@ class Widget extends \yii\base\Widget
* 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 $pluginOptions = 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 $pluginEvents = array(); public $clientEvents = array();
/** /**
...@@ -69,15 +69,15 @@ class Widget extends \yii\base\Widget ...@@ -69,15 +69,15 @@ class Widget extends \yii\base\Widget
$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->pluginOptions !== false) { if ($this->clientOptions !== false) {
$options = empty($this->pluginOptions) ? '' : Json::encode($this->pluginOptions); $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->pluginEvents)) { if (!empty($this->clientEvents)) {
$js = array(); $js = array();
foreach ($this->pluginEvents 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