Skip to content

Commit 6c1fde5

Browse files
committed
Make a utility for loading SRE, and use it in combined configurations
1 parent 0d04d6f commit 6c1fde5

File tree

23 files changed

+111
-70
lines changed

23 files changed

+111
-70
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import './lib/assistive-mml.js';
22

3+
import {combineDefaults} from '../../../../js/components/global.js';
34
import {AssistiveMmlHandler} from '../../../../js/a11y/assistive-mml.js';
45

56
if (MathJax.startup) {
7+
if (MathJax.config.options && MathJax.config.options.enableAssistiveMml !== false) {
8+
combineDefaults(MathJax.config, 'options', {
9+
menuOptions: {
10+
settings: {
11+
assistiveMml: true
12+
}
13+
}
14+
});
15+
}
616
MathJax.startup.extendHandler(handler => AssistiveMmlHandler(handler));
717
}

components/src/a11y/explorer/explorer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@ import {combineDefaults} from '../../../../js/components/global.js';
44
import {ExplorerHandler} from '../../../../js/a11y/explorer.js';
55

66
if (MathJax.startup) {
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+
}
716
MathJax.startup.extendHandler(handler => ExplorerHandler(handler));
817
}

components/src/a11y/semantic-enrich/semantic-enrich.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import Sre from '../../../../js/a11y/sre.js';
55
import {EnrichHandler} from '../../../../js/a11y/semantic-enrich.js';
66
import {MathML} from '../../../../js/input/mathml.js';
77

8+
export {Sre};
9+
810
if (MathJax.loader) {
911
combineDefaults(MathJax.config.loader, 'a11y/semantic-enrich', {checkReady: () => Sre.sreReady()});
1012
}

components/src/a11y/sre/sre.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import './lib/sre.js';
22
import './sre_config.js';
33
import Sre from '../../../../js/a11y/sre.js';
44

5+
export {Sre};
6+
57
if (MathJax.startup) {
68
((typeof window !== 'undefined') ? window : global).
79
SREfeature.custom = (loc) => Sre.preloadLocales(loc);

components/src/a11y/util.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Loader} from '../../../js/components/loader.js';
2+
import '../input/mml/init.js';
3+
import {Sre} from '../a11y/sre/sre.js';
4+
import '../a11y/semantic-enrich/semantic-enrich.js';
5+
import '../a11y/explorer/explorer.js';
6+
import MathMaps from '../../../js/a11y/mathmaps.js';
7+
import base from 'speech-rule-engine/lib/mathmaps/base.json';
8+
import en from 'speech-rule-engine/lib/mathmaps/en.json';
9+
import nemeth from 'speech-rule-engine/lib/mathmaps/nemeth.json';
10+
11+
Loader.preLoad(
12+
'a11y/sre',
13+
'a11y/semantic-enrich',
14+
'a11y/explorer'
15+
);
16+
17+
MathMaps.set('base', base);
18+
MathMaps.set('en', en);
19+
MathMaps.set('nemeth', nemeth);
20+
21+
export function checkSre(startup) {
22+
return () => startup(() => Sre.sreReady());
23+
}

components/src/input/mml/init.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import './lib/mml.js';
2+
3+
import {MathML} from '../../../../js/input/mathml.js';
4+
export {MathML};
5+
6+
if (MathJax.loader) {
7+
//
8+
// Install a path-filter to cause loading of an entity file to load all entities,
9+
// since the individual files don't have individual components.
10+
//
11+
MathJax.loader.pathFilters.add((data) => {
12+
data.name = data.name.replace(/\/util\/entities\/.*?\.js/, '/input/mml/entities.js');
13+
return true;
14+
});
15+
}

components/src/input/mml/mml.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import './lib/mml.js';
2-
3-
import {MathML} from '../../../../js/input/mathml.js';
1+
import {MathML} from './init.js';
42

53
if (MathJax.startup) {
64
MathJax.startup.registerConstructor('mml', MathML);
75
MathJax.startup.useInput('mml');
86
}
9-
if (MathJax.loader) {
10-
//
11-
// Install a path-filter to cause loading of an entity file to load all entities,
12-
// since the individual files don't have individual components.
13-
//
14-
MathJax.loader.pathFilters.add((data) => {
15-
data.name = data.name.replace(/\/util\/entities\/.*?\.js/, '/input/mml/entities.js');
16-
return true;
17-
});
18-
}

components/src/mml-chtml-nofont/mml-chtml-nofont.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import '../core/core.js';
44
import '../input/mml/mml.js';
55
import {loadFont} from '../output/chtml/chtml.js';
66
import '../ui/menu/menu.js';
7-
import '../a11y/assistive-mml/assistive-mml.js';
7+
import {checkSre} from '../a11y/util.js';
88

99
Loader.preLoad(
1010
'loader', 'startup',
1111
'core',
1212
'input/mml',
1313
'output/chtml',
14-
'ui/menu',
15-
'a11y/assistive-mml'
14+
'ui/menu'
1615
);
1716

18-
loadFont(startup);
17+
loadFont(checkSre(startup));

components/src/mml-chtml/mml-chtml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import '../core/core.js';
44
import '../input/mml/mml.js';
55
import {loadFont} from '../output/chtml/chtml.js';
66
import '../ui/menu/menu.js';
7-
import '../a11y/assistive-mml/assistive-mml.js';
7+
import {checkSre} from '../a11y/util.js';
88

99
Loader.preLoad(
1010
'loader', 'startup',
1111
'core',
1212
'input/mml',
1313
'output/chtml',
14-
'ui/menu', 'a11y/assistive-mml'
14+
'ui/menu'
1515
);
1616

17-
loadFont(startup, true);
17+
loadFont(checkSre(startup), true);

components/src/mml-svg-nofont/mml-svg-nofont.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import '../core/core.js';
44
import '../input/mml/mml.js';
55
import {loadFont} from '../output/svg/svg.js';
66
import '../ui/menu/menu.js';
7-
import '../a11y/assistive-mml/assistive-mml.js';
7+
import {checkSre} from '../a11y/util.js';
88

99
Loader.preLoad(
1010
'loader', 'startup',
1111
'core',
1212
'input/mml',
1313
'output/svg',
14-
'ui/menu',
15-
'a11y/assistive-mml'
14+
'ui/menu'
1615
);
1716

18-
loadFont(startup);
17+
loadFont(checkSre(startup));

0 commit comments

Comments
 (0)