2
0
mirror of https://github.com/PitPik/colorPicker.git synced 2025-08-27 11:02:47 -06:00

little bug fix and linting

Using ColorPicker.prototype.saveAsBackground needs some update of
variables (in preRenderAll()) to render the WGCA bar right and
calculating all color values correct…
This commit is contained in:
peterd 2014-09-08 18:22:06 +02:00
parent 5be71259ae
commit c6cb9f9585
2 changed files with 35 additions and 29 deletions

View File

@ -39,10 +39,10 @@
_targetOrigin = {}, _targetOrigin = {},
_renderTimer, // animationFrame/interval variable _renderTimer, // animationFrame/interval variable
_newData = true, _newData = true,
_txt = { // _txt = {
selection: document.selection || window.getSelection(), // selection: document.selection || window.getSelection(),
range: (document.createRange ? document.createRange() : document.body.createTextRange()) // range: (document.createRange ? document.createRange() : document.body.createTextRange())
}, // },
_renderVars = {}, // used only in renderAll and convertColors _renderVars = {}, // used only in renderAll and convertColors
_cashedVars = {}, // reset in initSliders _cashedVars = {}, // reset in initSliders
@ -120,11 +120,11 @@
if (forceRender) { if (forceRender) {
this.startRender(true); this.startRender(true);
} }
} };
ColorPicker.prototype.saveAsBackground = function() { ColorPicker.prototype.saveAsBackground = function() {
focusInstance(this); focusInstance(this);
return saveAsBackground(); return saveAsBackground(true);
}; };
ColorPicker.prototype.setCustomBackground = function(col) { ColorPicker.prototype.setCustomBackground = function(col) {
@ -171,7 +171,7 @@
} }
nodes[n] = null; nodes[n] = null;
delete nodes[n]; delete nodes[n];
}; }
}; };
this.stopRender(); this.stopRender();
@ -213,17 +213,17 @@
//_nodes.colorPicker.className += ' cmy-' + _options.cmyOnly; //_nodes.colorPicker.className += ' cmy-' + _options.cmyOnly;
if (_options.noHexButton) { if (_options.noHexButton) {
changeClass(_nodes.HEX_butt, CSSPrefix + 'butt', CSSPrefix + 'labl') changeClass(_nodes.HEX_butt, CSSPrefix + 'butt', CSSPrefix + 'labl');
} }
if (_options.size !== undefined) { if (_options.size !== undefined) {
resizeApp (undefined, _options.size); resizeApp(undefined, _options.size);
} }
optionButtons = { optionButtons = {
alphaBG: _nodes.alpha_labl, alphaBG: _nodes.alpha_labl,
cmyOnly: _nodes.HEX_labl // test... take out cmyOnly: _nodes.HEX_labl // test... take out
} };
for (var n in optionButtons) { for (var n in optionButtons) {
if (_options[n] !== undefined) { if (_options[n] !== undefined) {
buttonActions({target: optionButtons[n], data: _options[n]}); buttonActions({target: optionButtons[n], data: _options[n]});
@ -408,14 +408,14 @@
_mainTarget = target; _mainTarget = target;
stopChange(undefined, 'resetEventListener'); stopChange(undefined, 'resetEventListener');
if (target == _nodes.sldl_3 || target == _nodes.curm) { if (target === _nodes.sldl_3 || target === _nodes.curm) {
_mainTarget = _nodes.sldl_3; _mainTarget = _nodes.sldl_3;
_mouseMoveAction = changeXYValue; _mouseMoveAction = changeXYValue;
changeClass(_nodes.slds, 'do-drag'); changeClass(_nodes.slds, 'do-drag');
} else if (/sldr/.test(className) || target == _nodes.curl || target == _nodes.curr) { } else if (/sldr/.test(className) || target === _nodes.curl || target === _nodes.curr) {
_mainTarget = _nodes.sldr_4; _mainTarget = _nodes.sldr_4;
_mouseMoveAction = changeZValue; _mouseMoveAction = changeZValue;
} else if (target == _nodes.opacity.children[0] || target == _nodes.opacity_slider) { } else if (target === _nodes.opacity.children[0] || target === _nodes.opacity_slider) {
_mainTarget = _nodes.opacity; _mainTarget = _nodes.opacity;
_mouseMoveAction = changeOpacityValue; _mouseMoveAction = changeOpacityValue;
} else if (/-disp/.test(className) && !/HEX-/.test(className)) { } else if (/-disp/.test(className) && !/HEX-/.test(className)) {
@ -426,7 +426,7 @@
_valueType = {type: _valueType[0], z: _valueType[1] || ''}; _valueType = {type: _valueType[0], z: _valueType[1] || ''};
changeClass(_nodes.panel, 'start-change'); changeClass(_nodes.panel, 'start-change');
_delayState = 0; _delayState = 0;
} else if (target == _nodes.resize && !_options.noResize) { } else if (target === _nodes.resize && !_options.noResize) {
if (!_options.sizes) { if (!_options.sizes) {
getUISizes(); getUISizes();
} }
@ -477,7 +477,7 @@
onOffEvent(_nodes.colorPicker, 'paste', function(e) { onOffEvent(_nodes.colorPicker, 'paste', function(e) {
e.target.firstChild.data = e.clipboardData.getData('Text'); e.target.firstChild.data = e.clipboardData.getData('Text');
return preventDefault(event); return preventDefault(e);
}); });
} }
@ -750,9 +750,9 @@
changeClass(_nodes.colorPicker, 'no-HEX', (options.HEXState = !options.HEXState) ? undefined : ''); changeClass(_nodes.colorPicker, 'no-HEX', (options.HEXState = !options.HEXState) ? undefined : '');
buttonAction = 'HEXState'; buttonAction = 'HEXState';
} else if (target === _nodes.HEX_labl) { // web save state change } else if (target === _nodes.HEX_labl) { // web save state change
var isWebSave = _colors.saveColor === "web save"; var isWebSave = _colors.saveColor === 'web save';
if (_colors.saveColor !== "web smart" && !isWebSave) { if (_colors.saveColor !== 'web smart' && !isWebSave) {
options.webUnsave = copyColor(RGB); options.webUnsave = copyColor(RGB);
_colorPicker.setColor(_colors.webSmart, 'rgb'); _colorPicker.setColor(_colors.webSmart, 'rgb');
} else if (!isWebSave) { } else if (!isWebSave) {
@ -954,11 +954,15 @@
_newData = true; _newData = true;
} }
function saveAsBackground() { function saveAsBackground(refresh) {
_colorInstance.saveAsBackground(); _colorInstance.saveAsBackground();
_nodes.styles.col2.cssText = 'background-color: ' + color2string(_colors.background.RGB) + ';' + _nodes.styles.col2.cssText = 'background-color: ' + color2string(_colors.background.RGB) + ';' +
getOpacityCSS(_colors.background.alpha); getOpacityCSS(_colors.background.alpha);
if (refresh) {
preRenderAll(_colors);
// renderAll();
}
return (_colors); return (_colors);
} }
@ -1215,7 +1219,7 @@
return { return {
X: e.pageX || e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft, X: e.pageX || e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
Y: e.pageY || e.clientY + document.body.scrollTop + document.documentElement.scrollTop Y: e.pageY || e.clientY + document.body.scrollTop + document.documentElement.scrollTop
} };
} }
function addEvent(obj, type, func) { function addEvent(obj, type, func) {
@ -1253,7 +1257,7 @@
} }
if (obj.addEventListener) obj.addEventListener(type, func, false); if (obj.addEventListener) obj.addEventListener(type, func, false);
else obj.attachEvent("on" + type, func); else obj.attachEvent('on' + type, func);
} }
function removeEvent(obj, type, func) { function removeEvent(obj, type, func) {
@ -1263,7 +1267,7 @@
} }
if (obj.removeEventListener) obj.removeEventListener(type, func, false); if (obj.removeEventListener) obj.removeEventListener(type, func, false);
else obj.detachEvent("on" + type, func); else obj.detachEvent('on' + type, func);
} }
function caret(target, pos) { // only for contenteditable function caret(target, pos) { // only for contenteditable
@ -1279,7 +1283,7 @@
out = { out = {
end: range2.toString().length, end: range2.toString().length,
range: range1.toString().length range: range1.toString().length
} };
} else { // IE < 9 } else { // IE < 9
target.focus(); target.focus();
var range1 = document.selection.createRange(), var range1 = document.selection.createRange(),
@ -1289,7 +1293,7 @@
out = { out = {
end: range2.text.length, end: range2.text.length,
range: range1.text.length range: range1.text.length
} };
} }
out.start = out.end - out.range; out.start = out.end - out.range;
return out; return out;

