Skip to content

Commit f416701

Browse files
committed
to compare
1 parent 14642fd commit f416701

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

new-color-picker.js

+47-27
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
satus.components.colorPicker = function(component, skeleton) {
2-
var component_content = component.createChildElement('div', 'content'),
3-
component_value = component.createChildElement('span', 'value');
2+
component.childrenContainer = component.createChildElement('div', 'content');
3+
44

5-
component.childrenContainer = component_content;
6-
component.valueElement = component_value;
5+
component.color = (function(element) {
6+
var array;
77

8-
component.className = 'satus-button';
8+
Object.defineProperty(element, 'value', {
9+
get: function() {
10+
return array;
11+
},
12+
set: function(value) {
13+
array = value;
14+
15+
this.parentNode.storage.value = array;
16+
17+
element.style.backgroundColor = 'rgb(' + value.join(',') + ')';
18+
}
19+
});
20+
21+
element.value = component.storage.value || component.skeleton.value || [0, 0, 0];
22+
23+
return element;
24+
})(component.createChildElement('span', 'value'));
925

1026
component.addEventListener('click', function() {
11-
var rgb = this.rgb,
12-
hsl = satus.color.rgbToHsl(rgb),
27+
28+
var hsl = satus.color.rgbToHsl(this.color.value),
1329
s = hsl[1] / 100,
1430
l = hsl[2] / 100;
1531

@@ -32,13 +48,17 @@ satus.components.colorPicker = function(component, skeleton) {
3248
'backgroundColor': 'hsl(' + hsl[0] + 'deg, 100%, 50%)'
3349
},
3450
on: {
35-
mousedown: function() {
51+
mousedown: function(event) {
52+
if (event.button !== 0) {
53+
return false;
54+
}
55+
3656
var palette = this,
3757
rect = this.getBoundingClientRect(),
3858
cursor = this.children[0];
3959

4060
function mousemove(event) {
41-
var hsl = palette.skeleton.parentSkeleton.storage.value,
61+
var hsl = palette.skeleton.parentSkeleton.value,
4262
x = event.clientX - rect.left,
4363
y = event.clientY - rect.top,
4464
s;
@@ -87,7 +107,7 @@ satus.components.colorPicker = function(component, skeleton) {
87107
component: 'div',
88108
class: 'satus-color-picker__color',
89109
style: {
90-
'backgroundColor': 'rgb(' + this.rgb.join(',') + ')'
110+
'backgroundColor': 'rgb(' + this.color.value.join(',') + ')'
91111
}
92112
},
93113
hue: {
@@ -97,14 +117,14 @@ satus.components.colorPicker = function(component, skeleton) {
97117
value: hsl[0],
98118
max: 360,
99119
on: {
100-
change: function() {
120+
input: function() {
101121
var modal = this.skeleton.parentSkeleton.parentSkeleton,
102-
hsl = modal.storage.value;
122+
hsl = modal.value;
103123

104-
hsl[0] = this.values[0];
124+
hsl[0] = this.storage.value;
105125

106126
this.previousSibling.style.backgroundColor = 'hsl(' + hsl[0] + 'deg,' + hsl[1] + '%, ' + hsl[2] + '%)';
107-
this.parentSkeletonNode.previousSibling.style.backgroundColor = 'hsl(' + hsl[0] + 'deg, 100%, 50%)';
127+
this.parentNode.previousSibling.style.backgroundColor = 'hsl(' + hsl[0] + 'deg, 100%, 50%)';
108128
}
109129
}
110130
}
@@ -119,13 +139,13 @@ satus.components.colorPicker = function(component, skeleton) {
119139
on: {
120140
click: function() {
121141
var modal = this.skeleton.parentSkeleton.parentSkeleton,
122-
component = modal.parentSkeleton;
142+
component = modal.parentElement;
123143

124-
component.rgb = component.skeleton.value;
144+
component.color.value = component.skeleton.value || [0, 0, 0];
125145

126-
component.storage.value = component.rgb;
146+
127147

128-
component.valueElement.style.backgroundColor = 'rgb(' + component.rgb.join(',') + ')';
148+
129149

130150
modal.rendered.close();
131151
}
@@ -146,13 +166,13 @@ satus.components.colorPicker = function(component, skeleton) {
146166
on: {
147167
click: function() {
148168
var modal = this.skeleton.parentSkeleton.parentSkeleton,
149-
component = modal.parentSkeleton;
169+
component = modal.parentElement;
150170

151-
component.rgb = satus.color.hslToRgb(modal.storage.value);
171+
component.color.value = satus.color.hslToRgb(modal.value);
152172

153-
component.storage.value = component.rgb;
173+
154174

155-
component.valueElement.style.backgroundColor = 'rgb(' + component.rgb.join(',') + ')';
175+
156176

157177
modal.rendered.close();
158178
}
@@ -162,9 +182,9 @@ satus.components.colorPicker = function(component, skeleton) {
162182
}, this.baseProvider.layers[0]);
163183
});
164184

165-
component.addEventListener('render', function() {
166-
component.rgb = this.storage.value || [0, 100, 50];
185+
186+
167187

168-
component_value.style.backgroundColor = 'rgb(' + component.rgb.join(',') + ')';
169-
});
170-
};
188+
189+
190+
};

0 commit comments

Comments
 (0)