1
1
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
+
4
4
5
- component . childrenContainer = component_content ;
6
- component . valueElement = component_value ;
5
+ component . color = ( function ( element ) {
6
+ var array ;
7
7
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' ) ) ;
9
25
10
26
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 ) ,
13
29
s = hsl [ 1 ] / 100 ,
14
30
l = hsl [ 2 ] / 100 ;
15
31
@@ -32,13 +48,17 @@ satus.components.colorPicker = function(component, skeleton) {
32
48
'backgroundColor' : 'hsl(' + hsl [ 0 ] + 'deg, 100%, 50%)'
33
49
} ,
34
50
on : {
35
- mousedown : function ( ) {
51
+ mousedown : function ( event ) {
52
+ if ( event . button !== 0 ) {
53
+ return false ;
54
+ }
55
+
36
56
var palette = this ,
37
57
rect = this . getBoundingClientRect ( ) ,
38
58
cursor = this . children [ 0 ] ;
39
59
40
60
function mousemove ( event ) {
41
- var hsl = palette . skeleton . parentSkeleton . storage . value ,
61
+ var hsl = palette . skeleton . parentSkeleton . value ,
42
62
x = event . clientX - rect . left ,
43
63
y = event . clientY - rect . top ,
44
64
s ;
@@ -87,7 +107,7 @@ satus.components.colorPicker = function(component, skeleton) {
87
107
component : 'div' ,
88
108
class : 'satus-color-picker__color' ,
89
109
style : {
90
- 'backgroundColor' : 'rgb(' + this . rgb . join ( ',' ) + ')'
110
+ 'backgroundColor' : 'rgb(' + this . color . value . join ( ',' ) + ')'
91
111
}
92
112
} ,
93
113
hue : {
@@ -97,14 +117,14 @@ satus.components.colorPicker = function(component, skeleton) {
97
117
value : hsl [ 0 ] ,
98
118
max : 360 ,
99
119
on : {
100
- change : function ( ) {
120
+ input : function ( ) {
101
121
var modal = this . skeleton . parentSkeleton . parentSkeleton ,
102
- hsl = modal . storage . value ;
122
+ hsl = modal . value ;
103
123
104
- hsl [ 0 ] = this . values [ 0 ] ;
124
+ hsl [ 0 ] = this . storage . value ;
105
125
106
126
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%)' ;
108
128
}
109
129
}
110
130
}
@@ -119,13 +139,13 @@ satus.components.colorPicker = function(component, skeleton) {
119
139
on : {
120
140
click : function ( ) {
121
141
var modal = this . skeleton . parentSkeleton . parentSkeleton ,
122
- component = modal . parentSkeleton ;
142
+ component = modal . parentElement ;
123
143
124
- component . rgb = component . skeleton . value ;
144
+ component . color . value = component . skeleton . value || [ 0 , 0 , 0 ] ;
125
145
126
- component . storage . value = component . rgb ;
146
+
127
147
128
- component . valueElement . style . backgroundColor = 'rgb(' + component . rgb . join ( ',' ) + ')' ;
148
+
129
149
130
150
modal . rendered . close ( ) ;
131
151
}
@@ -146,13 +166,13 @@ satus.components.colorPicker = function(component, skeleton) {
146
166
on : {
147
167
click : function ( ) {
148
168
var modal = this . skeleton . parentSkeleton . parentSkeleton ,
149
- component = modal . parentSkeleton ;
169
+ component = modal . parentElement ;
150
170
151
- component . rgb = satus . color . hslToRgb ( modal . storage . value ) ;
171
+ component . color . value = satus . color . hslToRgb ( modal . value ) ;
152
172
153
- component . storage . value = component . rgb ;
173
+
154
174
155
- component . valueElement . style . backgroundColor = 'rgb(' + component . rgb . join ( ',' ) + ')' ;
175
+
156
176
157
177
modal . rendered . close ( ) ;
158
178
}
@@ -162,9 +182,9 @@ satus.components.colorPicker = function(component, skeleton) {
162
182
} , this . baseProvider . layers [ 0 ] ) ;
163
183
} ) ;
164
184
165
- component . addEventListener ( 'render' , function ( ) {
166
- component . rgb = this . storage . value || [ 0 , 100 , 50 ] ;
185
+
186
+
167
187
168
- component_value . style . backgroundColor = 'rgb(' + component . rgb . join ( ',' ) + ')' ;
169
- } ) ;
170
- } ;
188
+
189
+
190
+ } ;
0 commit comments