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

All Examples: Add browser and AT support notice #1404

Merged
merged 14 commits into from
Jun 30, 2020
55 changes: 55 additions & 0 deletions examples/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
(function () {
// Load syntax highlighting
hljs.initHighlightingOnLoad();

// Add support notice to all examples
window.addEventListener('DOMContentLoaded', addSupportNotice, false);

function addSupportNotice() {
// The "Example" heading
var headings = document.querySelectorAll('h2');
var exampleHeading = null;
for (var i = 0; i < headings.length; ++i) {
var heading = headings[i];
if (heading.textContent.trim().match(/^Examples?$/)) {
exampleHeading = heading;
break;
}
}
if (!exampleHeading) {
return;
}

// The #browser_and_AT_support link
var supportLink = document.querySelector('a[href$="#browser_and_AT_support"]');
if (!supportLink) {
return;
}

// Get the right relative URL to the root aria-practices page
var urlPrefix = supportLink.getAttribute('href').split('#')[0];

// Expected outcome '../js/app.js' OR '../../js/app.js'
var scriptSource = document.querySelector('[src$="app.js"]').getAttribute('src');
// Replace 'app.js' part with 'notice.html'
var fetchSource = scriptSource.replace('app.js', 'notice.html');

fetch(fetchSource)
.then(function(response) {
// Return notice.html as text
return response.text();
})
.then(function(html) {
// Parse response as text/html
var parser = new DOMParser();
return parser.parseFromString(html, "text/html");
})
.then(function(doc) {
// Get the details element from the parsed response
var noticeElement = doc.querySelector('details');
// Rewrite links with the right urlPrefix
var links = doc.querySelectorAll('a[href^="/#"]');
for (var i = 0; i < links.length; ++i) {
links[i].pathname = urlPrefix;
}
// Insert the support notice after the page's example heading
exampleHeading.parentNode.insertBefore(noticeElement, exampleHeading.nextSibling);
})
}
}());
28 changes: 28 additions & 0 deletions examples/js/notice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>support notice (template)</title>
<details id="support-notice" class="note">
<summary>Important Note About Use of This Example</summary>
<p>
Note: This is an illustrative example of one way of using ARIA that conforms with the ARIA specification.
</p>
<ul>
<li>
There may be support gaps in some
<a href="/#browser_and_AT_support">browser and assistive technology combinations</a>,
especially for <a href="/#mobile_and_touch_support">mobile/touch devices</a>.
Testing code based on this example with assistive technologies is essential before considering use in production systems.
</li>
<li>
The <a href="https://github.com/w3c/aria-at/">ARIA-AT project</a>
plans to provide measurements of this example's assistive technology support by the end of 2020.
</li>
<li>
Robust accessibility can be further optimized by choosing implementation patterns that
<a href="https://www.w3.org/TR/using-aria/#rule1">maximize use of semantic HTML</a>
and heeding the warning that
<a href="/#no_aria_better_bad_aria">No ARIA is better than Bad ARIA</a>.
</li>
</ul>
</details>