Skip to content

Commit

Permalink
Merge branch 'accessibility-mode' into profile-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanduke committed Mar 3, 2023
2 parents b301ff8 + 9c99aa7 commit 8d79182
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/content.js
Expand Up @@ -3,6 +3,7 @@
import "./features/register_feature_options";

import "./features/access_keys/access_keys";
import "./features/accessibility/accessibility";
import "./features/agc/agc_content";
import "./features/akaNameLinks/akaNameLinks";
import "./features/appsMenu/appsMenu";
Expand Down
22 changes: 22 additions & 0 deletions src/features/accessibility/accessibility.css
@@ -0,0 +1,22 @@
:root {
--a11y-spacing: 1em;
}

.a11y-list-spacing #toc ~ ol > li,
.a11y-list-spacing #toc ~ ul > li,
.a11y-list-spacing a[name='Biography'] ~ ol > li,
.a11y-list-spacing a[name='Biography'] ~ ul > li {
margin-top: var(--a11y-spacing);
margin-bottom: var(--a11y-spacing);
}

.a11y-src-spacing ol.references > li,
.a11y-src-spacing a[name='Sources'] ~ ol:not(a[name^='Acknowledgement'] ~ ol) > li,
.a11y-src-spacing a[name='Sources'] ~ ul:not(a[name^='Acknowledgement'] ~ ul) > li {
margin-top: var(--a11y-spacing);
margin-bottom: var(--a11y-spacing);
}

.a11y-src-bold .a11y-src-first {
font-weight: bold;
}
94 changes: 94 additions & 0 deletions src/features/accessibility/accessibility.js
@@ -0,0 +1,94 @@
import $ from "jquery";
import { checkIfFeatureEnabled, getFeatureOptions } from "../../core/options/options_storage.js";

async function initAccessibility() {
const options = await getFeatureOptions("accessibility");
if (options.listItemSpacing && options.listItemSpacing > 0) {
document.documentElement.style.setProperty("--a11y-spacing", 1.5 * options.listItemSpacing / 100 + "em"); // this is based on the normal paragraph margin being 1.5em
if (options.spaceSourceItemsOnly) {
$("html").addClass("a11y-src-spacing"); // only apply spacing to lists in the Sources section
} else {
$("html").addClass("a11y-list-spacing"); // apply spacing rules to all lists in the profile content
}
}
if (options.mergeAdjacentLists) {
let qy;
if (options.spaceSourceItemsOnly) {
//$("html").addClass("a11y-adj-src-merge");
qy = $("ol.references, a[name='Sources']").first().nextUntil("a[name^='Acknowledgement']"); // only look at elements between "Sources" and "Acknowledgements" (or the <references /> list, if there is no section header)
} else {
//$("html").addClass("a11y-adj-ul-merge");
qy = $("#toc, a[name='Biography']").first().nextAll(); // look at all elements after either the TOC or Biography header
}
let ul;
qy.each(function(index) {
let el = $(this);
if (el.is("ul")) {
if (ul) {
let li = el.children().detach().appendTo(ul); // merge all child list items into the preceding list
el.remove();
} else {
ul = el; // this will be the starting point where all successive lists will be merged into
}
} else {
ul = null; // there are no more adjacent lists, so start looking for the next starting point
}
});
}
if (options.removeSourceBreaks || options.removeSourceLabels || options.boldSources) {
let qy = $("ol.references, a[name='Sources']").first().nextUntil("a[name^='Acknowledgement']").addBack().filter("ol, ul").children("li");
if (options.removeSourceBreaks) {
qy.each(function (index) {
let li = $(this);
let isFirst = true;
li.find("br").replaceWith(" ");
});
}
if (options.removeSourceLabels) {
qy.each(function (index) {
let li = $(this);
let isFirst = true;
li.contents().each(function() {
let el = $(this);
if (el.is("sup, a[href^='#'], span:empty")) {
return true; // skip over back-reference links
}
if (this.nodeValue && /^\u2191?\s*$/.test(this.nodeValue)) {
return true; // skip over whitespace and the up arrow (sometimes a link, sometimes text, depending on whether there are multiple references)
}
if (el.is("b")) {
if (this.nextSibling && this.nextSibling.nodeType && this.nextSibling.nodeType === 3) {
this.nextSibling.nodeValue = this.nextSibling.nodeValue.replace(/^\s*:\s*/, "");
}
el.remove();
}
return false;
});
});
}
if (options.boldSources) {
$("html").addClass("a11y-src-bold");
let qy = $("ol.references, a[name='Sources']").first().nextUntil("a[name^='Acknowledgement']").addBack().filter("ol, ul").children("li");
qy.each(function (index) {
let li = $(this);
li.contents().filter(function() {
let el = $(this);
if (!el.is("sup, a[href^='#'], span:empty")) {
if (this.nodeValue && /^\u2191?\s*$/.test(this.nodeValue)) {
return false; // weed out whitespace and the up arrow (sometimes a link, sometimes text, depending on whether there are multiple references)
}
return (this.nodeType && (this.nodeType == 1 || this.nodeType == 3));
}
return false;
}).first().wrap('<span class="a11y-src-first"></span>');
});
}
}
}

checkIfFeatureEnabled("accessibility").then((result) => {
if (result) {
import("./accessibility.css");
initAccessibility();
}
});
83 changes: 83 additions & 0 deletions src/features/accessibility/accessibility_options.js
@@ -0,0 +1,83 @@
import { registerFeature, OptionType } from "../../core/options/options_registry";

const accessibilityFeature = {
name: "Accessibility Mode",
id: "accessibility",
description: "Style options to make profiles more readable.",
category: "Style",
defaultValue: false,
options: [
{
id: "listItemSpacing",
type: OptionType.SELECT,
label: "The amount of spacing to add between list items",
values: [
{
value: 0,
text: "none",
},
{
value: 50,
text: "50% (half)",
},
{
value: 75,
text: "75%",
},
{
value: 100,
text: "100% (standard)",
},
{
value: 150,
text: "150%",
},
{
value: 200,
text: "200% (double)",
},
{
value: 300,
text: "300%",
},
{
value: 400,
text: "400% (extra wide)",
},
],
defaultValue: 100,
},
{
id: "mergeAdjacentLists",
type: OptionType.CHECKBOX,
label: "Remove extra line spacing (added by profile editors) from between adjacent bullet list items.",
defaultValue: false,
},
{
id: "spaceSourceItemsOnly",
type: OptionType.CHECKBOX,
label: "Limit spacing rules to only lists under the Sources section.",
defaultValue: true,
},
{
id: "boldSources",
type: OptionType.CHECKBOX,
label: "Bold the first segment of each source citation for readability.",
defaultValue: true,
},
{
id: "removeSourceBreaks",
type: OptionType.CHECKBOX,
label: "Remove extra line breaks (added by profile editors) from the middle of source citations.",
defaultValue: false,
},
{
id: "removeSourceLabels",
type: OptionType.CHECKBOX,
label: "Remove extra source labels (added by profile editors) from the beginning of source citations.",
defaultValue: false,
},
],
};

registerFeature(accessibilityFeature);
1 change: 1 addition & 0 deletions src/features/register_feature_options.js
Expand Up @@ -7,6 +7,7 @@ import { registerFeature } from "../core/options/options_registry";
// the feature and options
////////////////////////////////////////////////////////////////////////////////

import "./accessibility/accessibility_options.js";
import "./agc/agc_options.js";
import "./categoryDisplay/categoryDisplay_options.js";
import "./change_family_lists/change_family_lists_options.js";
Expand Down

0 comments on commit 8d79182

Please sign in to comment.