Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'accessibility-mode' into profile-classes
- Loading branch information
Showing
5 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters