diff --git a/src/css/ValidationTypes.js b/src/css/ValidationTypes.js index 96689bc0..d3a1565e 100644 --- a/src/css/ValidationTypes.js +++ b/src/css/ValidationTypes.js @@ -40,7 +40,7 @@ var ValidationTypes = { }, /** - * Determines if the next part(s) of the given expresion + * Determines if the next part(s) of the given expression * are one of a group. */ isAnyOfGroup: function(expression, types) { @@ -187,10 +187,16 @@ var ValidationTypes = { var types = this, result = false, numeric = " | ", - xDir = "left | center | right", - yDir = "top | center | bottom", - part, - i, len; + xDir = "left | right", + yDir = "top | bottom", + count = 0, + hasNext = function() { + return expression.hasNext() && expression.peek() != ","; + }; + + while (expression.peek(count) && expression.peek(count) != ",") { + count++; + } /* = [ @@ -202,40 +208,48 @@ var ValidationTypes = { [ center | [ left | right ] [ | ]? ] && [ center | [ top | bottom ] [ | ]? ] ] +*/ -*/ - - if (ValidationTypes.isAny(expression, "top | bottom")) { - result = true; + if (count < 3) { + if (ValidationTypes.isAny(expression, xDir + " | center | " + numeric)) { + result = true; + ValidationTypes.isAny(expression, yDir + " | center | " + numeric); + } else if (ValidationTypes.isAny(expression, yDir)) { + result = true; + ValidationTypes.isAny(expression, xDir + " | center"); + } } else { - - //must be two-part - if (ValidationTypes.isAny(expression, numeric)){ - if (expression.hasNext()){ - result = ValidationTypes.isAny(expression, numeric + " | " + yDir); - } - } else if (ValidationTypes.isAny(expression, xDir)){ - if (expression.hasNext()){ - - //two- or three-part - if (ValidationTypes.isAny(expression, yDir)){ + if (ValidationTypes.isAny(expression, xDir)) { + if (ValidationTypes.isAny(expression, yDir)) { + result = true; + ValidationTypes.isAny(expression, numeric); + } else if (ValidationTypes.isAny(expression, numeric)) { + if (ValidationTypes.isAny(expression, yDir)) { result = true; - ValidationTypes.isAny(expression, numeric); - - } else if (ValidationTypes.isAny(expression, numeric)){ - - //could also be two-part, so check the next part - if (ValidationTypes.isAny(expression, yDir)){ - ValidationTypes.isAny(expression, numeric); - } - + } else if (ValidationTypes.isAny(expression, "center")) { result = true; } } - } - } - + } else if (ValidationTypes.isAny(expression, yDir)) { + if (ValidationTypes.isAny(expression, xDir)) { + result = true; + ValidationTypes.isAny(expression, numeric); + } else if (ValidationTypes.isAny(expression, numeric)) { + if (ValidationTypes.isAny(expression, xDir)) { + result = true; + ValidationTypes.isAny(expression, numeric); + } else if (ValidationTypes.isAny(expression, "center")) { + result = true; + } + } + } else if (ValidationTypes.isAny(expression, "center")) { + if (ValidationTypes.isAny(expression, xDir + " | " + yDir)) { + result = true; + ValidationTypes.isAny(expression, numeric); + } + } + } return result; }, @@ -339,4 +353,4 @@ var ValidationTypes = { return result; } } -}; \ No newline at end of file +}; diff --git a/tests/css/Validation.js b/tests/css/Validation.js index 9806cb49..8774bd28 100644 --- a/tests/css/Validation.js +++ b/tests/css/Validation.js @@ -153,23 +153,28 @@ "top", "bottom", "center", + "100%", "left center", + "bottom left", "left 10px", "center bottom", "10% top", "left 10px bottom", "right top 5%", - "center 3em center 10%", + "top 3em center", + "center top 3em", + "top 3em right 10%", "top, bottom", "left 10px, left 10px", "right top 5%, left 10px bottom" ], invalid: { - "foo" : "Expected () but found 'foo'.", - "left center right" : "Expected end of value but found 'right'." - - } + "foo" : "Expected () but found 'foo'.", + "10% left" : "Expected end of value but found 'left'.", + "left center right" : "Expected end of value but found 'center'.", + "center 3em right 10%": "Expected end of value but found '3em'.", + } })); suite.add(new ValidationTestCase({