Skip to content

Commit da33c5d

Browse files
authored
Merge pull request #1058 from mathjax/fix/ff_safari_issues
Fixes issues with firefox and safari.
2 parents 3b3bdce + fb70006 commit da33c5d

File tree

16 files changed

+378
-169
lines changed

16 files changed

+378
-169
lines changed

components/bin/build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const EXPORTPATTERN =
3939
/(^export(?:\s+default)?(?:\s+abstract)?\s+(?:[^ {*}]+\s+(?:enum\s+)?[a-zA-Z0-9_.$]+|\{.* as .*\}))/m;
4040

4141
const EXPORT_IGNORE = ['type', 'interface'];
42-
const EXPORT_PROCESS = ['let', 'const', 'var', 'function', 'class', 'namespace', 'as'];
42+
const EXPORT_PROCESS = ['let', 'const', 'var', 'function', 'class', 'namespace', 'enum', 'as'];
4343

4444
/**
4545
* The module type to use ('cjs' or 'mjs')
@@ -159,7 +159,7 @@ function processParts(parts) {
159159
for (let i = 1; i < parts.length; i += 2) {
160160
const words = parts[i].split(/\s+/);
161161
const n = words.length;
162-
const type = (words[n - 2] === 'enum' ? words[n - 3] : words[n - 2]);
162+
const type = (words[n - 2] === 'enum' && n > 3 ? words[n - 3] : words[n - 2]);
163163
const name = words[n - 1].replace(/\}$/, '');
164164

165165
if (words[1] === 'default' || type === 'default') {

components/mjs/a11y/explorer/config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"webpack": {
77
"name": "a11y/explorer",
88
"libs": [
9-
"components/src/ui/menu/lib",
109
"components/src/a11y/semantic-enrich/lib",
1110
"components/src/a11y/sre/lib",
1211
"components/src/input/mml/lib",
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import './lib/explorer.js';
22

3-
import {combineDefaults} from '#js/components/global.js';
43
import {ExplorerHandler} from '#js/a11y/explorer.js';
54

65
if (MathJax.startup && typeof window !== 'undefined') {
7-
if (MathJax.config.options && MathJax.config.options.enableExplorer !== false) {
8-
combineDefaults(MathJax.config, 'options', {
9-
menuOptions: {
10-
settings: {
11-
explorer: true
12-
}
13-
}
14-
});
15-
}
166
MathJax.startup.extendHandler(handler => ExplorerHandler(handler));
177
}

components/mjs/a11y/semantic-enrich/config.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"build": {
33
"component": "a11y/semantic-enrich",
4-
"targets": ["a11y/semantic-enrich.ts"]
4+
"targets": [
5+
"a11y/semantic-enrich.ts",
6+
"a11y/speech/SpeechUtil.ts",
7+
"a11y/speech/GeneratorPool.ts"
8+
]
59
},
610
"webpack": {
711
"name": "a11y/semantic-enrich",

components/mjs/dependencies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
export const dependencies = {
1919
'a11y/semantic-enrich': ['input/mml', 'a11y/sre'],
2020
'a11y/complexity': ['a11y/semantic-enrich'],
21-
'a11y/explorer': ['a11y/semantic-enrich', 'ui/menu'],
21+
'a11y/explorer': ['a11y/semantic-enrich'],
2222
'[mml]/mml3': ['input/mml'],
2323
'[tex]/action': ['input/tex-base', '[tex]/newcommand'],
2424
'[tex]/all-packages': ['input/tex-base'],

components/mjs/ui/menu/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"build": {
33
"component": "ui/menu",
4-
"targets": ["ui/menu"],
4+
"targets": ["ui/menu", "a11y/speech/SpeechMenu.ts"],
55
"excludeSubdirs": true
66
},
77
"webpack": {

ts/a11y/explorer.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export function ExplorerMathDocumentMixin<B extends MathDocumentConstructor<HTML
203203
align: 'top', // placement of magnified expression
204204
backgroundColor: 'Blue', // color for background of selected sub-expression
205205
backgroundOpacity: 20, // opacity for background of selected sub-expression
206-
braille: false, // switch on Braille output
206+
braille: true, // switch on Braille output
207207
flame: false, // color collapsible sub-expressions
208208
foregroundColor: 'Black', // color to use for text of selected sub-expression
209209
foregroundOpacity: 100, // opacity for text of selected sub-expression
@@ -219,7 +219,7 @@ export function ExplorerMathDocumentMixin<B extends MathDocumentConstructor<HTML
219219
speech: true, // switch on speech output
220220
subtitles: true, // show speech as a subtitle
221221
treeColoring: false, // tree color expression
222-
viewBraille: false, // display Braille output as subtitles
222+
viewBraille: true, // display Braille output as subtitles
223223
voicing: false, // switch on speech output
224224
}
225225
};
@@ -257,7 +257,6 @@ export function ExplorerMathDocumentMixin<B extends MathDocumentConstructor<HTML
257257
* @return {ExplorerMathDocument} The MathDocument (so calls can be chained)
258258
*/
259259
public explorable(): ExplorerMathDocument {
260-
this.options.enableSpeech = true;
261260
if (!this.processed.isSet('explorer')) {
262261
if (this.options.enableExplorer) {
263262
if (!this.explorerRegions) {
@@ -320,18 +319,13 @@ export function setA11yOptions(document: HTMLDOCUMENT, options: {[key: string]:
320319
for (let key in options) {
321320
if (document.options.a11y[key] !== undefined) {
322321
setA11yOption(document, key, options[key]);
323-
if (key === 'locale') {
324-
document.options.sre[key] = options[key];
325-
}
326-
continue;
327-
}
328-
if (sreOptions[key] !== undefined) {
322+
} else if (sreOptions[key] !== undefined) {
329323
document.options.sre[key] = options[key];
330324
}
331325
}
332326
// Reinit explorers
333327
for (let item of document.math) {
334-
(item as ExplorerMathItem).explorers.attach();
328+
(item as ExplorerMathItem)?.explorers?.attach();
335329
}
336330
}
337331

@@ -387,6 +381,10 @@ export function setA11yOption(document: HTMLDOCUMENT, option: string, value: str
387381
break;
388382
}
389383
break;
384+
case 'locale':
385+
document.options.sre.locale = value;
386+
document.options.a11y.locale = value;
387+
break;
390388
default:
391389
document.options.a11y[option] = value;
392390
}

ts/a11y/explorer/ExplorerPool.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,34 @@ export class ExplorerPool {
204204
this.attach();
205205
}
206206

207+
/**
208+
* A11y options keys associated with the speech explorer.
209+
*/
210+
private speechExplorerKeys = ['speech', 'braille', 'keyMagnifier'];
211+
207212
/**
208213
* Attaches the explorers that are currently meant to be active given
209214
* the document options. Detaches all others.
210215
*/
211216
public attach() {
212217
this.attached = [];
213218
let keyExplorers = [];
214-
for (let key of Object.keys(this.explorers)) {
215-
let explorer = this.explorers[key];
219+
const a11y = this.document.options.a11y;
220+
for (let [key, explorer] of Object.entries(this.explorers)) {
216221
if (explorer instanceof SpeechExplorer) {
217222
explorer.AddEvents();
218223
explorer.stoppable = false;
219224
keyExplorers.unshift(explorer);
225+
if (this.speechExplorerKeys.some(
226+
exKey => this.document.options.a11y[exKey])) {
227+
explorer.Attach();
228+
this.attached.push(key);
229+
} else {
230+
explorer.Detach();
231+
}
232+
continue;
220233
}
221-
if (this.document.options.a11y[key]) {
234+
if (a11y[key] || (key === 'speech' && (a11y.braille || a11y.keyMagnifier))) {
222235
explorer.Attach();
223236
this.attached.push(key);
224237
} else {

ts/a11y/explorer/KeyExplorer.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
178178
const prev = this.node.querySelector(prevNav);
179179
if (prev) {
180180
prev.removeAttribute('tabindex');
181+
this.FocusOut(null);
181182
}
182183
this.current = clicked;
183184
if (!this.triggerLinkMouse()) {
@@ -204,6 +205,9 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
204205
* @override
205206
*/
206207
public FocusOut(_event: FocusEvent) {
208+
// This guard is to FF and Safari, where focus in fires only once on
209+
// keyboard.
210+
if (!this.active) return;
207211
this.generators.CleanUp(this.current);
208212
if (!this.move) {
209213
this.Stop();
@@ -474,24 +478,25 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
474478
// the root node by default.
475479
this.current = this.node.childNodes[0] as HTMLElement;
476480
}
481+
const options = this.document.options;
477482
let promise = Sre.sreReady();
478-
if (this.generators.update(this.document.options)) {
483+
if (this.generators.update(options)) {
479484
promise = promise.then(
480485
() => this.Speech()
481486
);
482487
};
483488
this.current.setAttribute('tabindex', '0');
484489
this.current.focus();
485490
super.Start();
486-
if (this.document.options.a11y.subtitles) {
491+
if (options.a11y.subtitles && options.a11y.speech && options.enableSpeech) {
487492
promise.then(
488493
() => this.region.Show(this.node, this.highlighter));
489494
}
490-
if (this.document.options.a11y.viewBraille) {
495+
if (options.a11y.viewBraille && options.a11y.braille && options.enableBraille) {
491496
promise.then(
492497
() => this.brailleRegion.Show(this.node, this.highlighter));
493498
}
494-
if (this.document.options.a11y.keyMagnifier) {
499+
if (options.a11y.keyMagnifier) {
495500
this.magnifyRegion.Show(this.node, this.highlighter);
496501
}
497502
this.Update();
@@ -566,8 +571,8 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
566571
}
567572
}
568573
if (this.active) {
569-
this.stopEvent(event);
570574
if (this.Move(event)) {
575+
this.stopEvent(event);
571576
this.Update();
572577
return;
573578
}
@@ -642,7 +647,8 @@ export class SpeechExplorer extends AbstractExplorer<string> implements KeyExplo
642647
public semanticFocus() {
643648
const node = this.current || this.node;
644649
const id = node.getAttribute('data-semantic-id');
645-
const stree = this.generators.speechGenerator.getRebuilt().stree;
650+
const stree = this.generators.speechGenerator.getRebuilt()?.stree;
651+
if (!stree) return null;
646652
const snode = stree.root.querySelectorAll((x: any) => x.id.toString() === id)[0];
647653
return snode || stree.root;
648654
}

ts/a11y/explorer/Region.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,12 @@ export class SpeechRegion extends LiveRegion {
417417
setTimeout(() => {
418418
if (this.voiceRequest) {
419419
resolve(true);
420+
} else {
421+
// This case is to make FF and Safari work.
422+
setTimeout(() => {
423+
this.voiceRequest = true;
424+
resolve(true);
425+
}, 100);
420426
}
421427
}, 100);
422428
});

0 commit comments

Comments
 (0)