var cssFunctionAnyRegexStr = '(' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
var cssUnitAnyRegexStr = '(none|' + widthKeywords.join('|') + '|' + cssUnitRegexStr + '|' + cssVariableRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')';
+ var cssFunctionNoVendorRegex = new RegExp('^' + cssFunctionNoVendorRegexStr + '$', 'i');
+ var cssFunctionVendorRegex = new RegExp('^' + cssFunctionVendorRegexStr + '$', 'i');
+ var cssVariableRegex = new RegExp('^' + cssVariableRegexStr + '$', 'i');
+ var cssFunctionAnyRegex = new RegExp('^' + cssFunctionAnyRegexStr + '$', 'i');
+ var cssUnitRegex = new RegExp('^' + cssUnitRegexStr + '$', 'i');
+ var cssUnitAnyRegex = new RegExp('^' + cssUnitAnyRegexStr + '$', 'i');
+
var backgroundRepeatKeywords = ['repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'inherit'];
var backgroundAttachmentKeywords = ['inherit', 'scroll', 'fixed', 'local'];
var backgroundPositionKeywords = ['center', 'top', 'bottom', 'left', 'right'];
return s !== 'auto' && (s === 'transparent' || s === 'inherit' || /^[a-zA-Z]+$/.test(s));
},
isValidVariable: function(s) {
- return new RegExp('^' + cssVariableRegexStr + '$', 'gi').test(s);
+ return cssVariableRegex.test(s);
},
isValidColor: function (s) {
return validator.isValidNamedColor(s) || validator.isValidHexColor(s) || validator.isValidRgbaColor(s) || validator.isValidHslaColor(s) || validator.isValidVariable(s);
return s.indexOf('__ESCAPED_URL_CLEAN_CSS') === 0;
},
isValidUnit: function (s) {
- return new RegExp('^' + cssUnitAnyRegexStr + '$', 'gi').test(s);
+ return cssUnitAnyRegex.test(s);
},
isValidUnitWithoutFunction: function (s) {
- return new RegExp('^' + cssUnitRegexStr + '$', 'gi').test(s);
+ return cssUnitRegex.test(s);
},
isValidFunctionWithoutVendorPrefix: function (s) {
- return new RegExp('^' + cssFunctionNoVendorRegexStr + '$', 'gi').test(s);
+ return cssFunctionNoVendorRegex.test(s);
},
isValidFunctionWithVendorPrefix: function (s) {
- return new RegExp('^' + cssFunctionVendorRegexStr + '$', 'gi').test(s);
+ return cssFunctionVendorRegex.test(s);
},
isValidFunction: function (s) {
- return new RegExp('^' + cssFunctionAnyRegexStr + '$', 'gi').test(s);
+ return cssFunctionAnyRegex.test(s);
},
isValidBackgroundRepeat: function (s) {
return backgroundRepeatKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
if (backgroundPositionKeywords.indexOf(s) >= 0)
return true;
- return new RegExp('^' + cssUnitRegexStr + '$', 'gi').test(s) || validator.isValidVariable(s);
+ return cssUnitRegex.test(s) || validator.isValidVariable(s);
},
isValidBackgroundPosition: function (s) {
if (s === 'inherit')
return true;
- return s.split(' ').filter(function (p) {
- return p !== '';
- }).every(function(p) {
- return validator.isValidBackgroundPositionPart(p) || validator.isValidVariable(s);
- });
+ var parts = s.split(' ');
+ for (var i = 0, l = parts.length; i < l; i++) {
+ if (parts[i] === '')
+ continue;
+ if (validator.isValidBackgroundPositionPart(parts[i]) || validator.isValidVariable(parts[i]))
+ continue;
+
+ return false;
+ }
+
+ return true;
},
isValidListStyleType: function (s) {
return listStyleTypeKeywords.indexOf(s) >= 0 || validator.isValidVariable(s);
return /^-([A-Za-z0-9]|-)*$/gi.test(s);
},
areSameFunction: function (a, b) {
- if (!validator.isValidFunction(a) || !validator.isValidFunction(b)) {
+ if (!validator.isValidFunction(a) || !validator.isValidFunction(b))
return false;
- }
+
var f1name = a.substring(0, a.indexOf('('));
var f2name = b.substring(0, b.indexOf('('));
}
};
- validator.cssUnitRegexStr = cssUnitRegexStr;
- validator.cssFunctionNoVendorRegexStr = cssFunctionNoVendorRegexStr;
- validator.cssFunctionVendorRegexStr = cssFunctionVendorRegexStr;
- validator.cssFunctionAnyRegexStr = cssFunctionAnyRegexStr;
-
return validator;
})();