1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
// @license magnet:?xt=urn:btih:8e4f440f4c65981c5bf93c76d35135ba5064d8b7&dn=apache-2.0.txt Apache-2.0
/*************************************************************
*
* [Contrib]/a11y/accessibility-menu.js
*
* A thin extension to add opt-in menu items for the accessibility
* extensions in the a11y contributed directory.
*
* ---------------------------------------------------------------------
*
* Copyright (c) 2016-2017 The MathJax Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function(HUB,EXTENSIONS) {
var SETTINGS = HUB.config.menuSettings;
var ITEM, MENU; // filled in when MathMenu extension loads
var BIND = (Function.prototype.bind ? function (f,t) {return f.bind(t)} :
function (f,t) {return function () {f.apply(t,arguments)}});
var KEYS = Object.keys || function (obj) {
var keys = [];
for (var id in obj) {if (obj.hasOwnProperty(id)) keys.push(id)}
return keys;
};
//
// Set up the a11y path,if it isn't already in place
//
var PATH = MathJax.Ajax.config.path;
if (!PATH.a11y) PATH.a11y = HUB.config.root + "/extensions/a11y";
var Accessibility = EXTENSIONS["accessibility-menu"] = {
version: '1.6.0',
prefix: '', //'Accessibility-',
defaults: {},
modules: [],
MakeOption: function(name) {
return Accessibility.prefix + name;
},
GetOption: function(option) {
return SETTINGS[Accessibility.MakeOption(option)];
},
AddDefaults: function() {
var keys = KEYS(Accessibility.defaults);
for (var i = 0, key; key = keys[i]; i++) {
var option = Accessibility.MakeOption(key);
if (typeof(SETTINGS[option]) === 'undefined') {
SETTINGS[option] = Accessibility.defaults[key];
}
}
},
// Attaches the menu items;
AddMenu: function() {
var items = Array(this.modules.length);
for (var i = 0, module; module = this.modules[i]; i++) items[i] = module.placeHolder;
var menu = MENU.FindId('Accessibility');
if (menu) {
items.unshift(ITEM.RULE());
menu.submenu.items.push.apply(menu.submenu.items,items);
} else {
var renderer = (MENU.FindId("Settings","Renderer")||{}).submenu;
if (renderer) {
// move AssitiveMML and InTabOrder from Renderer to Accessibility menu
items.unshift(ITEM.RULE());
items.unshift(renderer.items.pop());
items.unshift(renderer.items.pop());
}
items.unshift("Accessibility");
var menu = ITEM.SUBMENU.apply(ITEM.SUBMENU,items);
var locale = MENU.IndexOfId('Locale');
if (locale) {
MENU.items.splice(locale,0,menu);
} else {
MENU.items.push(ITEM.RULE(), menu);
}
}
},
Register: function(module) {
Accessibility.defaults[module.option] = false;
Accessibility.modules.push(module);
},
Startup: function() {
ITEM = MathJax.Menu.ITEM;
MENU = MathJax.Menu.menu;
for (var i = 0, module; module = this.modules[i]; i++) module.CreateMenu();
this.AddMenu();
},
LoadExtensions: function () {
var extensions = [];
for (var i = 0, module; module = this.modules[i]; i++) {
if (SETTINGS[module.option]) extensions.push(module.module);
}
return (extensions.length ? HUB.Startup.loadArray(extensions) : null);
}
};
var ModuleLoader = MathJax.Extension.ModuleLoader = MathJax.Object.Subclass({
option: '',
name: ['',''],
module: '',
placeHolder: null,
submenu: false,
extension: null,
Init: function(option, name, module, extension, submenu) {
this.option = option;
this.name = [name.replace(/ /g,''),name];
this.module = module;
this.extension = extension;
this.submenu = (submenu || false);
},
CreateMenu: function() {
var load = BIND(this.Load,this);
if (this.submenu) {
this.placeHolder =
ITEM.SUBMENU(this.name,
ITEM.CHECKBOX(["Activate","Activate"],
Accessibility.MakeOption(this.option), {action: load}),
ITEM.RULE(),
ITEM.COMMAND(["OptionsWhenActive","(Options when Active)"],null,{disabled:true})
);
} else {
this.placeHolder = ITEM.CHECKBOX(
this.name, Accessibility.MakeOption(this.option), {action: load}
);
}
},
Load: function() {
HUB.Queue(["Require",MathJax.Ajax,this.module,["Enable",this]]);
},
Enable: function(menu) {
var extension = MathJax.Extension[this.extension];
if (extension) {
extension.Enable(true,true);
MathJax.Menu.saveCookie();
}
}
});
Accessibility.Register(
ModuleLoader(
'collapsible', 'Collapsible Math', '[a11y]/collapsible.js', 'collapsible'
)
);
Accessibility.Register(
ModuleLoader(
'autocollapse', 'Auto Collapse', '[a11y]/auto-collapse.js', 'auto-collapse'
)
);
Accessibility.Register(
ModuleLoader(
'explorer', 'Explorer', '[a11y]/explorer.js', 'explorer', true
)
);
Accessibility.AddDefaults();
HUB.Register.StartupHook('End Extensions', function () {
HUB.Register.StartupHook('MathMenu Ready', function () {
Accessibility.Startup();
HUB.Startup.signal.Post('Accessibility Menu Ready');
},5); // run before other extensions' menu hooks even if they are loaded first
},5);
MathJax.Hub.Register.StartupHook("End Cookie", function () {
MathJax.Callback.Queue(
["LoadExtensions",Accessibility],
["loadComplete",MathJax.Ajax,"[a11y]/accessibility-menu.js"]
);
});
})(MathJax.Hub,MathJax.Extension);
// @license-end
|