Skip to content

Commit c00c3fc

Browse files
committed
Update to release v1.0.1
1 parent df76ee8 commit c00c3fc

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

CHANGE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Change Log: `yii2-widget-colorinput`
99
- (enh #10): Update to latest version of spectrum plugin.
1010
- (enh #11): Implement translations and locales.
1111
- (enh #12): Implement theming for Krajee style.
12-
- (enh #13): Eliminate `polyFill` property.
1312

1413
## Version 1.0.0
1514

ColorInput.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,12 @@ class ColorInput extends Html5Input
148148
/**
149149
* @inheritdoc
150150
*/
151-
public function init()
151+
public function run()
152152
{
153153
$this->type = 'color';
154154
$this->width = '60px';
155-
parent::init();
156-
}
157-
158-
/**
159-
* @inheritdoc
160-
*/
161-
public function run()
162-
{
163155
$this->_msgCat = 'kvcolor';
156+
$this->html5Options['value'] = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
164157
$this->initI18N(__DIR__);
165158
if (substr($this->language, 0, 2) !== 'en') {
166159
$this->_defaultOptions += [
@@ -177,8 +170,9 @@ public function run()
177170
Html::addCssClass($this->options, 'spectrum-input');
178171
if (!$this->useNative) {
179172
Html::addCssClass($this->html5Container, 'input-group-sp');
180-
$this->pluginOptions = ArrayHelper::merge($this->_defaultOptions, $this->pluginOptions);
173+
$this->pluginOptions = array_replace_recursive($this->_defaultOptions, $this->pluginOptions);
181174
}
175+
$this->initInput();
182176
$this->registerColorInput();
183177
}
184178

@@ -188,8 +182,6 @@ public function run()
188182
public function registerColorInput()
189183
{
190184
$view = $this->getView();
191-
$value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
192-
$this->html5Options['value'] = $value;
193185
ColorInputAsset::register($view);
194186
if ($this->useNative) {
195187
return;
@@ -202,6 +194,7 @@ public function registerColorInput()
202194
}
203195
Html5InputAsset::register($view);
204196
$input = 'jQuery("#' . $this->html5Options['id'] . '")';
205-
$this->registerPlugin('spectrum', $input);
197+
$el = 'jQuery("#' . $this->options['id'] . '")';
198+
$this->registerPlugin('spectrum', $input, "function(){{$input}.spectrum('set',{$el}.val());}");
206199
}
207200
}

assets/js/spectrum-kv.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"use strict";
1313
$(document).on('ready', function () {
1414
$('.spectrum-group').on('change', 'input', function (e, color) {
15-
var $el = $(this), $group = $el.closest('.spectrum-group');
15+
var $el = $(this), $group = $el.closest('.spectrum-group'), val = $el.val();
1616
if ($el.is('.spectrum-source')) {
1717
$group.find('.spectrum-input').val(color.toString());
18-
} else {
19-
$group.find('.spectrum-source').spectrum('set', $el.val());
18+
val = color.toHslString();
2019
}
20+
$group.find('.spectrum-source').spectrum('set', val);
2121
});
2222
});
2323
})(window.jQuery);

0 commit comments

Comments
 (0)