Skip to content

Commit 21cdb71

Browse files
committed
extra z_slider height
1 parent b9f0c9a commit 21cdb71

File tree

6 files changed

+34
-28
lines changed

6 files changed

+34
-28
lines changed

colors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@
267267
'#' + colors.HEX;
268268

269269
return isHex ? innerText : (shouldBeHex ? 'rgb' : colorMode) +
270-
(hasAlpha ? 'a' : '') + '(' + innerText + (hasAlpha ? ', ' + alpha : '') + ')';
270+
(hasAlpha ? 'a' : '') + '(' + innerText +
271+
(hasAlpha ? ', ' + alpha : '') + ')';
271272
},
272273

273274
RGB2HEX: function(RGB) {

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<link rel="stylesheet" type="text/css" href="../index.css">
1212
<link id="colorPickerMod" rel="stylesheet" type="text/css" href="mod.css">
13-
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
13+
<script src="http://code.jquery.com/jquery-2.2.3.min.js"></script>
1414
<!-- <script type="text/javascript" src="../jqColorPicker.min.js"></script> -->
1515
<script type="text/javascript" src="../colors.js"></script>
1616
<script type="text/javascript" src="../jqColorPicker.js"></script>

demo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ $(function(){
8080
this.$sliders.toggle(!$elm.hasClass('no-sliders'));
8181
}
8282

83-
this.patchStyle.backgroundColor = $elm[0].style.backgroundColor; // set patch color...
83+
// this.patchStyle.backgroundColor = $elm[0].style.backgroundColor; // set patch color...
84+
this.patchStyle.backgroundColor = this.color.toString(); // no DOM access
8485
this.$display.text(this.color.options.colorNames[colors.HEX] || $elm.val()); // ...and text aside
8586

8687
this.currentWidth = this.currentWidth || this.$UI.find('.cp-rgb-r')[0].clientWidth; // first time

jqColorPicker.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
_color,
1818
_options,
1919

20-
_$trigger,
21-
_$UI, _$xy_slider, _$xy_cursor, _$z_cursor , _$alpha , _$alpha_cursor,
20+
_$trigger, _$UI,
21+
_$z_slider, _$xy_slider,
22+
_$xy_cursor, _$z_cursor , _$alpha , _$alpha_cursor,
2223

23-
_pointermove = 'touchmove.a mousemove.a pointermove.a',
24-
_pointerdown = 'touchstart.a mousedown.a pointerdown.a',
25-
_pointerup = 'touchend.a mouseup.a pointerup.a',
24+
_pointermove = 'touchmove.tcp mousemove.tcp pointermove.tcp',
25+
_pointerdown = 'touchstart.tcp mousedown.tcp pointerdown.tcp',
26+
_pointerup = 'touchend.tcp mouseup.tcp pointerup.tcp',
2627
_GPU = false,
2728
_round = Math.round,
2829
_animate = window.requestAnimationFrame ||
@@ -93,29 +94,32 @@
9394
(_$UI || build()).css({
9495
// 'width': _$UI[0]._width,
9596
'left': (_$UI[0]._left = position.left) -
96-
((_$UI[0]._left = _$UI[0]._left + _$UI[0]._width -
97+
((_$UI[0]._left += _$UI[0]._width -
9798
($window.scrollLeft() + $window.width())) + gap > 0 ?
9899
_$UI[0]._left + gap : 0),
99100
'top': (_$UI[0]._top = position.top + $this.outerHeight()) -
100-
((_$UI[0]._top = _$UI[0]._top + _$UI[0]._height -
101+
((_$UI[0]._top += _$UI[0]._height -
101102
($window.scrollTop() + $window.height())) + gap > 0 ?
102103
_$UI[0]._top + gap : 0)
103104
}).show(_options.animationSpeed, function() {
104-
if (event === true) {
105+
if (event === true) { // resize, scroll
105106
return;
106107
}
107108
_$alpha._width = _$alpha.width();
108109
_$xy_slider._width = _$xy_slider.width();
109110
_$xy_slider._height = _$xy_slider.height();
111+
_$z_slider._height = _$z_slider.height();
110112
_color.setColor(extractValue(_$trigger[0]));
111113

112114
preRender(true);
113-
});
115+
})
116+
.off('.tcp').on(_pointerdown,
117+
'.cp-xy-slider,.cp-z-slider,.cp-alpha', pointerdown);
114118
} else if (_colorPicker.$trigger) {
115119
$(_$UI).hide(_options.animationSpeed, function() {
116120
preRender(false);
117121
_colorPicker.$trigger = null;
118-
});
122+
}).off('.tcp');
119123
}
120124
}
121125

@@ -130,6 +134,7 @@
130134
var $this = $(this);
131135

132136
_GPU = _options.GPU && $this.css('perspective') !== undefined;
137+
_$z_slider = $('.cp-z-slider', this);
133138
_$xy_slider = $('.cp-xy-slider', this);
134139
_$xy_cursor = $('.cp-xy-cursor', this);
135140
_$z_cursor = $('.cp-z-cursor', this);
@@ -141,9 +146,7 @@
141146
);
142147
this._width = this.offsetWidth;
143148
this._height = this.offsetHeight;
144-
}).hide()
145-
.on(_pointerdown,
146-
'.cp-xy-slider,.cp-z-slider,.cp-alpha', pointerdown);
149+
}).hide();
147150
}
148151

