Permalink
Browse files

Give a nice warning if invalid color is passed

  • Loading branch information...
1 parent 1991b7c commit cbf9aa7d0719ef18e4d07f98ccef90994ee21ae5 @bebraw committed Jul 10, 2012
Showing with 16 additions and 5 deletions.
  1. +7 −1 dist/colorjoe.js
  2. +1 −1 dist/colorjoe.min.js
  3. +1 −2 index.html
  4. +7 −1 src/colorjoe.js
View
@@ -1280,7 +1280,11 @@ function setup(o) {
function getColor(c) {
var ret = onecolor(c);
- return ret? ret: onecolor('black');
+ if(ret) return ret;
+
+ if(isDefined(c)) console.warn('Passed invalid color to colorjoe, using black instead');
+
+ return onecolor('black');
}
function setupExtras(p, joe, extras) {
@@ -1297,7 +1301,9 @@ function setupExtras(p, joe, extras) {
}
function all(cb, a) {return a.map(cb).filter(id).length == a.length;}
+
function isString(o) {return typeof(o) === 'string';}
+function isDefined(input) {return typeof input !== "undefined";}
function isFunction(input) {return typeof input === "function";}
function id(a) {return a;}
}));
Oops, something went wrong.
View
@@ -108,8 +108,7 @@
});
defer('dist/colorjoe.js', function () {
var val = document.getElementById('rgbValue');
- // undefined or any other erroneous value results as black
- colorjoe.rgb('rgbPicker', undefined).on('change', function(c) {
+ colorjoe.rgb('rgbPicker').on('change', function(c) {
val.innerHTML = c.css();
}).update();
colorjoe.rgb('extraPicker', '#113c38', [
View
@@ -172,7 +172,11 @@ function setup(o) {
function getColor(c) {
var ret = onecolor(c);
- return ret? ret: onecolor('black');
+ if(ret) return ret;
+
+ if(isDefined(c)) console.warn('Passed invalid color to colorjoe, using black instead');
+
+ return onecolor('black');
}
function setupExtras(p, joe, extras) {
@@ -189,7 +193,9 @@ function setupExtras(p, joe, extras) {
}
function all(cb, a) {return a.map(cb).filter(id).length == a.length;}
+
function isString(o) {return typeof(o) === 'string';}
+function isDefined(input) {return typeof input !== "undefined";}
function isFunction(input) {return typeof input === "function";}
function id(a) {return a;}
}));

0 comments on commit cbf9aa7

Please sign in to comment.