View File

@ -392,7 +392,7 @@
r: Math.round([1, 1 - i, 0, 0, i, 1][mod] * 255), r: Math.round([1, 1 - i, 0, 0, i, 1][mod] * 255),
g: Math.round([i, 1, 1, 1 - i, 0, 0][mod] * 255), g: Math.round([i, 1, 1, 1 - i, 0, 0][mod] * 255),
b: Math.round([0, 0, i, 1, 1, 1 - i][mod] * 255) b: Math.round([0, 0, i, 1, 1, 1 - i][mod] * 255)
} };
}, },
// ------------------------ HSV ------------------------ // // ------------------------ HSV ------------------------ //
@ -452,7 +452,7 @@
h: hsv.h, h: hsv.h,
s: !hsv.v && !s ? ((_colors && _colors.hsl.s) || 0) : s, // ??? s: !hsv.v && !s ? ((_colors && _colors.hsl.s) || 0) : s, // ???
l: l / 2 l: l / 2
} };
}, },
rgb2hsl: function(rgb, dependent) { // not used in Color rgb2hsl: function(rgb, dependent) { // not used in Color
@ -551,11 +551,13 @@
r = X * M.R[0] + Y * M.R[1] + Z * M.R[2], r = X * M.R[0] + Y * M.R[1] + Z * M.R[2],
g = X * M.G[0] + Y * M.G[1] + Z * M.G[2], g = X * M.G[0] + Y * M.G[1] + Z * M.G[2],
b = X * M.B[0] + Y * M.B[1] + Z * M.B[2], b = X * M.B[0] + Y * M.B[1] + Z * M.B[2],
N = 1 / 2.4, M = 0.0031308; N = 1 / 2.4;
r = (r > M ? 1.055 * Math.pow(r, N) - 0.055 : 12.92 * r); M = 0.0031308;
g = (g > M ? 1.055 * Math.pow(g, N) - 0.055 : 12.92 * g);
b = (b > M ? 1.055 * Math.pow(b, N) - 0.055 : 12.92 * b); r = (r > M ? 1.055 * Math.pow(r, N) - 0.055 : 12.92 * r);
g = (g > M ? 1.055 * Math.pow(g, N) - 0.055 : 12.92 * g);
b = (b > M ? 1.055 * Math.pow(b, N) - 0.055 : 12.92 * b);
if (!skip) { // out of gammut if (!skip) { // out of gammut
_colors._rgb = {r: r, g: g, b: b}; _colors._rgb = {r: r, g: g, b: b};