Skip to content

Commit 0cdcde0

Browse files
committed
rewrites dialog popup and summary sections
1 parent 0b84d57 commit 0cdcde0

File tree

3 files changed

+119
-21
lines changed

3 files changed

+119
-21
lines changed

index.html

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,30 @@ <h1>Accessibility Report</h1>
2323
<p>Created by Mark Conroy & Big Blue Door</p>
2424
</footer>
2525
<dialog class="dialog-violations">
26-
<button class="dialog-close">Close</button>
27-
<h2 class="dialog-violations__title"></h2>
28-
<ol class="dialog-violations__list"></ol>
26+
<button class="dialog-violations__close">Close</button>
27+
<div class="dialog-violations__title">
28+
29+
<h2>2 Landmark Unique Violations</h2>
30+
<p>URL: <a href="https://www.cnn.com/">https://www.cnn.com/</a></p>
31+
32+
</div>
33+
<ol class="dialog-violations__list">
34+
<li>
35+
<ul>
36+
<li><strong>HTML:</strong> <code>&lt;nav data-uri="cms.cnn.com/_components/header/instances/cnn-v2@published" id="pageHeader" data-editable="settings" class="header cnn-app-display-none" data-analytics-aggregate-events="true"&gt;</code></li>
37+
<li><strong>Target:</strong> #pageHeader</li>
38+
<li><strong>Summary:</strong> Fix any of the following:
39+
The landmark must have a unique aria-label, aria-labelledby, or title to make landmarks distinguishable</li>
40+
</ul>
41+
</li><li>
42+
<ul>
43+
<li><strong>HTML:</strong> <code>&lt;nav class="user-account-nav user-account-nav--unauth" data-uri="cms.cnn.com/_components/user-account-nav/instances/user-account-nav@published" data-editable="settings" data-one-tap-enabled="false" data-one-tap-enabled-mw="false" aria-label="User Account Nav" data-avatar-enabled="false" tabindex="0" style="visibility: visible;"&gt;</code></li>
44+
<li><strong>Target:</strong> #desktop-header-account-nav &gt; .user-account-nav.user-account-nav--unauth[data-one-tap-enabled="false"]</li>
45+
<li><strong>Summary:</strong> Fix any of the following:
46+
The landmark must have a unique aria-label, aria-labelledby, or title to make landmarks distinguishable</li>
47+
</ul>
48+
</li>
49+
</ol>
2950
</dialog>
3051
<script src="public/script.js"></script>
3152
</body>

