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

New AccessKit feature: Alt text reminder #783

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/features/accesskit.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
{ "value": "hide", "label": "Only show image descriptions" }
],
"default": "show"
},
"alt_text_reminder": {
"type": "checkbox",
"label": "Remind me to add alt text to images",
"default": false
}
}
}
45 changes: 45 additions & 0 deletions src/features/accesskit/alt_text_reminder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { keyToCss } from '../../utils/css_map.js';
import { buildStyle } from '../../utils/interface.js';
import { translate } from '../../utils/language_data.js';
import { pageModifications } from '../../utils/mutations.js';

const missingAltTextBlock = `figure:has(img[alt="${translate('Image')}"], img[alt="${translate('Image').toLowerCase()}"])`;

const styleElement = buildStyle(`
${missingAltTextBlock} ${keyToCss('optionsIcon')} {
outline: 3px dashed rgb(var(--accent));
outline-offset: -1px;
}

${missingAltTextBlock}:hover ${keyToCss('images')} > div::after {
position: absolute;
bottom: 5px;
right: 0px;

padding: 23px 46px 23px 12px;
border-radius: 23px;

background-color: rgba(var(--black));
color: rgb(var(--white));

content: "Add a description! ->";
font-size: var(--base-font-size);
font-weight: 500;
line-height: 0;
}

${missingAltTextBlock} ${keyToCss('optionsWrapper')} {
display: unset !important;
}
`);

const processEditors = ([editor]) => editor.prepend(styleElement);

export const main = async () => {
pageModifications.register('.block-editor-writing-flow', processEditors);
};

export const clean = async () => {
pageModifications.unregister(processEditors);
styleElement.remove();
};