Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

accessibility.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const axsPath = require.resolve('../vendor/axs_testing');
  2. exports.addCommand = function (client, requireName) {
  3. client.addCommand('auditAccessibility', function (options) {
  4. return this.execute(
  5. function (axsPath, requireName, options) {
  6. options = options || {};
  7. const ignoreWarnings = options.ignoreWarnings || false;
  8. const ignoreRules = Array.isArray(options.ignoreRules)
  9. ? options.ignoreRules
  10. : [];
  11. const axs = window[requireName](axsPath);
  12. const audit = axs.Audit.run(
  13. new axs.AuditConfiguration({
  14. showUnsupportedRulesWarning: false
  15. })
  16. );
  17. let failures = audit.filter(function (result) {
  18. return result.result === 'FAIL';
  19. });
  20. if (ignoreWarnings) {
  21. failures = failures.filter(function (result) {
  22. return result.rule.severity !== 'Warning';
  23. });
  24. }
  25. failures = failures.filter(function (result) {
  26. return ignoreRules.indexOf(result.rule.code) === -1;
  27. });
  28. if (failures.length > 0) {
  29. let message = 'Accessibilty audit failed\n\n';
  30. message += failures
  31. .map(function (result) {
  32. return axs.Audit.accessibilityErrorMessage(result);
  33. })
  34. .join('\n\n');
  35. return {
  36. message: message,
  37. failed: true,
  38. results: failures.map(function (result) {
  39. return {
  40. code: result.rule.code,
  41. elements: result.elements.map(function (element) {
  42. return axs.utils.getQuerySelectorText(element);
  43. }),
  44. message: result.rule.heading,
  45. severity: result.rule.severity,
  46. url: result.rule.url
  47. };
  48. })
  49. };
  50. } else {
  51. return {
  52. message: 'Accessibilty audit passed',
  53. results: [],
  54. failed: false
  55. };
  56. }
  57. },
  58. axsPath,
  59. requireName,
  60. options
  61. ).then(function (response) {
  62. return response;
  63. });
  64. });
  65. };