Пример #1
0
    public function registerAssets()
    {
        $view = $this->getView();
        if (!empty($this->language) && $this->language != 'en' && $this->language != 'en_US') {
            Select2Asset::register($view)->js[] = 'js/i18n/' . $this->language . '.js';
        } else {
            Select2Asset::register($view);
        }
        $this->pluginOptions['width'] = 'resolve';
        if ($this->pluginLoading) {
            $id = $this->options['id'];
            $loading = "\$('.kv-plugin-loading.loading-{$id}')";
            $groupCss = "group-{$id}";
            $group = "\$('.kv-hide.{$groupCss}')";
            $el = "\$('#{$id}')";
            $callback = <<<JS
function(){
    var \$container = {$el}.select2('open');
    {$el}.removeClass('kv-hide');
    \$container.removeClass('kv-hide');
    {$loading}.remove();
    if (Object.keys({$group}).length > 0) {
        {$group}.removeClass('kv-hide').removeClass('{$groupCss}');
    }
}
JS;
            $this->registerPlugin('select2', $el, $callback);
        } else {
            $this->registerPlugin('select2');
        }
    }
Пример #2
0
 /**
  * Register widget asset.
  */
 public function registerClientScript()
 {
     $view = $this->getView();
     $selector = '#' . $this->options['id'];
     $settings = Json::encode($this->settings);
     // Register asset
     $asset = Select2Asset::register($view);
     // Init widget
     $view->registerJs(new JsExpression("\$('{$selector}').select2({$settings});"), \yii\web\View::POS_READY);
 }
Пример #3
0
 /**
  * Register widget asset.
  */
 public function registerClientScript()
 {
     $view = $this->getView();
     $selector = '#' . $this->options['id'];
     $settings = Json::encode($this->settings);
     // Register asset
     $asset = Asset::register($view);
     if ($this->language !== null) {
         $asset->language = $this->language;
     }
     if ($this->bootstrap === true) {
         BootstrapAsset::register($view);
     } else {
         Select2Asset::register($view);
     }
     // Init widget
     $view->registerJs("jQuery('{$selector}').select2({$settings});", $view::POS_READY, self::INLINE_JS_KEY . $this->options['id']);
     // Register events
     $this->registerEvents();
 }