Cleanup. Now responds to env.compress

This commit is contained in:
Kevin Gillette
2013-06-20 14:40:30 -06:00
committed by Luke Page
parent 54a5f74c09
commit 3d46350a40

View File

@@ -266,47 +266,48 @@ tree.functions = {
throw { type: "Argument", message: "argument must be a number" };
}
},
_minmax: function (name, args) {
_minmax: function (isMin, args) {
args = Array.prototype.slice.call(args);
switch(args.length) {
case 0: throw { type: "Argument", message: "one or more arguments required" };
case 1: return args[0];
}
var i, j, cur, ucur, uref, u,
isMin = name == 'min',
var i, j, current, currentUnified, referenceUnified, unit,
order = [], // elems only contains original argument values.
values = {}; // key is the unit.toString() for unified tree.Dimension values,
// value is the index into the order array.
for(i = 0; i < args.length; i++) {
cur = args[i];
if(!(cur instanceof tree.Dimension)) {
order.push(cur);
for (i = 0; i < args.length; i++) {
current = args[i];
if (!(current instanceof tree.Dimension)) {
order.push(current);
continue;
}
ucur = cur.unify();
u = ucur.unit.toString();
j = values[u];
if(j === undefined) {
values[u] = order.length;
order.push(cur);
currentUnified = current.unify();
unit = currentUnified.unit.toString();
j = values[unit];
if (j === undefined) {
values[unit] = order.length;
order.push(current);
continue;
}
uref = order[j].unify();
if(isMin && ucur.value < uref.value || !isMin && ucur.value > uref.value) {
order[j] = cur;
referenceUnified = order[j].unify();
if ( isMin && currentUnified.value < referenceUnified.value ||
!isMin && currentUnified.value > referenceUnified.value) {
order[j] = current;
}
}
if(order.length == 1) {
if (order.length == 1) {
return order[0];
}
return new(tree.Anonymous)(name +
"(" + order.map(function (a) { return a.toCSS(); }).join(', ') + ")");
args = order.map(function (a) { return a.toCSS(this.env); })
.join(this.env.compress ? "," : ", ");
return new(tree.Anonymous)((isMin ? "min" : "max") + "(" + args + ")");
},
min: function () {
return this._minmax('min', arguments);
return this._minmax(true, arguments);
},
max: function () {
return this._minmax('max', arguments);
return this._minmax(false, arguments);
},
argb: function (color) {
return new(tree.Anonymous)(color.toARGB());