public/script.js

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const app = document.querySelector('#app');
2-
const violations = fetch('violations.json').then(response => response.json());
2+
const dialog = document.querySelector('.dialog-violations');
3+
const dialogViolationsList = dialog.querySelector('.dialog-violations__list');
4+
const dialogViolationsTitle = dialog.querySelector('.dialog-violations__title');
5+
36
// Helper function to convert to sentence case
47
const toSentenceCase = (string) => {
58
return string
@@ -8,6 +11,7 @@ const toSentenceCase = (string) => {
811
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
912
.join(' ');
1013
};
14+
1115
const replaceHyphensWithSpaces = (string) => string.replace(/-/g, ' ');
1216

1317
// Helper function to escape HTML
@@ -20,12 +24,12 @@ const escapeHtml = (unsafe) => {
2024
.replace(/'/g, "&#039;");
2125
};
2226

23-
const dialog = document.querySelector('.dialog-violations');
24-
const violationsList = dialog.querySelector('.dialog-violations__list');
27+
const violations = fetch('violations.json').then(response => response.json());
2528

2629
violations.then(data => {
2730
const numberOfURLsTested = data.numberOfURLsTested;
2831
const allViolations = data.violations;
32+
const numberOfViolations = allViolations.length;
2933

3034
// Group violations by type
3135
const violationsByType = allViolations.reduce((acc, violation) => {
@@ -43,36 +47,63 @@ violations.then(data => {
4347
return acc;
4448
}, {});
4549

46-
// Count the number of nodes in color-contrast violations
47-
// const numberOfColorContrastNodes = violationVariables['color-contrast'].reduce((acc, violation) => acc + violation.nodes.length, 0);
48-
4950
// Get unique URLs with violations
5051
const uniqueURLsWithViolations = [...new Set(allViolations.map(violation => violation.url))];
5152

53+
// Count the number of issues for each impact level
54+
const impactCounts = allViolations.reduce((acc, violation) => {
55+
const impact = violation.impact || 'unknown';
56+
if (!acc[impact]) {
57+
acc[impact] = 0;
58+
}
59+
acc[impact] += 1;
60+
return acc;
61+
}, {});
62+
63+
// Set the content of the app element
5264
app.innerHTML = `
5365
<h2 id="summary">Summary</h2>
5466
<h3>URLs with violations</h3>
5567
<p>We tested <strong>${numberOfURLsTested} URLs</strong> and found <strong>${uniqueURLsWithViolations.length} URLs</strong> with accessibility violations <strong>(${(uniqueURLsWithViolations.length / numberOfURLsTested * 100).toFixed(2)}%</strong> of URLs).</p>
68+
<p>The total number of violations found was <strong>${numberOfViolations}</strong></p>
69+
70+
<h3>Issues by Impact</h3>
71+
<ul>
72+
${Object.entries(impactCounts).map(([impact, count]) => `
73+
<li>${toSentenceCase(impact)}: ${count}</li>
74+
`).join('')}
75+
</ul>
76+
77+
<h3>Issues by Type</h3>
78+
<ul>
79+
${violationTypes.map(type => `
80+
<li>
81+
${violationVariables[type].length} ${replaceHyphensWithSpaces(toSentenceCase(type))}
82+
</li>
83+
`).join('')}
84+
</ul>
85+
5686
<ul>
5787
${uniqueURLsWithViolations.map(url => `
5888
<li>
5989
<a href="${url}">${url}</a>
6090
</li>
6191
`).join('')}
6292
</ul>
93+
6394
<h2 id="violations">Accessibility Violations</h2>
64-
<div class="grid grid--2">
95+
<div class="grid">
6596
${violationTypes.map(type => `
6697
<article class="violations">
6798
<h3>${toSentenceCase(replaceHyphensWithSpaces(type))}</h3>
6899
<p>There are <strong>${violationVariables[type].length} ${type} violations</strong> across <strong>${uniqueURLsWithViolations.length} URLs</strong>.</p>
100+
<p>Impact: <span class="impact impact--${violationVariables[type][0]['impact']}">${toSentenceCase(violationVariables[type][0]['impact'])}</span></p>
101+
<p>Description: ${violationVariables[type][0]['description']}</p>
69102
<ol class="violations__list">
70103
${violationVariables[type].map((violation, index) => `
71104
<li>
72105
<a href="${violation.url}">${violation.url}</a>
73106
<ul>
74-
<li>Description: ${violation.description}</li>
75-
<li>Impact: <span class="impact impact--${violation.impact}">${toSentenceCase(violation.impact)}</span></li>
76107
<li>Instances: ${violation.nodes.length} - <button data-index="${index}" data-type="${type}" class="view-violations" type="button">View All</button></li>
77108
</ul>
78109
</li>
@@ -89,26 +120,34 @@ violations.then(data => {
89120
const type = event.target.getAttribute('data-type');
90121
const index = event.target.getAttribute('data-index');
91122
const violation = violationVariables[type][index];
92-
violationsList.innerHTML = '';
123+
const numberOfInstances = violation.nodes.length;
124+
const violationSummary = violation.nodes[0]['failureSummary'];
125+
dialogViolationsList.innerHTML = '';
126+
dialogViolationsTitle.innerHTML = '';
127+
128+
dialogViolationsTitle.innerHTML = `
129+
<h2>${numberOfInstances} ${toSentenceCase(replaceHyphensWithSpaces(type))} Violations</h2>
130+
<p>URL: <a href="${violation.url}">${violation.url}</a></p>
131+
<p>Summary: ${violationSummary}</p>
132+
`;
93133

94134
violation.nodes.forEach(node => {
95-
console.log(node);
96135
const listItem = document.createElement('li');
97136
listItem.innerHTML = `
98-
<p><strong>HTML:</strong></p>
99-
<code>${escapeHtml(node.html)}</code>
100-
<p><strong>Target:</strong> ${node.target.join(' > ')}</p>
101-
<p><strong>Summary:</strong> ${node.failureSummary}</p>
137+
<ul>
138+
<li><strong>HTML:</strong> <code>${escapeHtml(node.html)}</code></li>
139+
<li><strong>Target:</strong> ${node.target.join(' > ')}</li>
140+
</ul>
102141
`;
103-
violationsList.appendChild(listItem);
142+
dialogViolationsList.appendChild(listItem);
104143
});
105144

106145
dialog.showModal();
107146
});
108147
});
109148

110149
// Event listener for the close dialog button
111-
dialog.querySelector('.dialog-close').addEventListener('click', () => {
150+
dialog.querySelector('.dialog-violations__close').addEventListener('click', () => {
112151
document.querySelector('.dialog-violations').close();
113152
});
114153

public/style.css

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ h2 ~ h2 {
7575
background-color: #d4cd00;
7676
}
7777
.impact--serious {
78-
background-color: #c86e00;
78+
background-color: #b36200;
7979
color: var(--color-white);
8080
}
8181
.impact--critical {
@@ -88,6 +88,44 @@ dialog::backdrop {
8888
opacity: 0.9;
8989
}
9090

91+
dialog {
92+
width: 90%;
93+
height: 90%;
94+
max-width: 900px;
95+
max-height: 600px;
96+
padding: 2rem;
97+
background-color: var(--color-white);
98+
border: var(--border);
99+
}
100+
101+
.dialog-violations__close {
102+
display: block;
103+
margin-inline-start: auto;
104+
}
105+
106+
.dialog-violations__title {
107+
margin-block-start: 2rem;
108+
padding-block-start: 1rem;
109+
border-block-start: var(--border);
110+
}
111+
112+
.dialog-violations__list {
113+
padding-block-start: 2rem;
114+
margin-block-start: 2rem;
115+
border-block-start: var(--border);
116+
}
117+
118+
.dialog-violations__list > li {
119+
margin-block-end: 2rem;
120+
padding-block-end: 2rem;
121+
border-bottom: var(--border);
122+
}
123+
124+
.dialog-violations__list > li li {
125+
list-style-type: disc;
126+
margin-block-start: 0.5rem;
127+
}
128+
91129
button {
92130
padding: 0.25rem 0.5rem;
93131
background-color: var(--color-primary);

0 commit comments

Comments
 (0)