Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Fix axs.utils.isLargeFont float issue (#345) #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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/js/AccessibilityUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,15 @@ axs.utils.elementIsVisible = function(element) {
axs.utils.isLargeFont = function(style) {
var fontSize = style.fontSize;
var bold = style.fontWeight == 'bold';
var matches = fontSize.match(/(\d+)px/);
var matches = fontSize.match(/(\d+(\.\d+)?)px/);

if (matches) {
var fontSizePx = parseInt(matches[1], 10);
var fontSizePx = parseFloat(matches[1]);
var bodyStyle = window.getComputedStyle(document.body, null);
var bodyFontSize = bodyStyle.fontSize;
matches = bodyFontSize.match(/(\d+)px/);
matches = bodyFontSize.match(/(\d+(\.\d+)?)px/);
if (matches) {
var bodyFontSizePx = parseInt(matches[1], 10);
var bodyFontSizePx = parseFloat(matches[1]);
var boldLarge = bodyFontSizePx * 1.2;
var large = bodyFontSizePx * 1.5;
} else {
Expand All @@ -298,23 +299,23 @@ axs.utils.isLargeFont = function(style) {
}
return (bold && fontSizePx >= boldLarge || fontSizePx >= large);
}
matches = fontSize.match(/(\d+)em/);
matches = fontSize.match(/(\d+(\.\d+)?)em/);
if (matches) {
var fontSizeEm = parseInt(matches[1], 10);
var fontSizeEm = parseFloat(matches[1]);
if (bold && fontSizeEm >= 1.2 || fontSizeEm >= 1.5)
return true;
return false;
}
matches = fontSize.match(/(\d+)%/);
matches = fontSize.match(/(\d+(\.\d+)?)%/);
if (matches) {
var fontSizePercent = parseInt(matches[1], 10);
var fontSizePercent = parseFloat(matches[1]);
if (bold && fontSizePercent >= 120 || fontSizePercent >= 150)
return true;
return false;
}
matches = fontSize.match(/(\d+)pt/);
matches = fontSize.match(/(\d+(\.\d+)?)pt/);
if (matches) {
var fontSizePt = parseInt(matches[1], 10);
var fontSizePt = parseFloat(matches[1]);
if (bold && fontSizePt >= 14 || fontSizePt >= 18)
return true;
return false;
Expand Down