Skip to content

Commit 3bed8a9

Browse files
committed
MAGETWO-91003: Border Color should be disabled when "Border" is selected None
Add enable/disable state in update binding and instantiate with same config regardless of initial state
1 parent 23df0f3 commit 3bed8a9

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/color-picker.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ define([
1111
], function (ko, $, renderer, spectrum, tinycolor) {
1212
'use strict';
1313

14+
/**
15+
* Change color picker status to be enabled or disabled
16+
*
17+
* @param {HTMLElement} element - Element to apply colorpicker enable/disable status to.
18+
* @param {Object} viewModel - Object, which represents view model binded to el.
19+
*/
20+
function changeColorPickerStateBasedOnViewModel(element, viewModel) {
21+
$(element).spectrum(viewModel.disabled() ? 'disable' : 'enable');
22+
}
23+
1424
ko.bindingHandlers.colorPicker = {
1525
/**
1626
* Binding init callback.
@@ -31,35 +41,34 @@ define([
3141
config.value(value.toString());
3242
};
3343

34-
if (!viewModel.disabled()) {
35-
config.change = changeValue;
44+
config.change = changeValue;
3645

37-
config.hide = changeValue;
46+
config.hide = changeValue;
3847

39-
/** show value */
40-
config.show = function () {
41-
if (!viewModel.focused()) {
42-
viewModel.focused(true);
43-
}
48+
/** show value */
49+
config.show = function () {
50+
if (!viewModel.focused()) {
51+
viewModel.focused(true);
52+
}
4453

45-
return true;
46-
};
47-
$(element).spectrum(config);
48-
} else {
49-
$(element).spectrum({
50-
disabled: true
51-
});
52-
}
54+
return true;
55+
};
56+
57+
$(element).spectrum(config);
58+
59+
changeColorPickerStateBasedOnViewModel(element, viewModel);
5360
},
5461

5562
/**
5663
* Reads params passed to binding, parses component declarations.
5764
* Fetches for those found and attaches them to the new context.
5865
*
59-
* @param {HTMLElement} element
60-
* @param {Function} valueAccessor
66+
* @param {HTMLElement} element - Element to apply bindings to.
67+
* @param {Function} valueAccessor - Function that returns value, passed to binding.
68+
* @param {Object} allBindings - Object, which represents all bindings applied to element.
69+
* @param {Object} viewModel - Object, which represents view model binded to element.
6170
*/
62-
update: function (element, valueAccessor) {
71+
update: function (element, valueAccessor, allBindings, viewModel) {
6372
var config = valueAccessor();
6473

6574
if (tinycolor(config.value()).isValid() || config.value() === '') {
@@ -69,6 +78,8 @@ define([
6978
config.value($(element).spectrum('get').toString());
7079
}
7180
}
81+
82+
changeColorPickerStateBasedOnViewModel(element, viewModel);
7283
}
7384
};
7485

0 commit comments

Comments
 (0)