commit f0cc437b1e61d05c6c46d6b64a2a947c815272bf
parent d8357a2d03546576a368a25a9d860e1e796b1cfe
Author: Davide P. Cervone <dpvc@union.edu>
Date: Thu, 23 Jul 2015 16:40:18 -0400
Refactor code to make a separate configuration section with dynamically generated stylesheet. Use a class for the added MathML rather than explicit CSS.
Diffstat:
1 file changed, 55 insertions(+), 42 deletions(-)
diff --git a/unpacked/extensions/AssistiveMML.js b/unpacked/extensions/AssistiveMML.js
@@ -26,9 +26,54 @@
*/
(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(function () {
+ console.log("MathML time: "+((new Date().getTime())-state.start));
+ }),
+ start: new Date().getTime()
+ };
+ this.HandleMML(state);
+ return state.callback;
+ },
//
// For each jax in the state, look up the frame.
@@ -52,64 +97,32 @@
return MathJax.Callback.After(["HandleMML",this,state],err.restart);
}
frame.setAttribute("data-mathml",mml);
- span = HTML.Element("span",{
- isMathJax: true,
- style:{
- position:"absolute",
- clip: (HUB.Browser.isMSIE && (document.documentMode||0) < 8 ?
- "rect(1px 1px 1px 1px)" : "rect(1px, 1px, 1px, 1px)"),
- padding: "1 0 0 0",
- border: "0",
- height: "1px",
- width: "1px",
- overflow: "hidden",
- display:"block"
- }
- });
+ span = HTML.addElement(frame,"span",{
+ isMathJax: true, className: "MJX_Assistive_MathML"
+ });
span.innerHTML = mml;
- frame.appendChild(span);
}
state.i++;
}
state.callback();
- },
-
- //
- // 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) {
- var state = {
- jax: HUB.getAllJax(node), i: 0,
- callback: MathJax.Callback(function () {
- console.log("MathML time: "+((new Date().getTime())-state.start));
- }),
- start: new Date().getTime()
- };
- this.HandleMML(state);
- return state.callback;
}
};
- //
- // Call the hook when math has been processed.
- //
- HUB.Register.MessageHook("End Math",function (msg) {AssistiveMML.EndMathHook(msg[1])});
-
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.
+// 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"]
+ ["loadComplete",MathJax.Ajax,"[MathJax]/extensions/AssistiveMML.js"],
+ function () {
+ MathJax.Hub.Register.StartupHook("End Config",["Config",MathJax.Extension.AssistiveMML]);
+ }
);