From 223a014949499bb928c7295c0a51b47412e237e0 Mon Sep 17 00:00:00 2001 From: Fabrice Gangler Date: Thu, 8 Jun 2017 21:43:59 +0200 Subject: [PATCH] #57 Javascript: allowed colors by CSS name in isValidateColor() --- .../src/main/webapp/Js/36-sample.color.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/contrast-finder-webapp/src/main/webapp/Js/36-sample.color.js b/contrast-finder-webapp/src/main/webapp/Js/36-sample.color.js index 13d7a0b3..3e173536 100644 --- a/contrast-finder-webapp/src/main/webapp/Js/36-sample.color.js +++ b/contrast-finder-webapp/src/main/webapp/Js/36-sample.color.js @@ -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; } @@ -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" } }