macgyer\yii2materializecss\lib\MaterializeWidgetTrait::registerPlugin PHP Method

registerPlugin() protected method

Registers a specific Materialize plugin and the related events.
protected registerPlugin ( string $name, string | null $selector = null )
$name string the name of the Materialize plugin
$selector string | null the name of the selector the plugin shall be attached to
    protected function registerPlugin($name, $selector = null)
    {
        $view = $this->getView();
        MaterializePluginAsset::register($view);
        $id = $this->options['id'];
        if (is_null($selector)) {
            $selector = '#' . $id;
        }
        if ($this->clientOptions !== false) {
            $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
            $js = "jQuery('{$selector}').{$name}({$options});";
            $view->registerJs($js);
        }
        $this->registerClientEvents();
    }