Exemplo n.º 1
0
 /**
  * Registers the needed assets
  */
 public function registerAssets()
 {
     $view = $this->getView();
     SwitchInputAsset::register($view);
     if (empty($this->pluginOptions['animate'])) {
         $this->pluginOptions['animate'] = true;
     }
     $this->pluginOptions['indeterminate'] = $this->tristate && $this->value === $this->indeterminateValue && $this->type !== self::RADIO;
     $this->pluginOptions['disabled'] = $this->disabled;
     $this->pluginOptions['readonly'] = $this->readonly;
     $id = $this->type == self::RADIO ? 'jQuery("[name = \'' . $this->name . '\']")' : 'jQuery("#' . $this->options['id'] . '")';
     $this->registerPlugin($this->pluginName, $id);
     if (!$this->tristate || $this->indeterminateToggle === false || $this->type == self::RADIO) {
         return;
     }
     $tog = 'jQuery("[data-kv-switch=\'' . $this->options['id'] . '\']")';
     $js = "{$tog}.on('click',function(){\n    var \$el={$id}, val;\n    \$el.bootstrapSwitch('toggleIndeterminate');            \n    val = \$el.prop('indeterminate') ? '{$this->indeterminateValue}' : \n        (\$el.is(':checked').length > 0 ? 1 : 0);\n    \$el.val(val);\n});";
     $view->registerJs($js);
 }
Exemplo n.º 2
0
    /**
     * Registers the needed assets
     */
    public function registerAssets()
    {
        $view = $this->getView();
        SwitchInputAsset::register($view);
        if (!isset($this->pluginOptions['animate']) || !is_bool($this->pluginOptions['animate'])) {
            $this->pluginOptions['animate'] = true;
        }
        $ind = $this->indeterminateValue;
        $this->pluginOptions['indeterminate'] = $this->tristate && $this->value === $ind && $this->type !== self::RADIO;
        $this->pluginOptions['disabled'] = $this->disabled;
        $this->pluginOptions['readonly'] = $this->readonly;
        $id = $this->type == self::RADIO ? 'jQuery("[name = \'' . $this->name . '\']")' : 'jQuery("#' . $this->options['id'] . '")';
        $this->registerPlugin($this->pluginName, $id);
        if (!$this->tristate || $this->indeterminateToggle === false || $this->type == self::RADIO) {
            return;
        }
        $tog = 'jQuery("[data-kv-switch=\'' . $this->options['id'] . '\']")';
        $js = <<<JS
{$tog}.on('click',function(){
    var el={$id}, val;
    el.{$this->pluginName}('toggleIndeterminate');
    val = el.prop('indeterminate') ? '{$ind}' : (el.is(':checked').length > 0 ? 1 : 0);
    el.val(val);
});
JS;
        $view->registerJs($js);
    }