-
Notifications
You must be signed in to change notification settings - Fork 750
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
refactor: commons.color.getBackgroundColor method #1451
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ebd505
refactor: get backgground color function
jeeyyy a9ae29c
test: getCoordinatesFromRect
jeeyyy 1fe5a34
test: add tests for common color utility fns
jeeyyy 07cf21a
test: fix test
jeeyyy c133b91
test: update test
jeeyyy b6afc5e
refactor: update color fns and tests
jeeyyy be2e5dc
merge from develop
jeeyyy 03088ae
test: debugging
jeeyyy ca74b83
test: add more logging
jeeyyy 6916858
fix: wrap mocha anchors
jeeyyy 353451e
revert debugging
jeeyyy ca51192
refactor: rename fn and update comment
jeeyyy d0bd4af
update based on reviews
jeeyyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* global color */ | ||
|
||
/** | ||
* Get coordinates for an element's client rects or bounding client rect | ||
* | ||
* @method centerPointOfRect | ||
* @memberof axe.commons.color | ||
* @param {DOMRect} rect | ||
* @returns {Object | undefined} | ||
*/ | ||
color.centerPointOfRect = function centerPointOfRect(rect) { | ||
if (rect.left > window.innerWidth) { | ||
return undefined; | ||
} | ||
|
||
if (rect.top > window.innerHeight) { | ||
return undefined; | ||
} | ||
|
||
const x = Math.min( | ||
Math.ceil(rect.left + rect.width / 2), | ||
window.innerWidth - 1 | ||
); | ||
const y = Math.min( | ||
Math.ceil(rect.top + rect.height / 2), | ||
window.innerHeight - 1 | ||
); | ||
|
||
return { x, y }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* global color */ | ||
|
||
/** | ||
* Reports if an element has a background image or gradient | ||
* | ||
* @method elementHasImage | ||
* @memberof axe.commons.color | ||
* @private | ||
* @param {Element} elm | ||
* @param {Object|null} style | ||
* @return {Boolean} | ||
*/ | ||
color.elementHasImage = function elementHasImage(elm, style) { | ||
const graphicNodes = ['IMG', 'CANVAS', 'OBJECT', 'IFRAME', 'VIDEO', 'SVG']; | ||
const nodeName = elm.nodeName.toUpperCase(); | ||
|
||
if (graphicNodes.includes(nodeName)) { | ||
axe.commons.color.incompleteData.set('bgColor', 'imgNode'); | ||
return true; | ||
} | ||
|
||
style = style || window.getComputedStyle(elm); | ||
|
||
const bgImageStyle = style.getPropertyValue('background-image'); | ||
const hasBgImage = bgImageStyle !== 'none'; | ||
|
||
if (hasBgImage) { | ||
const hasGradient = /gradient/.test(bgImageStyle); | ||
axe.commons.color.incompleteData.set( | ||
'bgColor', | ||
hasGradient ? 'bgGradient' : 'bgImage' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing tests for imcompleteData. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
|
||
return hasBgImage; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tests for imcompleteData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See - https://github.com/dequelabs/axe-core/pull/1451/files#diff-e4959c7e9e75633a85787a47a13706b0R24