Skip to content

Commit

Permalink
πŸ› fix(a11y-init.js): fix bug in subsequent tests after clearing results
Browse files Browse the repository at this point in the history
✨ feat(a11y-init.js): encapsulate A11yTester class and improve separation of concerns for greater extensibility
πŸ“ docs(readme.txt): update changelog for version 1.0.9, fix bug in subsequent tests after clearing results
  • Loading branch information
skullzarmy committed Oct 28, 2023
1 parent 37569ee commit 177e45c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
29 changes: 19 additions & 10 deletions a11y-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,31 @@ class A11yTester {
return parser.parseFromString(text, "text/html");
}

executeAxe(iframe, resolve, reject) {
iframe.contentWindow.axe.run((err, results) => {
if (err) {
reject(err);
} else {
this.handleTestResults(results);
document.body.removeChild(iframe);
resolve();
}
});
}

async runAxeTest(docContent) {
const iframe = this.createIframe(docContent);
await this.injectAxeScript(iframe);

return new Promise((resolve, reject) => {
iframe.contentWindow.addEventListener("DOMContentLoaded", () => {
iframe.contentWindow.axe.run((err, results) => {
if (err) {
reject(err);
} else {
this.handleTestResults(results);
document.body.removeChild(iframe);
resolve();
}
if (iframe.contentWindow.document.readyState === "loading") {
iframe.contentWindow.addEventListener("DOMContentLoaded", () => {
this.executeAxe(iframe, resolve, reject);
});
});
} else {
// Document already loaded
this.executeAxe(iframe, resolve, reject);
}
}).catch((err) => {
this.handleError(err);
});
Expand Down
6 changes: 6 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ Initial release, no upgrades required.
= 1.0.8 =
* Refactored a11y-init.js with encapsulating class and better separation of concerns for greater extensibility.

= 1.0.9 =
* Fixed bug in subsequent tests after clearing results

== License ==

This WordPress Plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License or any later version.
Expand All @@ -107,6 +110,9 @@ Contributions, issues, and feature requests are welcome! For support, visit the

== Changelog ==

= 1.0.9 =
* Fixed bug in subsequent tests after clearing results

= 1.0.8 =
* Refactored a11y-init.js with encapsulating class and better separation of concerns for greater extensibility.

Expand Down

0 comments on commit 177e45c

Please sign in to comment.