Permalink
Browse files

if contrast first argument does not match, pass it through. Fixes #1090

  • Loading branch information...
1 parent 4f47545 commit ba99755f6b00088766a700ff93d7b4eb326c93da @lukeapage lukeapage committed Dec 30, 2012
Showing with 19 additions and 6 deletions.
  1. +5 −0 lib/less/functions.js
  2. +12 −6 lib/less/tree/call.js
  3. +1 −0 test/css/functions.css
  4. +1 −0 test/less/functions.less
View
@@ -173,6 +173,11 @@ tree.functions = {
return this.desaturate(color, new(tree.Dimension)(100));
},
contrast: function (color, dark, light, threshold) {
+ // filter: contrast(3.2);
+ // should be kept as is, so check for color
+ if (!color.rgb) {
+ return null;
+ }
if (typeof light === 'undefined') {
light = this.rgba(255, 255, 255, 1.0);
}
View
@@ -14,7 +14,8 @@ tree.Call.prototype = {
// When evaluating a function call,
// we either find the function in `tree.functions` [1],
// in which case we call it, passing the evaluated arguments,
- // or we simply print it out as it appeared originally [2].
+ // if this returns null or we cannot find the function, we
+ // simply print it out as it appeared originally [2].
//
// The *functions.js* file contains the built-in functions.
//
@@ -23,21 +24,26 @@ tree.Call.prototype = {
// The function should receive the value, not the variable.
//
eval: function (env) {
- var args = this.args.map(function (a) { return a.eval(env) });
+ var args = this.args.map(function (a) { return a.eval(env) }),
+ result;
if (this.name in tree.functions) { // 1.
try {
- return tree.functions[this.name].apply(tree.functions, args);
+ result = tree.functions[this.name].apply(tree.functions, args);
+ if (result != null) {
+ return result;
+ }
} catch (e) {
throw { type: e.type || "Runtime",
message: "error evaluating function `" + this.name + "`" +
(e.message ? ': ' + e.message : ''),
index: this.index, filename: this.filename };
}
- } else { // 2.
- return new(tree.Anonymous)(this.name +
- "(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
}
+
+ // 2.
+ return new(tree.Anonymous)(this.name +
+ "(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
},
toCSS: function (env) {
View
@@ -24,6 +24,7 @@
luma-yellow: 93%;
luma-cyan: 79%;
luma-white-alpha: 50%;
+ contrast-filter: contrast(30%);
contrast-white: #000000;
contrast-black: #ffffff;
contrast-red: #ffffff;
View
@@ -28,6 +28,7 @@
luma-yellow: luma(#ffff00);
luma-cyan: luma(#00ffff);
luma-white-alpha: luma(rgba(255,255,255,0.5));
+ contrast-filter: contrast(30%);
contrast-white: contrast(#fff);
contrast-black: contrast(#000);
contrast-red: contrast(#ff0000);

0 comments on commit ba99755

Please sign in to comment.