Skip to content

Commit

Permalink
feat(rules): Allow DPUB ARIA roles
Browse files Browse the repository at this point in the history
Closes #65
  • Loading branch information
rdeltour committed Oct 25, 2017
1 parent 5dfdd98 commit c4faabc
Show file tree
Hide file tree
Showing 10 changed files with 477 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/checker/checker-nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ if (!fs.existsSync(PATH_TO_H5O)) {
throw new Error('Can’t find h5o');
}

const PATH_TO_AXE_PATCH = path.join(__dirname, '../scripts/axe-patch.js');
if (!fs.existsSync(PATH_TO_AXE_PATCH)) {
winston.verbose(PATH_TO_AXE_PATCH);
throw new Error('Can’t find axe-patch script');
const PATH_TO_AXE_PATCH_GETSELECTOR = path.join(__dirname, '../scripts/axe-patch-getselector.js');
if (!fs.existsSync(PATH_TO_AXE_PATCH_GETSELECTOR)) {
winston.verbose(PATH_TO_AXE_PATCH_GETSELECTOR);
throw new Error('Can’t find axe-patch-getselector script');
}

const PATH_TO_AXE_PATCH_ARIALOOKUPTABLE = path.join(__dirname, '../scripts/axe-patch-arialookuptable.js');
if (!fs.existsSync(PATH_TO_AXE_PATCH_ARIALOOKUPTABLE)) {
winston.verbose(PATH_TO_AXE_PATCH_ARIALOOKUPTABLE);
throw new Error('Can’t find axe-patch-arialookuptable script');
}

const PATH_TO_ACE_AXE = path.join(__dirname, '../scripts/ace-axe.js');
Expand Down Expand Up @@ -54,8 +60,9 @@ function checkSingle(spineItem, epub, nightmare) {
return nightmare
.goto(spineItem.url)
.inject('js', PATH_TO_AXE)
.inject('js', PATH_TO_AXE_PATCH_GETSELECTOR)
.inject('js', PATH_TO_AXE_PATCH_ARIALOOKUPTABLE)
.inject('js', PATH_TO_H5O)
.inject('js', PATH_TO_AXE_PATCH)
.inject('js', PATH_TO_ACE_AXE)
.inject('js', PATH_TO_ACE_EXTRACTION)
.wait(50)
Expand Down
360 changes: 360 additions & 0 deletions src/scripts/axe-patch-arialookuptable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
'use strict';

(function axePatch(window) {
const axe = window.axe;
const dpubRoles = {
'doc-abstract': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author'],
context: null,
},
'doc-acknowledgments': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author'],
context: null,
},
'doc-afterword': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author'],
context: null,
},
'doc-appendix': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author'],
context: null,
},
'doc-backlink': {
type: 'link',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author', 'contents'],
context: null,
},
'doc-biblioentry': {
type: 'listitem',
attributes: {
allowed: ['aria-expanded', 'aria-level', 'aria-posinset', 'aria-setsize'],
},
owned: null,
nameFrom: ['author'],
context: ['doc-bibliography'],
},
'doc-bibliography': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author'],
context: null,
},
'doc-biblioref': {
type: 'link',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
nameFrom: ['author', 'contents'],
context: null,
},
'doc-chapter': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-colophon': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-conclusion': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-cover': {
type: 'img',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-credit': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-credits': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-dedication': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-endnote': {
type: 'listitem',
attributes: {
allowed: ['aria-expanded', 'aria-level', 'aria-posinset', 'aria-setsize'],
},
owned: null,
namefrom: ['author'],
context: ['doc-endnotes'],
},
'doc-endnotes': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: ['doc-endnote'],
namefrom: ['author'],
context: null,
},
'doc-epigraph': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-epilogue': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-errata': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-example': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-footnote': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-foreword': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-glossary': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: ['term', 'definition'],
namefrom: ['author'],
context: null,
},
'doc-glossref': {
type: 'link',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author', 'contents'],
context: null,
},
'doc-index': {
type: 'navigation',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-introduction': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-noteref': {
type: 'link',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author', 'contents'],
context: null,
},
'doc-notice': {
type: 'note',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-pagebreak': {
type: 'separator',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-pagelist': {
type: 'navigation',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-part': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-preface': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-prologue': {
type: 'landmark',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-pullquote': {
type: 'none',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-qna': {
type: 'section',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-subtitle': {
type: 'sectionhead',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-tip': {
type: 'note',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
'doc-toc': {
type: 'navigation',
attributes: {
allowed: ['aria-expanded'],
},
owned: null,
namefrom: ['author'],
context: null,
},
};

Object.assign(axe.commons.aria._lut.role, dpubRoles);
}(window));
File renamed without changes.
Loading

0 comments on commit c4faabc

Please sign in to comment.