Skip to content

Commit

Permalink
Asqatasun#57 Javascript: allowed colors by CSS name in isValidateColor()
Browse files Browse the repository at this point in the history
  • Loading branch information
dzc34 committed Jun 8, 2017
1 parent 7ffcccf commit 223a014
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions contrast-finder-webapp/src/main/webapp/Js/36-sample.color.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function changeColorSample(colorPrefix) {
}

function isValidateColor(str) {
str = str.trim();
if(str.match(/^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/) !== null){
return str;
}
Expand All @@ -48,6 +49,20 @@ function isValidateColor(str) {
return str;
}
else {
// source: https://gist.github.com/bobspace/2712980
var CssColorNames = ["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue","BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","Darkorange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray","Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow","LightGray","LightGrey","LightGreen","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGray","LightSlateGrey","LightSteelBlue","LightYellow","Lime","LimeGreen","Linen","Magenta","Maroon","MediumAquaMarine","MediumBlue","MediumOrchid","MediumPurple","MediumSeaGreen","MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed","MidnightBlue","MintCream","MistyRose","Moccasin","NavajoWhite","Navy","OldLace","Olive","OliveDrab","Orange","OrangeRed","Orchid","PaleGoldenRod","PaleGreen","PaleTurquoise","PaleVioletRed","PapayaWhip","PeachPuff","Peru","Pink","Plum","PowderBlue","Purple","Red","RosyBrown","RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","SeaShell","Sienna","Silver","SkyBlue","SlateBlue","SlateGray","SlateGrey","Snow","SpringGreen","SteelBlue","Tan","Teal","Thistle","Tomato","Turquoise","Violet","Wheat","White",
"WhiteSmoke","Yellow","YellowGreen"];
var query = str.toLowerCase();
var colorName = "";
CssColorNames.some(function(element, i) {
if (query === element.toLowerCase()) {
colorName = element;
return true;
}
});
if(colorName !== ""){
return colorName;
}
return "false"
}
}
Expand Down

0 comments on commit 223a014

Please sign in to comment.