/**
  * Registers Assets
  */
 public function registerAssets()
 {
     $view = $this->getView();
     $bandle = Select2Asset::register($view);
     if ($this->language !== false) {
         $langs[0] = $this->language ? $this->language : \Yii::$app->language;
         if (strpos($langs[0], '-') > 0) {
             $langs[1] = explode('-', $langs[0])[0];
         }
         foreach ($langs as $lang) {
             $langFile = "/js/i18n/{$lang}.js";
             if (file_exists($bandle->sourcePath . $langFile)) {
                 $view->registerJsFile($bandle->baseUrl . $langFile, ['depends' => Select2Asset::className()]);
                 break;
             }
         }
     }
     if ($this->bootstrap) {
         Select2BootstrapAsset::register($view);
     }
     $id = $this->options['id'];
     $settings = Json::encode($this->settings);
     $js = "jQuery('#{$id}').select2({$settings});";
     $view->registerJs($js);
 }
 /**
  * Registers Assets
  */
 public function registerAssets()
 {
     $view = $this->getView();
     /* @var $bandle yii\web\AssetBundle */
     $bandle = Select2Asset::register($view);
     if ($this->language !== false) {
         $langs[0] = $this->language ? $this->language : \Yii::$app->language;
         if (($pos = strpos($langs[0], '-')) > 0) {
             // If "en-us" is not found, try to use "en".
             $langs[1] = substr($langs[0], 0, $pos);
         }
         foreach ($langs as $lang) {
             $langFile = "/js/i18n/{$lang}.js";
             if (file_exists($bandle->sourcePath . $langFile)) {
                 $view->registerJsFile($bandle->baseUrl . $langFile, ['depends' => Select2Asset::className()]);
                 break;
             }
         }
     }
     if ($this->bootstrap) {
         Select2BootstrapAsset::register($view);
     }
     $settings = Json::encode($this->settings);
     $js = "jQuery('#{$this->options['id']}').select2({$settings})";
     if ($this->maximize) {
         Select2MaximizeAsset::register($view);
         if (is_integer($this->maximize)) {
             $this->maximize = "{cushion: {$this->maximize}}";
         } elseif (is_array($this->maximize)) {
             $this->maximize = Json::encode($this->maximize);
         } else {
             $this->maximize = '{}';
         }
         $js .= ".maximizeSelect2Height({$this->maximize})";
     }
     foreach ($this->events as $event => $handler) {
         $js .= '.on("' . $event . '", ' . new yii\web\JsExpression($handler) . ')';
     }
     $view->registerJs("{$js};");
 }
 /**
  * Registers Assets
  */
 public function registerAssets()
 {
     $view = $this->getView();
     $bandle = Select2Asset::register($view);
     if ($this->language !== false) {
         $langs[0] = $this->language ? $this->language : \Yii::$app->language;
         if (($pos = strpos($langs[0], '-')) > 0) {
             // If "en-us" is not found, try to use "en".
             $langs[1] = substr($langs[0], 0, $pos);
         }
         foreach ($langs as $lang) {
             $langFile = "/js/i18n/{$lang}.js";
             if (file_exists($bandle->sourcePath . $langFile)) {
                 $view->registerJsFile($bandle->baseUrl . $langFile, ['depends' => Select2Asset::className()]);
                 break;
             }
         }
     }
     if ($this->bootstrap) {
         Select2BootstrapAsset::register($view);
     }
     $settings = Json::encode($this->settings);
     $view->registerJs("jQuery('#{$this->options['id']}').select2({$settings});");
 }
Beispiel #4
0
 /**
  * Registers Assets
  */
 public function registerAssets()
 {
     $view = $this->getView();
     Select2Asset::register($view);
     if ($this->bootstrap) {
         Select2BootstrapAsset::register($view);
     }
     $id = $this->options['id'];
     $settings = Json::encode($this->settings);
     $js = "jQuery('#{$id}').select2({$settings});";
     $view->registerJs($js);
 }