Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transparent background as condition for inheritance #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/Rule/BaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,17 @@ public function getStyle($element) {
$style = $this->walkUpTreeForInheritance($element, $style);
}

if($element->hasAttribute('style')) {
$inline_styles = explode(';', $element->getAttribute('style'));
foreach($inline_styles as $inline_style) {
$s = explode(':', $inline_style);
// if($element->hasAttribute('style')) {
// $inline_styles = explode(';', $element->getAttribute('style'));
// foreach($inline_styles as $inline_style) {
// $s = explode(':', $inline_style);

// if(isset($s[1])){ // Edit: Make sure the style attribute doesn't have a trailing ;
// $style[trim($s[0])] = trim(strtolower($s[1]));
// }
// }
// }

if(isset($s[1])){ // Edit: Make sure the style attribute doesn't have a trailing ;
$style[trim($s[0])] = trim(strtolower($s[1]));
}
}
}
if($element->tagName === "strong"){
$style['font-weight'] = "bold";
}
Expand Down Expand Up @@ -201,7 +202,7 @@ private function walkUpTreeForInheritance($element, $style) {
$style[$k] = $v;
}

if((!isset($style['background-color'])) || strtolower($style['background-color']) == strtolower("#FFFFFF")){
if((!isset($style['background-color'])) || strtolower($style['background-color']) == strtolower("#FFFFFF") || strtolower($style['background-color']) == strtolower("transparent")){
if($k == 'background-color'){
$style['background-color'] = $v;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Rule/CssTextHasContrast.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public function check()
$style = $this->getStyle($element);
}

if(strtolower($style['background-color']) == strtolower("transparent")) {
$style['background-color'] = $default_background;
}

// 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
if (!isset($style['color']) && $this->childrenHaveTextColor($element)) {
Expand Down