Permalink
Browse files

MDL-23504 Theme: Extended support of colors in color picker

  • Loading branch information...
1 parent 0395306 commit e46fce762a963f95efd4ccad23439e63d5ed203c Danny Wahl committed with Rajesh Taneja Dec 4, 2012
Showing with 52 additions and 2 deletions.
  1. +52 −2 lib/adminlib.php
View
@@ -7936,12 +7936,62 @@ public function write_setting($data) {
* @return string|false
*/
protected function validate($data) {
- if (preg_match('/^#?([a-fA-F0-9]{3}){1,2}$/', $data)) {
+
+ /**
+ * List of valid HTML colour names
+ *
+ * @var array
+ */
+ $colornames = array(
+ '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'
+ );
+
+ if (preg_match('/^#?([[:xdigit:]]{3}){1,2}$/', $data)) {
if (strpos($data, '#')!==0) {
$data = '#'.$data;
}
return $data;
- } else if (preg_match('/^[a-zA-Z]{3, 25}$/', $data)) {
+ } else if (in_array(strtolower($data), $colornames)) {
+ return $data;
+ } else if (preg_match('/rgb\(\d{0,3}%?\, ?\d{0,3}%?, ?\d{0,3}%?\)/i', $data)) {
+ return $data;
+ } else if (preg_match('/rgba\(\d{0,3}%?\, ?\d{0,3}%?, ?\d{0,3}%?\, ?\d(\.\d)?\)/i', $data)) {
+ return $data;
+ } else if (preg_match('/hsl\(\d{0,3}\, ?\d{0,3}%, ?\d{0,3}%\)/i', $data)) {
+ return $data;
+ } else if (preg_match('/hsla\(\d{0,3}\, ?\d{0,3}%,\d{0,3}%\, ?\d(\.\d)?\)/i', $data)) {
+ return $data;
+ } else if (($data == 'transparent') || ($data == 'currentColor') || ($data == 'inherit')) {
return $data;
} else if (empty($data)) {
return $this->defaultsetting;

0 comments on commit e46fce7

Please sign in to comment.