149152
function pointerdown(e) {
@@ -162,7 +165,7 @@
162165
preRender();
163166

164167
$document.on(_pointerup, function(e) {
165-
$document.off('.a');
168+
$document.off('.tcp');
166169
}).on(_pointermove, function(e) {
167170
action(e);
168171
preRender();
@@ -183,7 +186,7 @@
183186
function z_slider(event) {
184187
var z = resolveEventType(event).pageY - _$trigger._offset.top;
185188

186-
_color.setColor({h: 360 - (z / _$xy_slider._height * 360)}, 'hsv');
189+
_color.setColor({h: 360 - (z / _$z_slider._height * 360)}, 'hsv');
187190
}
188191

189192
function alpha(event) {
@@ -205,7 +208,7 @@
205208
alphaContrast = colors.rgbaMixBlack.luminance > 0.22 ? dark : light,
206209
h = (1 - colors.hsv.h) * _$xy_slider._height,
207210
s = colors.hsv.s * _$xy_slider._width,
208-
v = (1 - colors.hsv.v) * _$xy_slider._height,
211+
v = (1 - colors.hsv.v) * _$z_slider._height,
209212
a = colors.alpha * _$alpha._width,
210213
translate3d = _GPU ? 'translate3d' : '',
211214
triggerValue = _$trigger[0].value,
@@ -286,7 +289,7 @@
286289
}, options);
287290

288291
!_colorPicker && options.scrollResize && $(window)
289-
.on('resize.a scroll.a', function() {
292+
.on('resize.tcp scroll.tcp', function() {
290293
if (_colorPicker.$trigger) {
291294
_colorPicker.toggle.call(_colorPicker.$trigger[0], true);
292295
}
@@ -295,13 +298,13 @@
295298
this.colorPicker = _instance.colorPicker =
296299
_colorPicker || new ColorPicker(options);
297300

298-
$(options.body).off('.a').on(_pointerdown, function(e) {
301+
$(options.body).off('.tcp').on(_pointerdown, function(e) {
299302
!_instance.add(_$UI).find(e.target)
300303
.add(_instance.filter(e.target))[0] && toggle();
301304
});
302305

303-
return this.on('focusin.a click.a', toggle)
304-
.on('change.a', function() {
306+
return this.on('focusin.tcp click.tcp', toggle)
307+
.on('change.tcp', function() {
305308
_color.setColor(this.value || '#FFF');
306309
_instance.colorPicker.render(true);
307310
})
@@ -316,16 +319,17 @@
316319
$elm.css({'background-color': value,
317320
'color': function() {
318321
return _color.setColor(value)
319-
.rgbaMixBGMixCustom.luminance > 0.22 ? '#222' : '#ddd'
322+
.rgbaMixBGMixCustom.luminance > 0.22 ? '#222' : '#DDD'
320323
}
321324
});
322325
});
323326
};
324327

325328
$.fn.colorPicker.destroy = function() {
326-
_instance.add(_options.body).off('.a'); // saver
329+
$('*').off('.tcp'); // slower but saver
327330
_colorPicker.toggle(false);
328331
_instance = $();
332+
// destroy _colorPicker
329333
};
330334

331335
}));

0 commit comments

Comments
 (0)