|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
-
-
- namespace yii\bootstrap;
-
- use Yii;
- use yii\helpers\Json;
-
-
- trait BootstrapWidgetTrait
- {
-
-
- public $clientOptions = [];
-
-
- public $clientEvents = [];
-
-
-
-
- public function init()
- {
- parent::init();
- if (!isset($this->options['id'])) {
- $this->options['id'] = $this->getId();
- }
- }
-
-
-
- protected function registerPlugin($name)
- {
- $view = $this->getView();
-
- BootstrapPluginAsset::register($view);
-
- $id = $this->options['id'];
-
- if ($this->clientOptions !== false) {
- $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
- $js = "jQuery('#$id').$name($options);";
- $view->registerJs($js);
- }
-
- $this->registerClientEvents();
- }
-
-
-
- protected function registerClientEvents()
- {
- if (!empty($this->clientEvents)) {
- $id = $this->options['id'];
- $js = [];
- foreach ($this->clientEvents as $event => $handler) {
- $js[] = "jQuery('#$id').on('$event', $handler);";
- }
- $this->getView()->registerJs(implode("\n", $js));
- }
- }
-
-
-
- abstract function getView();
- }
|