Browse Source

Merge pull request #352 from creocoder/bootstrap-refactoring

`yii\bootstrap\*` another refactioring
tags/2.0.0-alpha
Qiang Xue 12 years ago
parent
commit
b6b3e7fdda
  1. 4
      framework/yii/bootstrap/Modal.php
  2. 11
      framework/yii/bootstrap/TypeAhead.php
  3. 12
      framework/yii/bootstrap/Widget.php

4
framework/yii/bootstrap/Modal.php

@ -217,9 +217,9 @@ class Modal extends Widget
), $this->options);
$this->addCssClass($this->options, 'modal');
$this->pluginOptions = array_merge(array(
$this->clientOptions = array_merge(array(
'show' => false,
), $this->pluginOptions);
), $this->clientOptions);
if ($this->closeButton !== null) {
$this->closeButton = array_merge(array(

11
framework/yii/bootstrap/TypeAhead.php

@ -19,10 +19,9 @@ use yii\helpers\Html;
*
* ```php
* echo TypeAhead::widget(array(
* 'form' => $form,
* 'model' => $model,
* 'attribute' => 'country',
* 'pluginOptions' => array(
* 'clientOptions' => array(
* 'source' => array('USA', 'ESP'),
* ),
* ));
@ -33,7 +32,7 @@ use yii\helpers\Html;
* ```php
* echo TypeAhead::widget(array(
* 'name' => 'country',
* 'pluginOptions' => array(
* 'cloentOptions' => array(
* 'source' => array('USA', 'ESP'),
* ),
* ));
@ -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
* the [[name]] attribute.
* @return string the rendering result
* @throws InvalidConfigException when none of the required attributes are set to render the textInput. That is,
* if [[model]] and [[attribute]] are not set, then [[name]] is required.
* @throws InvalidConfigException when none of the required attributes are set to render the textInput.
* That is, if [[model]] and [[attribute]] are not set, then [[name]] is required.
*/
public function renderField()
{
@ -87,7 +86,7 @@ class TypeAhead extends Widget
} elseif ($this->name !== null) {
return Html::textInput($this->name, $this->value, $this->options);
} 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.");
}
}
}

12
framework/yii/bootstrap/Widget.php

@ -35,14 +35,14 @@ class Widget extends \yii\base\Widget
* 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").
*/
public $pluginOptions = array();
public $clientOptions = array();
/**
* @var array the event handlers for the underlying Bootstrap JS plugin.
* 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
* 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
$view->registerAssetBundle(static::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap');
$view->registerAssetBundle("yii/bootstrap/$name");
if ($this->pluginOptions !== false) {
$options = empty($this->pluginOptions) ? '' : Json::encode($this->pluginOptions);
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
$js = "jQuery('#$id').$name($options);";
$view->registerJs($js);
}
if (!empty($this->pluginEvents)) {
if (!empty($this->clientEvents)) {
$js = array();
foreach ($this->pluginEvents as $event => $handler) {
foreach ($this->clientEvents as $event => $handler) {
$js[] = "jQuery('#$id').on('$event', $handler);";
}
$view->registerJs(implode("\n", $js));

Loading…
Cancel
Save