Browse Source

Fixes #6672: `yii\bootstrap\Dropdown` should register client event handlers

tags/2.0.2
Qiang Xue 10 years ago
parent
commit
5ccdca1703
  1. 2
      extensions/bootstrap/CHANGELOG.md
  2. 1
      extensions/bootstrap/Dropdown.php
  3. 12
      extensions/bootstrap/Widget.php
  4. 2
      extensions/jui/Widget.php

2
extensions/bootstrap/CHANGELOG.md

@ -4,7 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
2.0.2 under development 2.0.2 under development
----------------------- -----------------------
- no changes in this release. - Bug #6672: `yii\bootstrap\Dropdown` should register client event handlers (qiangxue)
2.0.1 December 07, 2014 2.0.1 December 07, 2014

1
extensions/bootstrap/Dropdown.php

@ -60,6 +60,7 @@ class Dropdown extends Widget
{ {
echo $this->renderItems($this->items, $this->options); echo $this->renderItems($this->items, $this->options);
BootstrapPluginAsset::register($this->getView()); BootstrapPluginAsset::register($this->getView());
$this->registerClientEvents();
} }
/** /**

12
extensions/bootstrap/Widget.php

@ -71,12 +71,22 @@ class Widget extends \yii\base\Widget
$view->registerJs($js); $view->registerJs($js);
} }
$this->registerClientEvents();
}
/**
* Registers JS event handlers that are listed in [[clientEvents]].
* @since 2.0.2
*/
protected function registerClientEvents()
{
if (!empty($this->clientEvents)) { if (!empty($this->clientEvents)) {
$id = $this->options['id'];
$js = []; $js = [];
foreach ($this->clientEvents 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)); $this->getView()->registerJs(implode("\n", $js));
} }
} }
} }

2
extensions/jui/Widget.php

@ -48,7 +48,7 @@ class Widget extends \yii\base\Widget
public $clientEvents = []; public $clientEvents = [];
/** /**
* @var array event names mapped to what should be specified in .on( * @var array event names mapped to what should be specified in `.on()`.
* If empty, it is assumed that event passed to clientEvents is prefixed with widget name. * If empty, it is assumed that event passed to clientEvents is prefixed with widget name.
*/ */
protected $clientEventMap = []; protected $clientEventMap = [];

Loading…
Cancel
Save