merge branch 'assistive-mml' into develop
This commit is contained in:
commit
94363d94bb
|
@ -2569,6 +2569,8 @@ MathJax.Hub.Startup = {
|
|||
}
|
||||
if (SETTINGS.FastPreview && !MathJax.Extension["fast-preview"])
|
||||
MathJax.Hub.config.extensions.push("fast-preview.js");
|
||||
if (config.menuSettings.assistiveMML && !MathJax.Extension.AssistiveMML)
|
||||
MathJax.Hub.config.extensions.push("AssistiveMML.js");
|
||||
},MathJax.Hub.config],
|
||||
["Post",this.signal,"End Cookie"]
|
||||
);
|
||||
|
|
127
unpacked/extensions/AssistiveMML.js
Normal file
127
unpacked/extensions/AssistiveMML.js
Normal file
|
@ -0,0 +1,127 @@
|
|||
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
|
||||
/*************************************************************
|
||||
*
|
||||
* MathJax/extensions/AssistiveMML.js
|
||||
*
|
||||
* Implements an extension that inserts hidden MathML into the
|
||||
* page for screen readers or other asistive technology.
|
||||
*
|
||||
* ---------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2015 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 (AJAX,CALLBACK,HUB,HTML) {
|
||||
var SETTINGS = HUB.config.menuSettings;
|
||||
|
||||
var AssistiveMML = MathJax.Extension["AssistiveMML"] = {
|
||||
version: "2.6",
|
||||
|
||||
config: {
|
||||
disabled: false,
|
||||
styles: {
|
||||
".MJX_Assistive_MathML": {
|
||||
position:"absolute!important",
|
||||
clip: (HUB.Browser.isMSIE && (document.documentMode||0) < 8 ?
|
||||
"rect(1px 1px 1px 1px)" : "rect(1px, 1px, 1px, 1px)"),
|
||||
padding: "1px 0 0 0!important",
|
||||
border: "0!important",
|
||||
height: "1px!important",
|
||||
width: "1px!important",
|
||||
overflow: "hidden!important",
|
||||
display:"block!important"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Config: function () {
|
||||
if (!this.config.disabled && SETTINGS.assistiveMML == null)
|
||||
HUB.Config({menuSettings:{assistiveMML:true}});
|
||||
AJAX.Styles(this.config.styles);
|
||||
HUB.Register.MessageHook("End Math",function (msg) {AssistiveMML.EndMathHook(msg[1])});
|
||||
},
|
||||
|
||||
//
|
||||
// The hook for the End Math signal.
|
||||
// This sets up a state object that lists the jax and index into the jax,
|
||||
// and a dummy callback that is used to synchronizing with MathJax.
|
||||
// It will be called when the jax are all processed, and that will
|
||||
// let the MathJax queue continue (it will block until then).
|
||||
//
|
||||
EndMathHook: function (node) {
|
||||
if (!SETTINGS.assistiveMML) return;
|
||||
var state = {
|
||||
jax: HUB.getAllJax(node), i: 0,
|
||||
callback: MathJax.Callback({})
|
||||
};
|
||||
this.HandleMML(state);
|
||||
return state.callback;
|
||||
},
|
||||
|
||||
//
|
||||
// For each jax in the state, look up the frame.
|
||||
// If the jax doesn't use NativeMML and hasn't already been handled:
|
||||
// Get the MathML for the jax, taking resets into account.
|
||||
// Add a data-mathml attribute to the frame, and
|
||||
// Create a span that is not visible on screen and put the MathML in it,
|
||||
// and add it to the frame.
|
||||
// When all the jax are processed, call the callback.
|
||||
//
|
||||
HandleMML: function (state) {
|
||||
var m = state.jax.length, jax, mml, frame, span;
|
||||
while (state.i < m) {
|
||||
jax = state.jax[state.i];
|
||||
frame = document.getElementById(jax.inputID+"-Frame");
|
||||
if (jax.outputJax !== "NativeMML" && frame && !frame.getAttribute("data-mathml")) {
|
||||
try {
|
||||
mml = jax.root.toMathML("").replace(/\n */g,"").replace(/<!--.*?-->/g,"");
|
||||
} catch (err) {
|
||||
if (!err.restart) throw err; // an actual error
|
||||
return MathJax.Callback.After(["HandleMML",this,state],err.restart);
|
||||
}
|
||||
frame.setAttribute("data-mathml",mml);
|
||||
span = HTML.addElement(frame,"span",{
|
||||
isMathJax: true, className: "MJX_Assistive_MathML"
|
||||
});
|
||||
span.innerHTML = mml;
|
||||
frame.firstChild.setAttribute("aria-hidden","true");
|
||||
span.setAttribute("aria-readonly","true");
|
||||
}
|
||||
state.i++;
|
||||
}
|
||||
state.callback();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
HUB.Startup.signal.Post("AssistiveMML Ready");
|
||||
|
||||
})(MathJax.Ajax,MathJax.Callback,MathJax.Hub,MathJax.HTML);
|
||||
|
||||
//
|
||||
// Make sure the toMathML extension is loaded before we signal
|
||||
// the load complete for this extension. Then wait for the end
|
||||
// of the user configuration before configuring this extension.
|
||||
//
|
||||
MathJax.Callback.Queue(
|
||||
["Require",MathJax.Ajax,"[MathJax]/extensions/toMathML.js"],
|
||||
["loadComplete",MathJax.Ajax,"[MathJax]/extensions/AssistiveMML.js"],
|
||||
function () {
|
||||
MathJax.Hub.Register.StartupHook("End Config",["Config",MathJax.Extension.AssistiveMML]);
|
||||
}
|
||||
);
|
||||
|
|
@ -1471,7 +1471,8 @@
|
|||
ITEM.RADIO("MathML", "renderer", {action: MENU.Renderer, value:"NativeMML"}),
|
||||
ITEM.RADIO("SVG", "renderer", {action: MENU.Renderer}),
|
||||
ITEM.RULE(),
|
||||
ITEM.CHECKBOX("Fast Preview", "FastPreview")
|
||||
ITEM.CHECKBOX("Fast Preview", "FastPreview"),
|
||||
ITEM.CHECKBOX("Assistive MathML", "assistiveMML", {hidden:!CONFIG.showAssistiveMML})
|
||||
),
|
||||
ITEM.SUBMENU("MathPlayer", {hidden:!HUB.Browser.isMSIE || !CONFIG.showMathPlayer,
|
||||
disabled:!HUB.Browser.hasMathPlayer},
|
||||
|
@ -1558,7 +1559,11 @@
|
|||
MENU.cookie.showLocale = CONFIG.showLocale = show; MENU.saveCookie();
|
||||
MENU.menu.Find("Language").hidden = !show;
|
||||
};
|
||||
|
||||
MENU.showAssistiveMML = function (show) {
|
||||
MENU.cookie.showAssistiveMML = CONFIG.showAssistiveMML = show; MENU.saveCookie();
|
||||
MENU.menu.Find("Math Settings","Math Renderer","Assistive MathML").hidden = !show;
|
||||
};
|
||||
|
||||
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
|
||||
if (!MathJax.OutputJax["HTML-CSS"].config.imageFont)
|
||||
{MENU.menu.Find("Math Settings","Font Preference","TeX (image)").disabled = true}
|
||||
|
|
|
@ -99,8 +99,8 @@ MathJax.Extension.mml2jax = {
|
|||
}
|
||||
for (var i = 0, m = math.length; i < m; i++) {
|
||||
var parent = math[i].parentNode;
|
||||
if (parent && parent.className !== preview && !math[i].prefix === !namespace)
|
||||
{array.push(math[i])}
|
||||
if (parent && parent.className !== preview &&
|
||||
!parent.isMathJax && !math[i].prefix === !namespace) array.push(math[i]);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user