Skip to content

Commit

Permalink
Merge pull request cidilabs#52 from cidilabs/scottcooper/UDOIT3-836-n…
Browse files Browse the repository at this point in the history
…ested-color-styles

Make CssTextHasContrast look for children with styles
  • Loading branch information
cidilabs authored Feb 27, 2023
2 parents ebf7253 + 4ab184e commit 5a8657a
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Rule/CssTextHasContrast.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ public function check()
$default_color = $options['textColor'];

foreach ($entries as $element) {
$style = $this->getStyle($element);
$childNodeWithStyle = $this->GetChildWithStyle($element);
if($childNodeWithStyle){
$style = $this->getStyle($childNodeWithStyle);
}else {
$style = $this->getStyle($element);
}

// If the parent element doesn't have a text color, but one of the children does
// then we won't assume the parent is using the LMS default
Expand Down Expand Up @@ -319,6 +324,32 @@ public function parseCSS($css) {

return $results;
}

public function GetChildWithStyle($element) {
if ($element->hasChildNodes()){
$children = $element->childNodes;
foreach ($children as $child) {
// Check if its a DOM element
if ($child->nodeType !== 1 ) { //Element nodes are of nodeType 1. Text 3. Comments 8. etc rtm
continue;
}

$child_style = $this->getNodeStyle($child);

if(is_array($child_style)) {
if (isset($child_style['color'])){
return $child;
}
}

if($child->hasChildNodes()){
return $this->GetChildWithStyle($child);
}
}

return [];
}
}

/**
* Converts multiple color or background styles into a simple hex string
Expand Down

0 comments on commit 5a8657a

Please sign in to comment.