Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:decker-edu/decker into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
marcerich committed Oct 20, 2024
2 parents e6769e8 + e36f53b commit 8489db8
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 190 deletions.
9 changes: 9 additions & 0 deletions resource/decker/support/flyingFocus/flying-focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export function showFlyingFocus(event) {
}
target = event.target;

// Navigate to the slide the focus target is located in if not in handout mode
if (!document.documentElement.classList.contains("handout")) {
const section = target.closest("section");
if (section && !section.classList.contains("present")) {
const index = window.Reveal.getIndices(section);
window.Reveal.slide(index.h, index.v);
}
}

// set new position of flying focus
Object.assign(flyingFocus.style, rectOf(target));

Expand Down
31 changes: 24 additions & 7 deletions resource/decker/support/plugins/a11y/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function addScreenReaderSlideNumbers() {

function addScreenReaderSlideNumber(slide, h, v) {
const header = slide.querySelector("h1");
if (header) {
if (header && header.textContent.trim() !== "") {
const innerHTML = header.innerHTML;
const replacementHTML = `<span class="sr-only">${localization.slide} ${
h + 1
Expand Down Expand Up @@ -95,7 +95,7 @@ function addCustomSpacebarHandler() {
}
}

function toggleA11YMode() {
function toggleAccessibility() {
a11yMode = !a11yMode;

if (a11yMode) {
Expand All @@ -111,6 +111,15 @@ function toggleA11YMode() {
modifyMedia(audio);
}
Decker.flash.message(localization.accessible_colors_on);
if (window.MathJax) {
window.MathJax.startup.document.options.enableMenu = true;
window.MathJax.startup.document.menu.menu
.findID("Accessibility", "Activate")
.variable.setter(true);
window.MathJax.startup.document.menu.loadingPromise.then(() => {
window.MathJax.startup.document.rerender();
});
}
} else {
pluginButton.ariaPressed = false;
pluginButton.setLabel(localization.activate_accessibility);
Expand All @@ -124,6 +133,16 @@ function toggleA11YMode() {
restoreMedia(audio);
}
Decker.flash.message(localization.accessible_colors_off);
if (window.MathJax) {
// Does it make sense to remove this again if once activated?
window.MathJax.startup.document.options.enableMenu = false;
window.MathJax.startup.document.menu.menu
.findID("Accessibility", "Activate")
.variable.setter(false);
window.MathJax.startup.document.menu.loadingPromise.then(() => {
window.MathJax.startup.document.rerender();
});
}
}
}

Expand Down Expand Up @@ -162,9 +181,7 @@ const Plugin = {
description: "Toggle Decker Accessibility Adjustments (Triple Click)",
},

Decker.tripleClick(() => {
toggleA11YMode();
})
Decker.tripleClick(toggleAccessibility)
);
reveal.addEventListener("ready", () => {
const menuPlugin = reveal.getPlugin("decker-menu");
Expand All @@ -173,13 +190,13 @@ const Plugin = {
"decker-menu-a11y-button",
"fa-universal-access",
localization.activate_accessibility,
toggleA11YMode
toggleAccessibility
);
}
});
if (a11y) {
Reveal.addEventListener("ready", () => {
toggleA11YMode();
toggleAccessibility();
});
}
},
Expand Down
208 changes: 106 additions & 102 deletions resource/decker/support/plugins/math/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
* Modifications by Mario Botsch:
* - upgrade to MathJax v3
* - disable math typesetting on each slide change
* - disable AssistiveMML, since it duplicates math in speaker notes
* - disable SVG font caches, since it doesn't work in speaker notes
* - reset menu settings in localStorage
* - use promise mechanism to ensure that math is typset before PDF print
* - fix links generated by referencing equations to jump to the slide
* containing the referenced equation
Expand All @@ -22,7 +20,7 @@
* Reveal's zoom plugin work on equations.
*/

// reference to Reveal object
// This module's reference to Reveal
let Reveal;

function loadScript(url, callback) {
Expand Down Expand Up @@ -53,55 +51,74 @@ function loadScript(url, callback) {
head.appendChild(script);
}

/*
* correct links generated by referencing equations, such that they
* point to the slide containing the referenced equation.
* Requires that each slide has a CSS id (as generated e.g. by pandoc/decker)
*/
function fixLinks() {
for (let a of document.getElementsByTagName("a")) {
let href = a.href;
if (href.baseVal) {
let label = href.baseVal;
if (label.includes("#mjx-eqn")) {
label = decodeURIComponent(label.substring(1));
const eqn = document.getElementById(label);
if (eqn) {
const s = eqn.closest("section");
if (s) {
a.href.baseVal = location.origin + location.pathname + "#" + s.id;
function adjustLinksDocument(doc) {
for (const item of doc.math) {
adjustLinksItem(item, doc);
}
}

function adjustLinksItem(item, doc) {
const root = item.typesetRoot;
if (root) {
const anchors = root.querySelectorAll("a");
for (const anchor of anchors) {
const href = anchor.href;
if (href.baseVal) {
let label = href.baseVal;
if (label.includes("#mjx-eqn")) {
label = decodeURIComponent(label.substring(1));
const eqn = document.getElementById(label);
if (eqn) {
const s = eqn.closest("section");
if (s) {
anchor.href.baseVal =
location.origin +
location.pathname +
location.search +
"#" +
s.id;
}
}
}
}
}
}
}

/*
* If a multi-line equation is enclosed in a div with class math-incremental,
* then add class fragment to the individual rows of the equation, making it
* appear row-by-row.
*/
function setupMathIncremental() {
// unlabeled equations
for (let mrow of document.querySelectorAll(
'.reveal .math-incremental mjx-container svg g[data-mml-node="mtable"]:first-of-type > g[data-mml-node="mtr"]'
)) {
mrow.classList.add("fragment");
function incrementalDocument(doc) {
for (const item of doc.math) {
incrementalItem(item, doc);
}
}

// unlabeled equations
for (let mrow of document.querySelectorAll(
'.reveal .math-incremental mjx-container svg g[data-mml-node="mtable"]:first-of-type g[data-mml-node="mlabeledtr"]'
)) {
mrow.classList.add("fragment");
function incrementalItem(item, mdoc) {
const doc = document.documentElement;
const root = item.typesetRoot;
if (root && root.closest(".math-incremental")) {
for (let mrow of root.querySelectorAll(
'g[data-mml-node="mtable"]:first-of-type > g[data-mml-node="mtr"]'
)) {
mrow.classList.add("fragment");
if (doc.classList.contains("handout") || doc.classList.contains("a11y")) {
mrow.classList.add("visible");
}
}
for (let mrow of document.querySelectorAll(
'g[data-mml-node="mtable"]:first-of-type g[data-mml-node="mlabeledtr"]'
)) {
mrow.classList.add("fragment");
if (doc.classList.contains("handout") || doc.classList.contains("a11y")) {
mrow.classList.add("visible");
}
}
}
}

/*
/*
* remove fragments from assistive MML blocks
*/
function fixAssistiveMML() {
function fixAssistiveMML(doc) {
for (let elem of document.querySelectorAll("mjx-assistive-mml .fragment")) {
elem.classList.remove("fragment");
}
Expand Down Expand Up @@ -135,6 +152,9 @@ function injectStyle() {
document.head.append(style);
}

// Is initial a11y mode requested?
const a11y = /a11y/gi.test(window.location.search);

const Plugin = {
id: "math",

Expand All @@ -144,38 +164,43 @@ const Plugin = {
// get configuration, built MathJax URL
const options = Reveal.getConfig().math || {};
if (!options.mathjax) {
console.error("MathJax not properly configured. Call Hauer.");
console.error(
"No MathJax source URI has been configured. This should not happen!",
"The config.math.mathjax value is usually configured in your resource pack's 'deck.html'",
"Please contact the developers: https://github.com/decker-edu/decker"
);
return;
}
const url = options.mathjax + "tex-svg.js";

// remove menu settings, which are stored in localStorage.
// otherwise user could select CHTML renderer, which is not
// installed in decker.
if (window.localStorage) {
window.localStorage.removeItem("MathJax-Menu-Settings");
// define \fragment{...} funtion
let macros = { fragment: ["\\class{fragment}{#1}", 1] };
// add user-defined Latex macros
if (options.macros) {
macros = Object.assign(macros, options.macros);
}

// configure through global MathJax object
const language = Decker.meta.lang || navigator.language;

/* MathJax configuration object */
window.MathJax = {
loader: {
load: [
"[tex]/ams",
// "a11y/assistive-mml",
// "a11y/explorer",
// "a11y/semantic-enrich",
// "a11y/complexity",
// "a11y/sre",
],
typeset: false,
},
startup: {
ready: () => {
console.log("mathjax loaded");
/* Workaround to allow loading of a11y features past initial load
* Necessary due do a bug in 3.2.2 throwing a Mathjax.retry error. */
const { mathjax } = window.MathJax._.mathjax;
const { STATE } = window.MathJax._.core.MathItem;
const { Menu } = window.MathJax._.ui.menu.Menu;
const rerender = Menu.prototype.rerender;
Menu.prototype.rerender = function (start = STATE.TYPESET) {
mathjax.handleRetriesFor(() => {
rerender.call(this, start);
});
};
},
},
svg: {
scale: Decker.meta.math.scale || 1.0, // global scaling factor for all expressions
scale: window.Decker.meta.math.scale || 1.0, // global scaling factor for all expressions
minScale: 0.5, // smallest scaling factor to use
mtextInheritFont: true, // true to make mtext elements use surrounding font
merrorInheritFont: true, // true to make merror text use surrounding font
Expand All @@ -191,9 +216,6 @@ const Plugin = {
},
tex: {
tags: "ams",
packages: {
"[+]": ["ams"],
},
inlineMath: [
// start/end delimiter pairs for in-line math
["$", "$"],
Expand All @@ -204,60 +226,42 @@ const Plugin = {
["$$", "$$"],
["\\[", "\\]"],
],
macros: macros,
},
options: {
enableMenu: false,
// enableMenu: true,
// enableEnrichment: true,
// enableComplexity: true,
// enableExplorer: true,
// menuOptions: {
// settings: {
// assistiveMml: true,
// collapsible: false, // messes up spacing in some equations
// explorer: true,
// },
// },
// a11y: {
// speech: true,
// braille: true,
// },
// sre: {
// speech: "deep",
// domain: "mathspeak",
// style: "default",
// locale: window.navigator.language,
// },
renderActions: {
incremental: [1000, incrementalDocument, incrementalItem, false],
adjustLinks: [1001, adjustLinksDocument, adjustLinksItem, false],
fixmml: [1002, fixAssistiveMML, "", false],
},
sre: {
locale: language === "de" ? "de" : "en",
},
enableMenu: a11y,
menuOptions: {
settings: {
explorer: a11y, //if in a11y page mode: active by default
},
},
a11y: {
backgroundColor: "Green",
backgroundOpacity: 50,
foregroundColor: "Black",
foregroundOpacity: 100,
},
},
};

// define \fragment{...} funtion
let macros = { fragment: ["\\class{fragment}{#1}", 1] };
// add user-defined Latex macros
if (options.macros) {
macros = Object.assign(macros, options.macros);
}
window.MathJax.tex.macros = macros;
injectStyle();

// use promise mechanism to make sure that math typesetting
// is performend before Reveal fires ready-event or
// generates a PDF
/* Return a promise to reveal to make it wait until startup.promise resolves. */
return new Promise((resolve) => {
// load mathjax script
loadScript(url, () => {
// Typeset followed by an immediate reveal.js layout since
// the typesetting process could affect slide height
console.time("mathjax typesetting");
window.MathJax.startup.defaultReady();
window.MathJax.startup.promise.then(() => {
console.timeEnd("mathjax typesetting");
Reveal.layout();
fixLinks();
setupMathIncremental();
fixAssistiveMML();
injectStyle();
resolve();
});
window.MathJax.startup.defaultReady();
});
});
},
Expand Down
Loading

0 comments on commit 8489db8

Please sign in to comment.