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
56 changes: 56 additions & 0 deletions examples/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,60 @@
(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 foundExampleHeading;
for (var i = 0; i < headings.length; ++i) {
if (headings[i].textContent.trim().match(/^Examples?$/)) {
foundExampleHeading = true;
break;
}
}
if (!foundExampleHeading) {
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('https://raw.githack.com/w3c/aria-practices/1228-support-notice/examples/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 before the page's h1
var heading = document.querySelector('h1');
heading.parentNode.insertBefore(noticeElement, heading.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>