code cosmetic updates

pull/32/head
peterd 9 years ago
parent f7347ddd24
commit 6ee05825b4

@ -54,7 +54,7 @@
return setColor(this.colors, newCol, type, undefined, alpha); return setColor(this.colors, newCol, type, undefined, alpha);
} else { } else {
if (alpha !== undefined) { if (alpha !== undefined) {
this.colors.alpha = alpha; this.colors.alpha = limitValue(alpha, 0, 1);
} }
return convertColors(type); return convertColors(type);
} }
@ -89,7 +89,7 @@
} }
} }
if (alpha !== undefined) { if (alpha !== undefined) {
colors.alpha = +alpha; colors.alpha = limitValue(+alpha, 0, 1);
} }
return convertColors(type, save ? colors : undefined); return convertColors(type, save ? colors : undefined);
} }

@ -1,4 +1,4 @@
(function(window, undefined){ (function(window, $, undefined){
'use strict'; 'use strict';
var plugin = {}, var plugin = {},
@ -495,4 +495,4 @@
); );
$('.trigger').colorPicker(); $('.trigger').colorPicker();
$('pre').colorPicker({doRender: false}); $('pre').colorPicker({doRender: false});
})(window); })(window, jQuery);

@ -49,7 +49,7 @@
ColorPicker.prototype = { ColorPicker.prototype = {
render: preRender, render: preRender,
toggle: toggle toggle: toggle
} };
function extractValue(elm) { function extractValue(elm) {
return elm.value || elm.getAttribute('value') || return elm.value || elm.getAttribute('value') ||
@ -105,7 +105,7 @@
preRender(false); preRender(false);
}); });
} }
}; }
function build() { function build() {
$('head').append('<style type="text/css">' + $('head').append('<style type="text/css">' +
@ -142,14 +142,17 @@
e.returnValue = false; e.returnValue = false;
_$trigger._offset = $(this).offset(); _$trigger._offset = $(this).offset();
(action = action === 'xy_slider' ? xy_slider : (action = action === 'xy_slider' ? xy_slider :
action === 'z_slider' ? z_slider : alpha)(e); action === 'z_slider' ? z_slider : alpha)(e);
preRender();
$document.on(_pointerup, pointerup).on(_pointermove, action); $document.on(_pointerup, function(e) {
} $document.off('.a');
}).on(_pointermove, function(e) {
function pointerup(e) { action(e);
$document.off('.a'); preRender();
});
} }
function xy_slider(event) { function xy_slider(event) {
@ -161,23 +164,19 @@
s: x / _$xy_slider._width * 100, s: x / _$xy_slider._width * 100,
v: 100 - (y / _$xy_slider._height * 100) v: 100 - (y / _$xy_slider._height * 100)
}, 'hsv'); }, 'hsv');
preRender();
} }
function z_slider(event) { function z_slider(event) {
var z = resolveEventType(event).pageY - _$trigger._offset.top, var z = resolveEventType(event).pageY - _$trigger._offset.top;
hsv = _color.colors.hsv;
_color.setColor({h: 360 - (z / _$xy_slider._height * 360)}, 'hsv'); _color.setColor({h: 360 - (z / _$xy_slider._height * 360)}, 'hsv');
preRender();
} }
function alpha(event) { function alpha(event) {
var x = resolveEventType(event).pageX - _$trigger._offset.left, var x = resolveEventType(event).pageX - _$trigger._offset.left,
alpha = x / _$alpha._width; alpha = x / _$alpha._width;
_color.setColor({}, 'rgb', alpha > 1 ? 1 : alpha < 0 ? 0 : alpha); _color.setColor({}, 'rgb', alpha);
preRender();
} }
function preRender(toggled) { function preRender(toggled) {
@ -295,9 +294,8 @@
on(_pointerdown, function(e) { on(_pointerdown, function(e) {
var $target = $(e.target); var $target = $(e.target);
if ($.inArray($target.closest(_selector)[0], if ($.inArray($target.closest(_selector)[0], _instance) === -1 &&
_instance) === -1 && !$target.closest(_$UI).length) {
!$target.closest(_$UI).length) {
toggle(); toggle();
} }
}). }).
@ -313,9 +311,9 @@
$elm = findElement($(this)); $elm = findElement($(this));
$elm.data('colorMode', mode[1] ? mode[0].substr(0, 3) : 'HEX'). $elm.data('colorMode', mode[1] ? mode[0].substr(0, 3) : 'HEX').
attr('readonly', _options.preventFocus); attr('readonly', _options.preventFocus);
options.doRender && $elm. options.doRender &&
css({'background-color': value, $elm.css({'background-color': value,
'color': function() { 'color': function() {
return _color.setColor(value). return _color.setColor(value).
rgbaMixBGMixCustom.luminance > 0.22 ? '#222' : '#ddd' rgbaMixBGMixCustom.luminance > 0.22 ? '#222' : '#ddd'
@ -329,6 +327,6 @@
_colorPicker.toggle(false); _colorPicker.toggle(false);
_instance = null; _instance = null;
_selector = ''; _selector = '';
} };
})(jQuery, Colors); })(jQuery, Colors);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,5 +1,5 @@
{ {
"name": "tiny colorPicker", "name": "tinyColorPicker",
"version": "1.0.0", "version": "1.0.0",
"repository": { "repository": {
"type": "git", "type": "git",
@ -7,6 +7,7 @@
}, },
"devDependencies": { "devDependencies": {
"grunt": "^0.4.5", "grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.5.1" "grunt-contrib-uglify": "^0.5.1",
"grunt-smushit": "^1.3.0"
} }
} }

Loading…
Cancel
Save