@componyx/ui 0.0.0-stage → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AppSkin/AppSkin.css +1268 -0
- package/AppSkin/AppSkin.js +2748 -0
- package/AppSkin/Themes/Default.css +241 -0
- package/Base/Base.js +3407 -0
- package/Base/ComponentIcons.css +66 -0
- package/Base/Font/ComponentIcons.woff +0 -0
- package/Base/Font/UI.woff +0 -0
- package/Base/Library.js +8432 -0
- package/Base/NavigationManager.js +462 -0
- package/Base/ResponsiveTemplates.js +371 -0
- package/Base/Sanitizer.js +288 -0
- package/Base/Themes/Default.css +255 -0
- package/Base/UI.css +618 -0
- package/Base/UIResourcePath.js +6 -0
- package/Bindary/Bindary.js +2011 -0
- package/Bindary/Modules/Connection.js +216 -0
- package/Bindary/Modules/Core.js +854 -0
- package/Bindary/Modules/DataUpdater.js +351 -0
- package/Bindary/Modules/ExpressionEngine.js +347 -0
- package/Bindary/Modules/ProxyManager.js +482 -0
- package/Bindary/Modules/Renderer.js +605 -0
- package/Bindary/Modules/Router.js +291 -0
- package/Bindary/Modules/Scroller.js +89 -0
- package/Bindary/Modules/Template.js +1273 -0
- package/BookmarkSpy/BookmarkSpy.js +430 -0
- package/Box/Box.css +36 -0
- package/Box/Box.js +1685 -0
- package/Button/Button.css +470 -0
- package/Button/Button.js +1398 -0
- package/Button/Themes/Default.css +200 -0
- package/Carousel/Carousel.css +273 -0
- package/Carousel/Carousel.js +607 -0
- package/ColorButton/ColorButton.css +39 -0
- package/ColorButton/ColorButton.js +336 -0
- package/ColorPicker/ColorPicker.css +359 -0
- package/ColorPicker/ColorPicker.js +972 -0
- package/ComboBox/ComboBox.css +357 -0
- package/ComboBox/ComboBox.js +2342 -0
- package/ComboBox/Themes/Default.css +23 -0
- package/DataPager/DataPager.css +72 -0
- package/DataPager/DataPager.js +674 -0
- package/DatePicker/DatePicker.css +227 -0
- package/DatePicker/DatePicker.js +1531 -0
- package/DatePicker/Themes/Default.css +26 -0
- package/Dialog/Dialog.css +106 -0
- package/Dialog/Dialog.js +572 -0
- package/Dialog/Themes/Default.css +10 -0
- package/Editor/Data/Emoji.json +8285 -0
- package/Editor/Data/Special.json +1042 -0
- package/Editor/Editor.css +1562 -0
- package/Editor/Editor.js +4058 -0
- package/Editor/Font/Editor.woff +0 -0
- package/Editor/Modules/ComponentFactory.js +565 -0
- package/Editor/Modules/ContentManager.js +748 -0
- package/Editor/Modules/DialogManager.js +1234 -0
- package/Editor/Modules/EventManager.js +458 -0
- package/Editor/Modules/Format.js +950 -0
- package/Editor/Modules/History.js +191 -0
- package/Editor/Modules/LayoutState.js +379 -0
- package/Editor/Modules/ListManager.js +296 -0
- package/Editor/Modules/MenuManager.js +388 -0
- package/Editor/Modules/NodeManager.js +681 -0
- package/Editor/Modules/ParagraphButtons.js +122 -0
- package/Editor/Modules/Resizer.js +176 -0
- package/Editor/Modules/SelectionRange.js +564 -0
- package/Editor/Modules/SourceViewBuilder.js +212 -0
- package/Editor/Modules/SymbolPicker.js +208 -0
- package/Editor/Modules/Table.js +2327 -0
- package/Editor/Modules/TableDialog.js +757 -0
- package/Editor/Modules/Toolbar.js +375 -0
- package/Editor/Modules/TooltipMenu.js +125 -0
- package/Editor/Modules/Utility.js +131 -0
- package/Editor/Themes/Default.css +204 -0
- package/FileUpload/FileUpload.css +156 -0
- package/FileUpload/FileUpload.js +898 -0
- package/FileUpload/Themes/Default.css +17 -0
- package/Form/Form.css +1934 -0
- package/Form/Form.js +4943 -0
- package/Form/Modules/ActionManager.js +368 -0
- package/Form/Modules/BuildPanelManager.js +319 -0
- package/Form/Modules/ComponentFactory.js +468 -0
- package/Form/Modules/ComponentPanel.js +265 -0
- package/Form/Modules/ConfigPanelManager.js +685 -0
- package/Form/Modules/DataBinder.js +602 -0
- package/Form/Modules/DataObserver.js +717 -0
- package/Form/Modules/Draggable.js +756 -0
- package/Form/Modules/OptionsPanel.js +342 -0
- package/Form/Modules/Renderer.js +1889 -0
- package/Form/Modules/RuleEngine.js +585 -0
- package/Form/Modules/RulesPanel.js +1158 -0
- package/Form/Modules/Types.js +1709 -0
- package/Form/Modules/ValidationManager.js +194 -0
- package/Form/Themes/Default.css +216 -0
- package/FormField/FormField.css +468 -0
- package/FormField/FormField.js +576 -0
- package/FormField/Themes/Default.css +99 -0
- package/Grid/Grid.css +544 -0
- package/Grid/Grid.js +3761 -0
- package/Grid/Themes/Default.css +43 -0
- package/LICENSE +126 -0
- package/MaskedTextBox/MaskedTextBox.css +28 -0
- package/MaskedTextBox/MaskedTextBox.js +642 -0
- package/MaskedTextBox/Themes/Default.css +6 -0
- package/Menu/Menu.css +328 -0
- package/Menu/Menu.js +2386 -0
- package/Menu/Themes/Default.css +24 -0
- package/NumericBox/NumericBox.css +120 -0
- package/NumericBox/NumericBox.js +984 -0
- package/PanelBar/PanelBar.css +123 -0
- package/PanelBar/PanelBar.js +505 -0
- package/PanelBar/Themes/Default.css +51 -0
- package/PieChart/PieChart.css +95 -0
- package/PieChart/PieChart.js +820 -0
- package/PieChart/Themes/Default.css +9 -0
- package/README.md +178 -3
- package/Slider/Slider.css +348 -0
- package/Slider/Slider.js +1306 -0
- package/Slider/Themes/Default.css +44 -0
- package/TabStrip/TabStrip.css +52 -0
- package/TabStrip/TabStrip.js +362 -0
- package/TabStrip/Themes/Default.css +35 -0
- package/TimePicker/Themes/Default.css +30 -0
- package/TimePicker/TimePicker.css +253 -0
- package/TimePicker/TimePicker.js +1485 -0
- package/TooltipManager/Themes/Default.css +21 -0
- package/TooltipManager/TooltipManager.css +227 -0
- package/TooltipManager/TooltipManager.js +791 -0
- package/Validator/Validator.css +54 -0
- package/Validator/Validator.js +2508 -0
- package/componyx.html-data.json +619 -0
- package/index.js +27 -0
- package/package.json +43 -4
- package/types/AppSkin.d.ts +842 -0
- package/types/Base.d.ts +1034 -0
- package/types/Bindary.d.ts +1196 -0
- package/types/BookmarkSpy.d.ts +112 -0
- package/types/Box.d.ts +374 -0
- package/types/Button.d.ts +455 -0
- package/types/Carousel.d.ts +136 -0
- package/types/ColorButton.d.ts +120 -0
- package/types/ColorPicker.d.ts +225 -0
- package/types/ComboBox.d.ts +507 -0
- package/types/DataPager.d.ts +152 -0
- package/types/DatePicker.d.ts +354 -0
- package/types/Dialog.d.ts +160 -0
- package/types/Editor.d.ts +1289 -0
- package/types/FileUpload.d.ts +206 -0
- package/types/Form.d.ts +3078 -0
- package/types/FormField.d.ts +204 -0
- package/types/Grid.d.ts +911 -0
- package/types/Library.d.ts +1899 -0
- package/types/MaskedTextBox.d.ts +91 -0
- package/types/Menu.d.ts +577 -0
- package/types/NumericBox.d.ts +310 -0
- package/types/PanelBar.d.ts +223 -0
- package/types/PieChart.d.ts +224 -0
- package/types/ResponsiveTemplates.d.ts +108 -0
- package/types/Slider.d.ts +227 -0
- package/types/TabStrip.d.ts +185 -0
- package/types/TimePicker.d.ts +265 -0
- package/types/TooltipManager.d.ts +178 -0
- package/types/UI.d.ts +29 -0
- package/types/Validator.d.ts +653 -0
- package/types/index.d.ts +59 -0
- package/ui.css +11783 -0
- package/ui.js +79477 -0
- package/ui.min.css +138 -0
- package/ui.min.js +264 -0
- package/ui.min.js.map +1 -0
|
@@ -0,0 +1,972 @@
|
|
|
1
|
+
/*! Componyx.UI | (c) E.H. Daanen / Componyx | BUSL-1.1 | componyx.com/license */
|
|
2
|
+
import '../Base/Base.js';
|
|
3
|
+
import '../Base/Library.js';
|
|
4
|
+
import '../Button/Button.js';
|
|
5
|
+
import '../Box/Box.js';
|
|
6
|
+
import '../NumericBox/NumericBox.js';
|
|
7
|
+
|
|
8
|
+
(function (window)
|
|
9
|
+
{
|
|
10
|
+
/**
|
|
11
|
+
* ColorPicker class.
|
|
12
|
+
* @class
|
|
13
|
+
* @memberof componyx.UI
|
|
14
|
+
* @augments componyx.UI.base.Component
|
|
15
|
+
* @mixes componyx.UI.base.methods
|
|
16
|
+
*/
|
|
17
|
+
componyx.UI.ColorPicker = function ColorPicker(id, properties)
|
|
18
|
+
{
|
|
19
|
+
// define private properties
|
|
20
|
+
var _instance = this,
|
|
21
|
+
_draggableSatPicker, _draggableHuePicker, _hex, _popupContent, _box,
|
|
22
|
+
_rgba, _confirmCallback;
|
|
23
|
+
$base.static.ThemeOption;
|
|
24
|
+
var _classOption =
|
|
25
|
+
{
|
|
26
|
+
SATURATION: 'saturation',
|
|
27
|
+
HUE: 'hue',
|
|
28
|
+
PREVIEW: 'preview',
|
|
29
|
+
INPUTCONTAINER: 'input-container',
|
|
30
|
+
PICKER: 'picker',
|
|
31
|
+
RGB: 'rgb',
|
|
32
|
+
HSB: 'hsb',
|
|
33
|
+
ALPHA: 'alpha',
|
|
34
|
+
HEX: 'hex',
|
|
35
|
+
BUTTON: 'button'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// define public properties
|
|
39
|
+
/**
|
|
40
|
+
* Gets or sets the css class of the preview color box.
|
|
41
|
+
* @type {String}
|
|
42
|
+
*/
|
|
43
|
+
this.cssClassPreview = '';
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Gets or sets the css class of the saturation palette.
|
|
47
|
+
* @type {String}
|
|
48
|
+
*/
|
|
49
|
+
this.cssClassSaturation = '';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Gets or sets the css class of the hue palette.
|
|
53
|
+
* @type {String}
|
|
54
|
+
*/
|
|
55
|
+
this.cssClassHue = '';
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gets or sets the css class of the input container.
|
|
59
|
+
* @type {String}
|
|
60
|
+
*/
|
|
61
|
+
this.cssClassInputContainer = '';
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Gets or sets the css class of the saturation and hue picker.
|
|
65
|
+
* @type {String}
|
|
66
|
+
*/
|
|
67
|
+
this.cssClassPicker = '';
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets or sets the css class of the hue-saturation-brightness(value) input container.
|
|
71
|
+
* @type {String}
|
|
72
|
+
*/
|
|
73
|
+
this.cssClassHSB = '';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Gets or sets the css class of the red-green-blue input container.
|
|
77
|
+
* @type {String}
|
|
78
|
+
*/
|
|
79
|
+
this.cssClassRGB = '';
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets or sets the css class of the alpha input container.
|
|
83
|
+
* @type {String}
|
|
84
|
+
*/
|
|
85
|
+
this.cssClassAlpha = '';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Gets or sets the css class of the hex input container.
|
|
89
|
+
* @type {String}
|
|
90
|
+
*/
|
|
91
|
+
this.cssClassHex = '';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Gets or sets the css class appended to the confirm button.
|
|
95
|
+
* @type {String}
|
|
96
|
+
*/
|
|
97
|
+
this.cssClassConfirmButton = '';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Gets or sets the css class appended to the cancel button.
|
|
101
|
+
* @type {String}
|
|
102
|
+
*/
|
|
103
|
+
this.cssClassCancelButton = '';
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Gets or sets the css class appended to the clear button.
|
|
107
|
+
* @type {String}
|
|
108
|
+
*/
|
|
109
|
+
this.cssClassClearButton = '';
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Gets or sets the text label of the confirm button.
|
|
113
|
+
* @type {String}
|
|
114
|
+
*/
|
|
115
|
+
this.confirmButtonLabel = 'OK';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Gets or sets the text label of the cancel button.
|
|
119
|
+
* @type {String}
|
|
120
|
+
*/
|
|
121
|
+
this.cancelButtonLabel = 'Cancel';
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Gets or sets the text label of the clear button.
|
|
125
|
+
* @type {String}
|
|
126
|
+
*/
|
|
127
|
+
this.clearButtonLabel = 'No Color';
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Gets or sets the color in the format Hue, Saturation, Brightness, Alpha.
|
|
131
|
+
* @type {String|null}
|
|
132
|
+
*/
|
|
133
|
+
this.hsba = null;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Gets or sets the color in the format Red, Green, Blue, Alpha.
|
|
137
|
+
* @type {String|null}
|
|
138
|
+
*/
|
|
139
|
+
this.rgba = null;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Gets or sets the color in the hexadecimal format.
|
|
143
|
+
* @type {String}
|
|
144
|
+
*/
|
|
145
|
+
this.hex = '';
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Gets or sets a value indicating if the color picker is displayed within a popup with a color box as popup trigger.
|
|
149
|
+
* @type {Boolean}
|
|
150
|
+
*/
|
|
151
|
+
this.popupView = false;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Gets or sets the clientid of the numeric box.
|
|
155
|
+
* @type {String|null}
|
|
156
|
+
*/
|
|
157
|
+
this.numericBoxId = null;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gets or sets the clientid of the popup box.
|
|
161
|
+
* @type {String|null}
|
|
162
|
+
*/
|
|
163
|
+
this.boxId = null;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets or sets the id of the component from which the settings are cloned for the confirm button.
|
|
167
|
+
* @type {String|null}
|
|
168
|
+
*/
|
|
169
|
+
this.confirmButtonId = null;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets or sets the id of the component from which the settings are cloned for the cancel button.
|
|
173
|
+
* @type {String|null}
|
|
174
|
+
*/
|
|
175
|
+
this.cancelButtonId = null;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Gets or sets the id of the component from which the settings are cloned for the clear button.
|
|
179
|
+
* @type {String|null}
|
|
180
|
+
*/
|
|
181
|
+
this.clearButtonId = null;
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @class
|
|
186
|
+
* @augments componyx.UI.base.Events
|
|
187
|
+
* @memberof componyx.UI.ColorPicker
|
|
188
|
+
* @property {componyx.UI.base.Event} onChange - Event which fires on a color change. @see {@link componyx.UI.ColorPicker.ColorPickerEventArgs}
|
|
189
|
+
* @property {componyx.UI.base.Event} onConfirm - Event which fires on a color change confirmation. @see {@link componyx.UI.ColorPicker.ColorPickerEventArgs}
|
|
190
|
+
* @see {@link componyx.UI.base.Events}
|
|
191
|
+
*/
|
|
192
|
+
function ColorPickerEvents(events)
|
|
193
|
+
{
|
|
194
|
+
Object.assign(this, events);
|
|
195
|
+
|
|
196
|
+
this.onChange = $base.static.createEvent('onChange');
|
|
197
|
+
this.onConfirm = $base.static.createEvent('onConfirm');
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* ColorPicker events
|
|
201
|
+
* @type {componyx.UI.ColorPicker.ColorPickerEvents}
|
|
202
|
+
*/
|
|
203
|
+
this.events = new ColorPickerEvents(this.events);
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* @typedef {Object} componyx.UI.ColorPicker.ColorPickerEventArgs
|
|
207
|
+
* @property {componyx.UI.ColorPicker} ColorPicker - The ColorPicker instance.
|
|
208
|
+
* @property {Object} eventArgs - The event object containing more detailed information about the event.
|
|
209
|
+
* @property {number[]} eventArgs.rgba - The RGBA color value as [r, g, b, a].
|
|
210
|
+
*/
|
|
211
|
+
|
|
212
|
+
// inherit base instance members
|
|
213
|
+
$base.Component.apply(this, [id, properties]);
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Gets the corresponding box component.
|
|
217
|
+
* @returns {componyx.UI.Box} The box component.
|
|
218
|
+
*/
|
|
219
|
+
this.getBox = function ()
|
|
220
|
+
{
|
|
221
|
+
return _box;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Expands the colorpicker popup box.
|
|
226
|
+
* @param {HTMLElement|String} [expander] The expander element or id of the expander element.
|
|
227
|
+
* @param {String[]} [rgba] RGBA color value.
|
|
228
|
+
* @param {Function} [confirmCallback] The callback function to call when the color is confirmed through the confirm button.
|
|
229
|
+
* @param {componyx.UI.Box.AutoPositionOption} [boxPosition] The popup box autoPosition.
|
|
230
|
+
* @param {Boolean} [modal] A value indicating if the colorpicker popup is shown as modal.
|
|
231
|
+
* @param {Boolean} [toggle] A value indicating if the colorpicker popup hides when already showing.
|
|
232
|
+
*/
|
|
233
|
+
this.expand = function (expander, rgba, confirmCallback, boxPosition, modal, toggle)
|
|
234
|
+
{
|
|
235
|
+
_confirmCallback = confirmCallback;
|
|
236
|
+
|
|
237
|
+
if (expander)
|
|
238
|
+
{
|
|
239
|
+
_box.expander = expander;
|
|
240
|
+
_box.autoPosition = componyx.UI.Box.AutoPositionOption.EXPAND;
|
|
241
|
+
}
|
|
242
|
+
else
|
|
243
|
+
{
|
|
244
|
+
_box.expander = null;
|
|
245
|
+
_box.autoPosition = componyx.UI.Box.AutoPositionOption.CENTER;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (boxPosition)
|
|
249
|
+
_box.position = boxPosition;
|
|
250
|
+
|
|
251
|
+
if (rgba)
|
|
252
|
+
{
|
|
253
|
+
_rgba = rgba;
|
|
254
|
+
this.setRGBA.apply(_instance, rgba);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
_box.modal = modal || false;
|
|
258
|
+
|
|
259
|
+
if (toggle)
|
|
260
|
+
togglePopup();
|
|
261
|
+
else
|
|
262
|
+
_box.show();
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Returns the current selected HSBA color value.
|
|
267
|
+
*/
|
|
268
|
+
this.getHSBA = function ()
|
|
269
|
+
{
|
|
270
|
+
return getHSBA();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Sets the selected color to the specified HSBA color value.
|
|
275
|
+
* @param {Number} h Hue value (0-1).
|
|
276
|
+
* @param {Number} s Saturation value (0-1).
|
|
277
|
+
* @param {Number} b Brightness value (0-1).
|
|
278
|
+
* @param {Number} a Alpha value (0-1).
|
|
279
|
+
*/
|
|
280
|
+
this.setHSBA = function (h, s, b, a)
|
|
281
|
+
{
|
|
282
|
+
setHSBA(h, s, b, ($lib.isEmpty(a)) ? 1 : a);
|
|
283
|
+
hsbChanged();
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Returns the current selected RGBA color value.
|
|
288
|
+
*/
|
|
289
|
+
this.getRGBA = function ()
|
|
290
|
+
{
|
|
291
|
+
return getRGBA();
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Sets the selected color to the specified RGBA color value.
|
|
296
|
+
* @param {Number} r Red value (0-255).
|
|
297
|
+
* @param {Number} g Green value (0-255).
|
|
298
|
+
* @param {Number} b Blue value (0-255).
|
|
299
|
+
* @param {Number} a Alpha value (0-1).
|
|
300
|
+
*/
|
|
301
|
+
this.setRGBA = function (r, g, b, a)
|
|
302
|
+
{
|
|
303
|
+
setRGBA(r, g, b, ($lib.isEmpty(a)) ? 1 : a);
|
|
304
|
+
rgbChanged();
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Returns the current selected hex color value.
|
|
309
|
+
*/
|
|
310
|
+
this.getHex = function ()
|
|
311
|
+
{
|
|
312
|
+
return getHex();
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Sets the selected color to the specified hex color value.
|
|
317
|
+
* @param {String} value Hex color value.
|
|
318
|
+
*/
|
|
319
|
+
this.setHex = function (value)
|
|
320
|
+
{
|
|
321
|
+
setHex(value);
|
|
322
|
+
hexChanged();
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Renders the component
|
|
327
|
+
*/
|
|
328
|
+
this.render = function ()
|
|
329
|
+
{
|
|
330
|
+
if (_instance.renderState != $base.static.RenderState.RENDERING)
|
|
331
|
+
{
|
|
332
|
+
// call base render and return
|
|
333
|
+
$base.methods.render.call(_instance, preRender, 'color-picker', false);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// render logic after loading resources
|
|
338
|
+
|
|
339
|
+
draw();
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Handles the post render procedure.
|
|
344
|
+
*/
|
|
345
|
+
this.postRender = function ()
|
|
346
|
+
{
|
|
347
|
+
if (_instance.renderState != $base.static.RenderState.RENDERING) // extra safety to never execute a postRender when the component state is incorrect
|
|
348
|
+
return;
|
|
349
|
+
|
|
350
|
+
postRender();
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Destroys the component.
|
|
355
|
+
* @see {@link componyx.UI.base.methods#destroy}
|
|
356
|
+
*/
|
|
357
|
+
this.destroy = function (...args)
|
|
358
|
+
{
|
|
359
|
+
dispose();
|
|
360
|
+
$base.methods.destroy.call(this, ...args);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
function preRender()
|
|
364
|
+
{
|
|
365
|
+
// initialize script and css
|
|
366
|
+
var script = ['NumericBox'];
|
|
367
|
+
|
|
368
|
+
if (_instance.popupView)
|
|
369
|
+
{
|
|
370
|
+
script.push('Button');
|
|
371
|
+
script.push('Box');
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return ['ColorPicker', script];
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function postRender()
|
|
378
|
+
{
|
|
379
|
+
var hsba;
|
|
380
|
+
|
|
381
|
+
if (_box)
|
|
382
|
+
_box.update(_popupContent);
|
|
383
|
+
|
|
384
|
+
if (_instance.rgba)
|
|
385
|
+
{
|
|
386
|
+
_rgba = _instance.rgba.split(',');
|
|
387
|
+
|
|
388
|
+
$lib.each(_rgba, function (item, index)
|
|
389
|
+
{
|
|
390
|
+
_rgba[index] = (index == 3) ? parseFloat(item) : parseInt(item, 10);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
setRGBA.apply(_instance, _rgba);
|
|
394
|
+
rgbChanged();
|
|
395
|
+
}
|
|
396
|
+
else if (_instance.hsba)
|
|
397
|
+
{
|
|
398
|
+
hsba = _instance.hsba.split(',');
|
|
399
|
+
$lib.each(hsba, function (item, index)
|
|
400
|
+
{
|
|
401
|
+
hsba[index] = parseFloat(item);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
setHSBA.apply(_instance, _instance.hsba.split(/\D/));
|
|
405
|
+
hsbChanged();
|
|
406
|
+
}
|
|
407
|
+
else
|
|
408
|
+
{
|
|
409
|
+
setHex(_instance.hex || 'ff0000');
|
|
410
|
+
hexChanged();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
_rgba = getRGBA();
|
|
414
|
+
$base.methods.postRender.call(_instance);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function draw()
|
|
418
|
+
{
|
|
419
|
+
var el = _instance.element;
|
|
420
|
+
|
|
421
|
+
if (_instance.popupView)
|
|
422
|
+
createPopup();
|
|
423
|
+
else
|
|
424
|
+
createContent(el);
|
|
425
|
+
|
|
426
|
+
_instance.renderChildren();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function createContent(container)
|
|
430
|
+
{
|
|
431
|
+
var divSB = document.createElement('div'),
|
|
432
|
+
divHue = document.createElement('div'),
|
|
433
|
+
divInputContainer = document.createElement('div'),
|
|
434
|
+
divHSB = document.createElement('div'),
|
|
435
|
+
divRGB = document.createElement('div'),
|
|
436
|
+
divAlpha = document.createElement('div'),
|
|
437
|
+
divHex = document.createElement('div');
|
|
438
|
+
|
|
439
|
+
divSB.className = _instance.cssClassSaturation || _classOption.SATURATION;
|
|
440
|
+
divHue.className = _instance.cssClassHue || _classOption.HUE;
|
|
441
|
+
divInputContainer.className = _instance.cssClassInputContainer || _classOption.INPUTCONTAINER;
|
|
442
|
+
divHSB.className = _instance.cssClassHSB || _classOption.HSB;
|
|
443
|
+
divRGB.className = _instance.cssClassRGB || _classOption.RGB;
|
|
444
|
+
divAlpha.className = _instance.cssClassAlpha || _classOption.ALPHA;
|
|
445
|
+
divHex.className = _instance.cssClassHex || _classOption.HEX;
|
|
446
|
+
|
|
447
|
+
container.appendChild(divSB);
|
|
448
|
+
container.appendChild(divHue);
|
|
449
|
+
container.appendChild(divInputContainer);
|
|
450
|
+
|
|
451
|
+
createColorBox(divInputContainer, _instance.cssClassPreview || _classOption.PREVIEW);
|
|
452
|
+
divInputContainer.appendChild(divHSB);
|
|
453
|
+
divInputContainer.appendChild(divRGB);
|
|
454
|
+
divInputContainer.appendChild(divAlpha);
|
|
455
|
+
divInputContainer.appendChild(divHex);
|
|
456
|
+
|
|
457
|
+
createSaturationPicker(divSB);
|
|
458
|
+
createHuePicker(divHue);
|
|
459
|
+
createNumericBox(divHSB, 'h', 360, hsbChanged);
|
|
460
|
+
createNumericBox(divHSB, 's', 100, hsbChanged);
|
|
461
|
+
createNumericBox(divHSB, 'v', 100, hsbChanged);
|
|
462
|
+
createNumericBox(divRGB, 'r', 255, rgbChanged);
|
|
463
|
+
createNumericBox(divRGB, 'g', 255, rgbChanged);
|
|
464
|
+
createNumericBox(divRGB, 'b', 255, rgbChanged);
|
|
465
|
+
createNumericBox(divAlpha, 'a', 100, alphaChanged);
|
|
466
|
+
createTextBox(divHex);
|
|
467
|
+
$lib.on(divSB, 'mousedown', saturationSelect);
|
|
468
|
+
$lib.on(divHue, 'mousedown', hueSelect);
|
|
469
|
+
|
|
470
|
+
return container;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function createButton(container, id, cloneId, config)
|
|
474
|
+
{
|
|
475
|
+
var id = _instance.id + id,
|
|
476
|
+
button = $UI.createComponent(componyx.UI.Button, { id: id, containerElement: container });
|
|
477
|
+
|
|
478
|
+
button.transparentBorder = button.primary = false;
|
|
479
|
+
button.clone($UI.store[cloneId], _instance);
|
|
480
|
+
button.cssClass = button.cssClass || (_classOption.BUTTON + (config.cssClass ? " " + config.cssClass : ""));
|
|
481
|
+
button.text = config.text;
|
|
482
|
+
button.command = config.command;
|
|
483
|
+
button.primary = config.primary || false;
|
|
484
|
+
button.transparent = config.transparent || false;
|
|
485
|
+
button.events.onPostRender.priorityAdd(function () { _instance.isReady.apply(_instance); }, null);
|
|
486
|
+
button.showing = true;
|
|
487
|
+
|
|
488
|
+
return button;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function createColorBox(container, css)
|
|
492
|
+
{
|
|
493
|
+
var div = document.createElement('div');
|
|
494
|
+
div.appendChild(document.createElement('div'));
|
|
495
|
+
div.className = css;
|
|
496
|
+
container.appendChild(div);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function createPopup()
|
|
500
|
+
{
|
|
501
|
+
var id = _instance.id + '_Box', buttonContainer;
|
|
502
|
+
|
|
503
|
+
_box = $UI.createComponent(componyx.UI.Box, { id: id, containerElement: _instance.element });
|
|
504
|
+
|
|
505
|
+
_box.clone($UI.store[_instance.boxId], _instance);
|
|
506
|
+
_box.cssClass = _box.cssClass || _instance.cssClassPopupBox || _classOption.BOX;
|
|
507
|
+
_box.showing = false;
|
|
508
|
+
_box.hideOnOutsideClick = _box.autoResizeFit = _box.autoInvertFit = true;
|
|
509
|
+
_box.autoPosition = componyx.UI.Box.AutoPositionOption.EXPAND;
|
|
510
|
+
_box.events.onPostRender.priorityAdd(function () { _instance.isReady.apply(_instance); }, null);
|
|
511
|
+
|
|
512
|
+
_popupContent = _instance.element.appendChild(document.createElement('div'));
|
|
513
|
+
createContent(_popupContent);
|
|
514
|
+
|
|
515
|
+
buttonContainer = _popupContent.appendChild(document.createElement('div'));
|
|
516
|
+
createButton(buttonContainer, 'confirm', _instance.confirmButtonId,
|
|
517
|
+
{
|
|
518
|
+
cssClass: _instance.cssClassConfirmButton,
|
|
519
|
+
text: _instance.confirmButtonLabel,
|
|
520
|
+
command: confirm,
|
|
521
|
+
primary: true
|
|
522
|
+
});
|
|
523
|
+
createButton(buttonContainer, 'cancel', _instance.cancelButtonId,
|
|
524
|
+
{
|
|
525
|
+
cssClass: _instance.cssClassCancelButton,
|
|
526
|
+
text: _instance.cancelButtonLabel,
|
|
527
|
+
command: cancel
|
|
528
|
+
});
|
|
529
|
+
createButton(buttonContainer, 'clear', _instance.clearButtonId,
|
|
530
|
+
{
|
|
531
|
+
cssClass: _instance.cssClassClearButton,
|
|
532
|
+
text: _instance.clearButtonLabel,
|
|
533
|
+
command: clear,
|
|
534
|
+
transparent: true
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function createSaturationPicker(container)
|
|
539
|
+
{
|
|
540
|
+
var divPicker = createPicker(container), overshootX = $lib.styleValue(divPicker, 'left', true),
|
|
541
|
+
overshootY = $lib.styleValue(divPicker, 'top', true);
|
|
542
|
+
|
|
543
|
+
overshootX = (!$lib.isEmpty(overshootX)) ? Math.abs(parseInt(overshootX, 10)) : 0;
|
|
544
|
+
overshootY = (!$lib.isEmpty(overshootY)) ? Math.abs(parseInt(overshootY, 10)) : 0;
|
|
545
|
+
|
|
546
|
+
divPicker.style.top = $lib.unit(overshootY * -1);
|
|
547
|
+
divPicker.style.left = $lib.unit(255 - overshootX);
|
|
548
|
+
|
|
549
|
+
_draggableSatPicker = $lib.draggable(divPicker,
|
|
550
|
+
{
|
|
551
|
+
boundaryZone: container,
|
|
552
|
+
boundaryOvershootLeft: overshootX,
|
|
553
|
+
boundaryOvershootRight: overshootX,
|
|
554
|
+
boundaryOvershootTop: overshootY,
|
|
555
|
+
boundaryOvershootBottom: overshootY,
|
|
556
|
+
onDrag: function (args)
|
|
557
|
+
{
|
|
558
|
+
$lib.defer(drag.bind(this, args));
|
|
559
|
+
}.bind(this)
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
return divPicker;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
function createHuePicker(container)
|
|
566
|
+
{
|
|
567
|
+
var divPicker = createPicker(container), overshootY = $lib.styleValue(divPicker, 'top', true);
|
|
568
|
+
|
|
569
|
+
overshootY = (!$lib.isEmpty(overshootY)) ? Math.abs(parseInt(overshootY, 10)) : 0;
|
|
570
|
+
divPicker.style.top = $lib.unit(overshootY * -1);
|
|
571
|
+
|
|
572
|
+
_draggableHuePicker = $lib.draggable(divPicker,
|
|
573
|
+
{
|
|
574
|
+
boundaryZone: container,
|
|
575
|
+
boundaryOvershootTop: overshootY,
|
|
576
|
+
boundaryOvershootBottom: overshootY,
|
|
577
|
+
dragX: false,
|
|
578
|
+
onDrag: function (args)
|
|
579
|
+
{
|
|
580
|
+
$lib.defer(drag.bind(this, args));
|
|
581
|
+
}.bind(this)
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
return divPicker;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function drag(args)
|
|
588
|
+
{
|
|
589
|
+
let el = args.element,
|
|
590
|
+
elPos = $lib.getPos(el),
|
|
591
|
+
transform = el.style.transform,
|
|
592
|
+
left = el.style.left,
|
|
593
|
+
top = el.style.top;
|
|
594
|
+
|
|
595
|
+
el.style.transform = "";
|
|
596
|
+
el.style.left = el.style.top = '';
|
|
597
|
+
$.setPos(el, { left: elPos.left, top: elPos.top }); // force element at position
|
|
598
|
+
sliderChanged();
|
|
599
|
+
el.style.transform = transform;
|
|
600
|
+
el.style.left = left;
|
|
601
|
+
el.style.top = top;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
function createPicker(container)
|
|
606
|
+
{
|
|
607
|
+
var divPicker = container.appendChild(document.createElement('div'));
|
|
608
|
+
divPicker.className = _instance.cssClassPicker || _classOption.PICKER;
|
|
609
|
+
return divPicker;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function createNumericBox(container, id, maxValue, onChange)
|
|
613
|
+
{
|
|
614
|
+
id = _instance.id + '_' + id;
|
|
615
|
+
var input = $UI.createComponent(componyx.UI.NumericBox, { id: id, containerElement: container });
|
|
616
|
+
|
|
617
|
+
input.clone($UI.store[_instance.numericBoxId], _instance);
|
|
618
|
+
input.events.onPostRender.priorityAdd(function () { _instance.isReady.apply(_instance); }, null);
|
|
619
|
+
input.maxLength = 3;
|
|
620
|
+
input.minValue = 0;
|
|
621
|
+
input.maxValue = maxValue;
|
|
622
|
+
input.showing = true;
|
|
623
|
+
input.events.onChange.priorityAdd(onChange, null);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function createTextBox(container)
|
|
627
|
+
{
|
|
628
|
+
var div = container.appendChild(document.createElement('div'));
|
|
629
|
+
|
|
630
|
+
_hex = div.appendChild(document.createElement('input'));
|
|
631
|
+
_hex.id = _instance.id + '_hex';
|
|
632
|
+
_hex.type = 'text';
|
|
633
|
+
_hex.maxLength = 6;
|
|
634
|
+
|
|
635
|
+
$lib.on(_hex, 'keydown', function (e)
|
|
636
|
+
{
|
|
637
|
+
var key = e.key;
|
|
638
|
+
|
|
639
|
+
return (e.ctrlKey || (' End Home ArrowLeft ArrowUp ArrowRight ArrowDown Delete Backspace Tab 0 1 2 3 4 5 6 7 8 9 A B C D E F '.indexOf(' ' + key.toString() + ' ') > -1));
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
$lib.on(_hex, 'keyup', hexChanged);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function togglePopup()
|
|
646
|
+
{
|
|
647
|
+
if (!_box.showing)
|
|
648
|
+
_box.show();
|
|
649
|
+
else
|
|
650
|
+
_box.hide();
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function confirm()
|
|
654
|
+
{
|
|
655
|
+
_rgba = getRGBA();
|
|
656
|
+
_box.hide();
|
|
657
|
+
|
|
658
|
+
if (_confirmCallback)
|
|
659
|
+
_confirmCallback(_instance, { rgba: _rgba });
|
|
660
|
+
|
|
661
|
+
_confirmCallback = null;
|
|
662
|
+
_instance.events.onConfirm.fire(_instance, { rgba: _rgba });
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function cancel()
|
|
666
|
+
{
|
|
667
|
+
setRGBA.apply(_instance, _rgba);
|
|
668
|
+
rgbChanged();
|
|
669
|
+
_box.hide();
|
|
670
|
+
}
|
|
671
|
+
function clear()
|
|
672
|
+
{
|
|
673
|
+
const color = _rgba.slice();
|
|
674
|
+
|
|
675
|
+
color[3] = 0;
|
|
676
|
+
setRGBA.apply(_instance, color);
|
|
677
|
+
rgbChanged();
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function saturationSelect()
|
|
681
|
+
{
|
|
682
|
+
var scroll = $lib.getScrollPosition(),
|
|
683
|
+
overshootX = _draggableSatPicker.settings.boundaryOvershootLeft,
|
|
684
|
+
overshootY = _draggableSatPicker.settings.boundaryOvershootTop,
|
|
685
|
+
parentNode = _draggableSatPicker.element.parentNode,
|
|
686
|
+
parentPos = $lib.getPos(parentNode),
|
|
687
|
+
parentDev = $lib.borderAndPadding(parentNode),
|
|
688
|
+
minY = (parentPos.top + parentDev.borderTop) - overshootY,
|
|
689
|
+
maxY = (parentPos.top + parentDev.borderTop) + (255 - overshootY),
|
|
690
|
+
minX = (parentPos.left + parentDev.borderLeft) - overshootX,
|
|
691
|
+
maxX = (parentPos.left + parentDev.borderLeft) + (255 - overshootX),
|
|
692
|
+
clientX = ($lib.clientX($lib.event) + scroll.scrollLeft) - overshootX,
|
|
693
|
+
clientY = ($lib.clientY($lib.event) + scroll.scrollTop) - overshootY;
|
|
694
|
+
|
|
695
|
+
if (clientX < minX)
|
|
696
|
+
clientX = minX;
|
|
697
|
+
if (clientX > maxX)
|
|
698
|
+
clientX = maxX;
|
|
699
|
+
|
|
700
|
+
if (clientY < minY)
|
|
701
|
+
clientY = minY;
|
|
702
|
+
if (clientY > maxY)
|
|
703
|
+
clientY = maxY;
|
|
704
|
+
|
|
705
|
+
$lib.setPos(_draggableSatPicker.element, { top: clientY, left: clientX });
|
|
706
|
+
sliderChanged();
|
|
707
|
+
_draggableSatPicker.startDrag($lib.event);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function hueSelect(e)
|
|
711
|
+
{
|
|
712
|
+
var scroll = $lib.getScrollPosition(),
|
|
713
|
+
overshootY = _draggableHuePicker.settings.boundaryOvershootTop,
|
|
714
|
+
parentNode = _draggableHuePicker.element.parentNode,
|
|
715
|
+
parentPos = $lib.getPos(parentNode),
|
|
716
|
+
parentDev = $lib.borderAndPadding(parentNode),
|
|
717
|
+
minY = (parentPos.top + parentDev.borderTop) - overshootY,
|
|
718
|
+
maxY = (parentPos.top + parentDev.borderTop) + (255 - overshootY),
|
|
719
|
+
clientY = ($lib.clientY(e) + scroll.scrollTop) - overshootY;
|
|
720
|
+
|
|
721
|
+
if (clientY < minY)
|
|
722
|
+
clientY = minY;
|
|
723
|
+
if (clientY > maxY)
|
|
724
|
+
clientY = maxY;
|
|
725
|
+
|
|
726
|
+
$lib.setPos(_draggableHuePicker.element, { top: clientY });
|
|
727
|
+
sliderChanged();
|
|
728
|
+
_draggableHuePicker.startDrag(e);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function sliderChanged()
|
|
732
|
+
{
|
|
733
|
+
var hPicker = _draggableHuePicker, sPicker = _draggableSatPicker,
|
|
734
|
+
h = 1 - (Math.round(hPicker.element.style.top.replace(/[^0-9\.\-]/g, '')) + hPicker.settings.boundaryOvershootTop) / 255,
|
|
735
|
+
s = (Math.round(sPicker.element.style.left.replace(/[^0-9\.\-]/g, '')) + sPicker.settings.boundaryOvershootLeft) / 255,
|
|
736
|
+
b = 1 - (Math.round(sPicker.element.style.top.replace(/[^0-9\.\-]/g, '')) + sPicker.settings.boundaryOvershootTop) / 255,
|
|
737
|
+
rgba = hsvToRgb(h, s, b),
|
|
738
|
+
alpha = getAlpha();
|
|
739
|
+
|
|
740
|
+
if (alpha === 0)
|
|
741
|
+
{
|
|
742
|
+
alpha = 1;
|
|
743
|
+
setAlpha(alpha);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
rgba.push(alpha);
|
|
747
|
+
setSaturationBaseColor(h);
|
|
748
|
+
setPreview.apply(_instance, rgba);
|
|
749
|
+
setHSBA(h, s, b);
|
|
750
|
+
setRGBA.apply(_instance, rgba);
|
|
751
|
+
setHex($lib.rgbToHex.apply(_instance, rgba));
|
|
752
|
+
changed();
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
function hsbChanged()
|
|
756
|
+
{
|
|
757
|
+
var hsb = [], rgba;
|
|
758
|
+
hsb[0] = $UI.store[_instance.id + '_h'].getValue() || 0;
|
|
759
|
+
hsb[1] = $UI.store[_instance.id + '_s'].getValue() || 0;
|
|
760
|
+
hsb[2] = $UI.store[_instance.id + '_v'].getValue() || 0;
|
|
761
|
+
|
|
762
|
+
hsb[0] /= 360;
|
|
763
|
+
hsb[1] /= 100;
|
|
764
|
+
hsb[2] /= 100;
|
|
765
|
+
rgba = hsvToRgb.apply(_instance, hsb);
|
|
766
|
+
rgba.push(getAlpha());
|
|
767
|
+
|
|
768
|
+
setSaturationBaseColor(hsb[0]);
|
|
769
|
+
setPreview.apply(_instance, rgba);
|
|
770
|
+
setRGBA.apply(_instance, rgba);
|
|
771
|
+
setHex($lib.rgbToHex.apply(_instance, rgba));
|
|
772
|
+
setSliders.apply(_instance, hsb);
|
|
773
|
+
changed();
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function rgbChanged()
|
|
777
|
+
{
|
|
778
|
+
var rgba = getRGBA(),
|
|
779
|
+
hsb = rgbToHsv.apply(_instance, rgba);
|
|
780
|
+
|
|
781
|
+
hsb.push(getAlpha());
|
|
782
|
+
setSaturationBaseColor(hsb[0]);
|
|
783
|
+
setPreview.apply(_instance, rgba);
|
|
784
|
+
setHSBA.apply(_instance, hsb);
|
|
785
|
+
setHex($lib.rgbToHex.apply(_instance, rgba));
|
|
786
|
+
setSliders.apply(_instance, hsb);
|
|
787
|
+
changed();
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
function alphaChanged()
|
|
791
|
+
{
|
|
792
|
+
setPreview.apply(_instance, getRGBA());
|
|
793
|
+
changed();
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function hexChanged()
|
|
797
|
+
{
|
|
798
|
+
var rgba = $lib.hexToRgb($lib('#' + _instance.id + '_hex').value || 0),
|
|
799
|
+
hsb = rgbToHsv.apply(_instance, rgba);
|
|
800
|
+
|
|
801
|
+
rgba.push(getAlpha());
|
|
802
|
+
setSaturationBaseColor(hsb[0]);
|
|
803
|
+
setPreview.apply(_instance, rgba);
|
|
804
|
+
setHSBA.apply(_instance, hsb);
|
|
805
|
+
setRGBA.apply(_instance, rgba);
|
|
806
|
+
setSliders.apply(_instance, hsb);
|
|
807
|
+
changed();
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
function changed()
|
|
811
|
+
{
|
|
812
|
+
_instance.events.onChange.fire(_instance, { rgba: getRGBA() });
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function setSaturationBaseColor(h)
|
|
816
|
+
{
|
|
817
|
+
var step = h / (1 / 6),
|
|
818
|
+
pos = step - Math.floor(step),
|
|
819
|
+
r = 0, g = 0, b = 0;
|
|
820
|
+
|
|
821
|
+
if (step == 6)
|
|
822
|
+
step = 0;
|
|
823
|
+
|
|
824
|
+
switch (Math.floor(step))
|
|
825
|
+
{
|
|
826
|
+
case 0:
|
|
827
|
+
r = 255;
|
|
828
|
+
g = pos * 255;
|
|
829
|
+
break;
|
|
830
|
+
case 1:
|
|
831
|
+
r = 255 - (pos * 255);
|
|
832
|
+
g = 255;
|
|
833
|
+
break;
|
|
834
|
+
case 2:
|
|
835
|
+
g = 255;
|
|
836
|
+
b = pos * 255;
|
|
837
|
+
break;
|
|
838
|
+
case 3:
|
|
839
|
+
g = 255 - (pos * 255);
|
|
840
|
+
b = 255;
|
|
841
|
+
break;
|
|
842
|
+
case 4:
|
|
843
|
+
r = pos * 255;
|
|
844
|
+
b = 255;
|
|
845
|
+
break;
|
|
846
|
+
case 5:
|
|
847
|
+
r = 255;
|
|
848
|
+
b = 255 - (pos * 255);
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
$lib(_instance.cssClassSaturation || _classOption.SATURATION, _instance.element, 'div', true).style.backgroundColor = "rgba(" + [Math.round(r), Math.round(g), Math.round(b), 1].join(',') + ")";
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function setSliders(h, s, b)
|
|
856
|
+
{
|
|
857
|
+
_draggableHuePicker.element.style.top = $lib.unit(((1 - h) * 255) - _draggableHuePicker.settings.boundaryOvershootTop);
|
|
858
|
+
_draggableSatPicker.element.style.left = $lib.unit((s * 255) - _draggableSatPicker.settings.boundaryOvershootLeft);
|
|
859
|
+
_draggableSatPicker.element.style.top = $lib.unit(((1 - b) * 255) - _draggableSatPicker.settings.boundaryOvershootTop);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function setHSBA(h, s, b, a)
|
|
863
|
+
{
|
|
864
|
+
h = Math.round(h * 360);
|
|
865
|
+
$UI.store[_instance.id + '_h'].setValue((h == 360) ? 0 : h);
|
|
866
|
+
$UI.store[_instance.id + '_s'].setValue(Math.round(s * 100));
|
|
867
|
+
$UI.store[_instance.id + '_v'].setValue(Math.round(b * 100));
|
|
868
|
+
setAlpha(a);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function setRGBA(r, g, b, a)
|
|
872
|
+
{
|
|
873
|
+
$UI.store[_instance.id + '_r'].setValue(r);
|
|
874
|
+
$UI.store[_instance.id + '_g'].setValue(g);
|
|
875
|
+
$UI.store[_instance.id + '_b'].setValue(b);
|
|
876
|
+
setAlpha(a);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function setAlpha(a)
|
|
880
|
+
{
|
|
881
|
+
if (!$lib.isEmpty(a))
|
|
882
|
+
$UI.store[_instance.id + '_a'].setValue(Math.round(a * 100));
|
|
883
|
+
else if ($lib.isEmpty($UI.store[_instance.id + '_a'].getValue()))
|
|
884
|
+
$UI.store[_instance.id + '_a'].setValue(100);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function setHex(hex)
|
|
888
|
+
{
|
|
889
|
+
_hex.value = hex.replace('#', '');
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function setPreview(r, g, b, a)
|
|
893
|
+
{
|
|
894
|
+
a = ($lib.isEmpty(a)) ? 100 : a;
|
|
895
|
+
$lib(_instance.cssClassPreview || _classOption.PREVIEW, _instance.element, 'div', true).firstChild.style.backgroundColor = "rgba(" + [r, g, b, a].join(',') + ")";
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function getHSBA()
|
|
899
|
+
{
|
|
900
|
+
var hsba = [];
|
|
901
|
+
|
|
902
|
+
hsba[0] = parseInt($UI.store[_instance.id + '_h'].getValue() || 0, 10);
|
|
903
|
+
hsba[1] = parseInt($UI.store[_instance.id + '_s'].getValue() || 0, 10);
|
|
904
|
+
hsba[2] = parseInt($UI.store[_instance.id + '_v'].getValue() || 0, 10);
|
|
905
|
+
hsba[3] = getAlpha();
|
|
906
|
+
|
|
907
|
+
return hsba;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
function getRGBA()
|
|
911
|
+
{
|
|
912
|
+
var rgba = [];
|
|
913
|
+
rgba[0] = parseInt($UI.store[_instance.id + '_r'].getValue() || 0, 10);
|
|
914
|
+
rgba[1] = parseInt($UI.store[_instance.id + '_g'].getValue() || 0, 10);
|
|
915
|
+
rgba[2] = parseInt($UI.store[_instance.id + '_b'].getValue() || 0, 10);
|
|
916
|
+
rgba[3] = getAlpha();
|
|
917
|
+
return rgba;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function getHex()
|
|
921
|
+
{
|
|
922
|
+
return '#' + _hex.value;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
function getAlpha()
|
|
926
|
+
{
|
|
927
|
+
return parseInt($UI.store[_instance.id + '_a'].getValue() || 100, 10) / 100;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function rgbToHsv(r, g, b) { return componyx.UI.ColorPicker.rgbToHsv(r, g, b); }
|
|
931
|
+
function hsvToRgb(h, s, v) { return componyx.UI.ColorPicker.hsvToRgb(h, s, v); }
|
|
932
|
+
|
|
933
|
+
function dispose()
|
|
934
|
+
{
|
|
935
|
+
_box = null;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* @see {@link componyx.UI.base.methods}
|
|
941
|
+
*/
|
|
942
|
+
componyx.UI.ColorPicker.prototype = Object.create($base.methods);
|
|
943
|
+
componyx.UI.ColorPicker.prototype.constructor = componyx.UI.ColorPicker;
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* Converts the rgb value to hsv.
|
|
947
|
+
* @param {Number} r The red value 0-255.
|
|
948
|
+
* @param {Number} g The green value 0-255.
|
|
949
|
+
* @param {Number} b The blue value 0-255.
|
|
950
|
+
* @returns {Number[]} The hue saturation value.
|
|
951
|
+
*/
|
|
952
|
+
componyx.UI.ColorPicker.rgbToHsv = function (r, g, b)
|
|
953
|
+
{
|
|
954
|
+
return $lib.rgbToHsv(r, g, b);
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Converts the hsv value to rgb.
|
|
959
|
+
* @param {Number} h The hue value 0-1.
|
|
960
|
+
* @param {Number} s The saturation value 0-1.
|
|
961
|
+
* @param {Number} v The lightness value 0-1.
|
|
962
|
+
* @returns {Number[]} The rgb value.
|
|
963
|
+
*/
|
|
964
|
+
componyx.UI.ColorPicker.hsvToRgb = function (h, s, v)
|
|
965
|
+
{
|
|
966
|
+
return $lib.hsvToRgb(h, s, v);
|
|
967
|
+
};
|
|
968
|
+
})();
|
|
969
|
+
|
|
970
|
+
const ColorPicker = componyx.UI.ColorPicker;
|
|
971
|
+
|
|
972
|
+
export { ColorPicker };
|