/**
  * Registers the needed assets
  */
 public function registerColorInput()
 {
     $view = $this->getView();
     ColorInputAsset::register($view);
     if ($this->useNative) {
         return;
     }
     if ($this->showDefaultPalette) {
         $palette = Json::encode($this->_defaultPalette);
         $this->_paletteVar = 'kvPalette_' . hash('crc32', $palette);
         $view->registerJs("var {$this->_paletteVar}={$palette};", View::POS_HEAD);
         $this->pluginOptions['palette'] = new JsExpression($this->_paletteVar);
     }
     Html5InputAsset::register($view);
     $input = 'jQuery("#' . $this->html5Options['id'] . '")';
     $el = 'jQuery("#' . $this->options['id'] . '")';
     $this->registerPlugin('spectrum', $input, "function(){{$input}.spectrum('set',{$el}.val());}");
 }
示例#2
0
    /**
     *
     * Registers the needed assets
     */
    public function registerAssets()
    {
        $view = $this->getView();
        $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
        $this->html5Options['value'] = $value;
        ColorInputAsset::register($view);
        if ($this->useNative) {
            parent::registerAssets();
            return;
        }
        \kartik\base\Html5InputAsset::register($view);
        $caption = 'jQuery("#' . $this->options['id'] . '")';
        $input = 'jQuery("#' . $this->html5Options['id'] . '")';
        $this->pluginOptions['change'] = new JsExpression("function(color){\n            _.delay(function()\n            {\n                {$caption}.val(color." . $this->saveValueAs . "());\n            }, 500);\n        }");
        $this->registerPlugin('spectrum', $input);
        $js = <<<JS
{$input}.spectrum('set','{$value}');
{$caption}.on('change', function(){
    {$input}.spectrum('set',{$caption}.val());
});
JS;
        $view->registerJs($js);
    }