Skip to content

Commit cd0e084

Browse files
committed
Minor updates
- minor optimizations - added options ‘dark’ and ‘light’
1 parent 9d7ea52 commit cd0e084

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ $('.color').colorPicker({
5454
margin: '', // positioning margin (can also be set in cssAddon)
5555
scrollResize: true // toggle for reposition colorPicker on window.resize/scroll
5656
gap: 4 // gap to right and bottom edge of view port if repositioned to fit
57+
dark: '#222' // default font color if background is light
58+
light: '#DDD' // default font color if background is dark
5759
preventFocus: false // prevents default on focus of input fields (e.g. no keyboard on mobile)
5860
body: document.body // the element where the events are attached to (touchstart, mousedown, pointerdown, focus, click, change),
5961
forceAlpha: // force printing alpha channel (undefined = auto; false = never print alpha)

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h2>Features</h2>
7373
<pre style="display: block; overflow: auto;">
7474
window.myColorPicker = $('input.color').colorPicker({
7575
buildCallback: function($elm) {
76-
$elm.prepend('&lt;div class="cp-disp">&lt;/div>');
76+
this.$colorPatch = $elm.prepend('&lt;div class="cp-disp">').find('.cp-disp');
7777
},
7878
cssAddon:
7979
'.cp-disp {padding:10px; margin-bottom:6px; font-size:19px; height:20px; line-height:20px}' +
@@ -87,10 +87,10 @@ <h2>Features</h2>
8787
renderCallback: function($elm, toggled) {
8888
var colors = this.color.colors;
8989

90-
$('.cp-disp').css({
90+
this.$colorPatch.css({
9191
backgroundColor: '#' + colors.HEX,
9292
color: colors.RGBLuminance > 0.22 ? '#222' : '#ddd'
93-
}).text(this.color.toString($elm._colorMode));
93+
}).text(this.color.toString($elm._colorMode)); // $elm.val();
9494
}
9595
});
9696
</pre>

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// demo on how to make plugins... mobile support plugin
3030
buildCallback: function($elm) {
31-
$elm.prepend('<div class="cp-disp"></div>');
31+
this.$colorPatch = $elm.prepend('<div class="cp-disp">').find('.cp-disp');
3232
$('.color').on('click', function(e) {
3333
e.preventDefault && e.preventDefault();
3434
});
@@ -45,7 +45,7 @@
4545
renderCallback: function($elm, toggled) {
4646
var colors = this.color.colors;
4747

48-
$('.cp-disp').css({
48+
this.$colorPatch.css({
4949
backgroundColor: '#' + colors.HEX,
5050
color: colors.RGBLuminance > 0.22 ? '#222' : '#ddd'
5151
}).text(this.color.toString($elm._colorMode)); // $elm.val();

jqColorPicker.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
_pointerdown = 'touchstart.tcp mousedown.tcp pointerdown.tcp',
2626
_pointerup = 'touchend.tcp mouseup.tcp pointerup.tcp',
2727
_GPU = false,
28-
_round = Math.round,
2928
_animate = window.requestAnimationFrame ||
3029
window.webkitRequestAnimationFrame || function(cb){cb()},
3130
_html = '<div class="cp-color-picker"><div class="cp-z-slider"><div c' +
@@ -92,15 +91,14 @@
9291
_colorPicker.$trigger = $this;
9392

9493
(_$UI || build()).css({
95-
// 'width': _$UI[0]._width,
96-
'left': (_$UI[0]._left = position.left) -
97-
((_$UI[0]._left += _$UI[0]._width -
94+
'left': (_$UI._left = position.left) -
95+
((_$UI._left += _$UI._width -
9896
($window.scrollLeft() + $window.width())) + gap > 0 ?
99-
_$UI[0]._left + gap : 0),
100-
'top': (_$UI[0]._top = position.top + $this.outerHeight()) -
101-
((_$UI[0]._top += _$UI[0]._height -
97+
_$UI._left + gap : 0),
98+
'top': (_$UI._top = position.top + $this.outerHeight()) -
99+
((_$UI._top += _$UI._height -
102100
($window.scrollTop() + $window.height())) + gap > 0 ?
103-
_$UI[0]._top + gap : 0)
101+
_$UI._top + gap : 0)
104102
}).show(_options.animationSpeed, function() {
105103
if (event === true) { // resize, scroll
106104
return;
@@ -127,25 +125,23 @@
127125
$('head').append('<style type="text/css" id="tinyColorPickerStyles">' +
128126
(_options.css || _css) + (_options.cssAddon || '') + '</style>');
129127

130-
return _colorPicker.$UI = _$UI =
131-
$(_html).css({'margin': _options.margin})
128+
return $(_html).css({'margin': _options.margin})
132129
.appendTo('body')
133130
.show(0, function() {
134-
var $this = $(this);
131+
_colorPicker.$UI = _$UI = $(this);
135132

136-
_GPU = _options.GPU && $this.css('perspective') !== undefined;
133+
_GPU = _options.GPU && _$UI.css('perspective') !== undefined;
137134
_$z_slider = $('.cp-z-slider', this);
138135
_$xy_slider = $('.cp-xy-slider', this);
139136
_$xy_cursor = $('.cp-xy-cursor', this);
140137
_$z_cursor = $('.cp-z-cursor', this);
141138
_$alpha = $('.cp-alpha', this);
142139
_$alpha_cursor = $('.cp-alpha-cursor', this);
143-
_options.buildCallback.call(_colorPicker, $this);
144-
$this.prepend('<div>').children().eq(0).css('width',
145-
$this.children().eq(0).width() // stabilizer
146-
);
147-
this._width = this.offsetWidth;
148-
this._height = this.offsetHeight;
140+
_options.buildCallback.call(_colorPicker, _$UI);
141+
_$UI.prepend('<div>').children().eq(0).css('width',
142+
_$UI.children().eq(0).width()); // stabilizer
143+
_$UI._width = this.offsetWidth;
144+
_$UI._height = this.offsetHeight;
149145
}).hide();
150146
}
151147

@@ -201,8 +197,8 @@
201197
hueRGB = colors.hueRGB,
202198
RGB = colors.RND.rgb,
203199
HSL = colors.RND.hsl,
204-
dark = '#222',
205-
light = '#ddd',
200+
dark = _options.dark,
201+
light = _options.light,
206202
colorText = _color.toString(_$trigger._colorMode, _options.forceAlpha),
207203
HUEContrast = colors.HUELuminance > 0.22 ? dark : light,
208204
alphaContrast = colors.rgbaMixBlack.luminance > 0.22 ? dark : light,
@@ -282,6 +278,8 @@
282278
body: document.body,
283279
scrollResize: true,
284280
gap: 4,
281+
dark: '#222',
282+
light: '#DDD'
285283
// forceAlpha: undefined,
286284
// css: '',
287285
// cssAddon: '',
@@ -324,7 +322,8 @@
324322
$elm.css({'background-color': value,
325323
'color': function() {
326324
return _color.setColor(value)
327-
.rgbaMixBGMixCustom.luminance > 0.22 ? '#222' : '#DDD'
325+
.rgbaMixBGMixCustom.luminance > 0.22 ?
326+
options.dark : options.light
328327
}
329328
});
330329
});

jqColorPicker.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jqColorPicker.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinyColorPicker",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"repository": {
55
"type": "git",
66
"url": "http://github.com/PitPik/tinyColorPicker.git"

0 commit comments

Comments
 (0)