Add menu item for fast preview, and check for it in the preview code. Make sure CHTML-preview.js is loaded in MathJax.js if the menu item is selected.

This commit is contained in:
Davide P. Cervone 2014-11-02 10:03:26 -05:00
parent b137d2e65d
commit d128cfbd5d
3 changed files with 19 additions and 9 deletions

View File

@ -2466,6 +2466,8 @@ MathJax.Hub.Startup = {
} }
jax.unshift(name); jax.unshift(name);
} }
if (config.menuSettings.CHTMLpreview && !MathJax.Extension["CHTML-preview"])
{MathJax.Hub.config.extensions.push("CHTML-preview.js")}
},MathJax.Hub.config], },MathJax.Hub.config],
["Post",this.signal,"End Cookie"] ["Post",this.signal,"End Cookie"]
); );

View File

@ -27,6 +27,8 @@
*/ */
(function (HUB,HTML) { (function (HUB,HTML) {
var SETTINGS = HUB.config.menuSettings;
var CHTMLpreview = MathJax.Extension["CHTML-preview"] = { var CHTMLpreview = MathJax.Extension["CHTML-preview"] = {
version: "1.0", version: "1.0",
@ -38,8 +40,9 @@
config: HUB.CombineConfig("CHTML-preview",{ config: HUB.CombineConfig("CHTML-preview",{
Chunks: {EqnChunk: 10000, EqnChunkFactor: 1, EqnChunkDelay: 0}, Chunks: {EqnChunk: 10000, EqnChunkFactor: 1, EqnChunkDelay: 0},
color: "inherit", color: "inherit",
updateTime: 10, updateDelay: 50, updateTime: 10, updateDelay: 10,
messageStyle: "none" messageStyle: "none",
disabled: false
}), }),
// //
@ -51,20 +54,22 @@
SVG: this.config.Chunks, SVG: this.config.Chunks,
}); });
MathJax.Ajax.Styles({".MathJax_Preview":{color:this.config.color}}); MathJax.Ajax.Styles({".MathJax_Preview":{color:this.config.color}});
var update, delay, style, done; var update, delay, style, done, saved;
var config = this.config; var config = this.config;
HUB.Register.MessageHook("Begin Math Output",function () { HUB.Register.MessageHook("Begin Math Output",function () {
if (!done) { if (!done && !config.disabled && SETTINGS.CHTMLpreview &&
SETTINGS.renderer !== "CommonHTML") {
update = HUB.processUpdateTime; delay = HUB.processUpdateDelay; update = HUB.processUpdateTime; delay = HUB.processUpdateDelay;
style = HUB.config.messageStyle; style = HUB.config.messageStyle;
HUB.processUpdateTime = config.updateTime; HUB.processUpdateTime = config.updateTime;
HUB.processUpdateDelay = config.updateDelay; HUB.processUpdateDelay = config.updateDelay;
HUB.Config({messageStyle: config.messageStyle}); HUB.Config({messageStyle: config.messageStyle});
MathJax.Message.Clear(0,0); MathJax.Message.Clear(0,0);
saved = true;
} }
}); });
HUB.Register.MessageHook("End Math Output",function () { HUB.Register.MessageHook("End Math Output",function () {
if (!done) { if (!done && saved) {
HUB.processUpdateTime = update; HUB.processUpdateTime = update;
HUB.processUpdateDelay = delay; HUB.processUpdateDelay = delay;
HUB.Config({messageStyle: style}); HUB.Config({messageStyle: style});
@ -78,6 +83,8 @@
// and call the CommonHTML output jax to create the preview // and call the CommonHTML output jax to create the preview
// //
Preview: function (data) { Preview: function (data) {
if (this.config.disabled || !SETTINGS.CHTMLpreview ||
SETTINGS.renderer === "CommonHTML") return;
var preview = data.script.previousSibling; var preview = data.script.previousSibling;
if (!preview || preview.className !== MathJax.Hub.config.preRemoveClass) { if (!preview || preview.className !== MathJax.Hub.config.preRemoveClass) {
preview = HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass}); preview = HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});
@ -85,7 +92,6 @@
} }
preview.innerHTML = ""; preview.innerHTML = "";
return this.postFilter(preview,data); return this.postFilter(preview,data);
return data;
}, },
postFilter: function (preview,data) { postFilter: function (preview,data) {
try { try {

View File

@ -964,7 +964,7 @@
"The MathJax contextual menu will be disabled, but you can " + "The MathJax contextual menu will be disabled, but you can " +
"Alt-Click on an expression to obtain the MathJax menu instead."] "Alt-Click on an expression to obtain the MathJax menu instead."]
}; };
/*************************************************************/ /*************************************************************/
/*************************************************************/ /*************************************************************/
@ -1092,14 +1092,16 @@
ITEM.RADIO("HTML-CSS", "renderer", {action: MENU.Renderer}), ITEM.RADIO("HTML-CSS", "renderer", {action: MENU.Renderer}),
ITEM.RADIO("Fast HTML", "renderer", {action: MENU.Renderer, value:"CommonHTML"}), ITEM.RADIO("Fast HTML", "renderer", {action: MENU.Renderer, value:"CommonHTML"}),
ITEM.RADIO("MathML", "renderer", {action: MENU.Renderer, value:"NativeMML"}), ITEM.RADIO("MathML", "renderer", {action: MENU.Renderer, value:"NativeMML"}),
ITEM.RADIO("SVG", "renderer", {action: MENU.Renderer}) ITEM.RADIO("SVG", "renderer", {action: MENU.Renderer}),
ITEM.RULE(),
ITEM.CHECKBOX("Fast Preview", "CHTMLpreview")
), ),
ITEM.SUBMENU("MathPlayer", {hidden:!HUB.Browser.isMSIE || !CONFIG.showMathPlayer, ITEM.SUBMENU("MathPlayer", {hidden:!HUB.Browser.isMSIE || !CONFIG.showMathPlayer,
disabled:!HUB.Browser.hasMathPlayer}, disabled:!HUB.Browser.hasMathPlayer},
ITEM.LABEL(["MPHandles","Let MathPlayer Handle:"]), ITEM.LABEL(["MPHandles","Let MathPlayer Handle:"]),
ITEM.CHECKBOX(["MenuEvents","Menu Events"], "mpContext", {action: MENU.MPEvents, hidden:!isIE9}), ITEM.CHECKBOX(["MenuEvents","Menu Events"], "mpContext", {action: MENU.MPEvents, hidden:!isIE9}),
ITEM.CHECKBOX(["MouseEvents","Mouse Events"], "mpMouse", {action: MENU.MPEvents, hidden:!isIE9}), ITEM.CHECKBOX(["MouseEvents","Mouse Events"], "mpMouse", {action: MENU.MPEvents, hidden:!isIE9}),
ITEM.CHECKBOX(["MenuAndMouse","Mouse and Menu Events"], "mpMouse", {action: MENU.MPEvents, hidden:isIE9}) ITEM.CHECKBOX(["MenuAndMouse","Mouse and Menu Events"], "mpMouse", {action: MENU.MPEvents, hidden:isIE9})
), ),
ITEM.SUBMENU(["FontPrefs","Font Preference"], {hidden:!CONFIG.showFontMenu}, ITEM.SUBMENU(["FontPrefs","Font Preference"], {hidden:!CONFIG.showFontMenu},
ITEM.LABEL(["ForHTMLCSS","For HTML-CSS:"]), ITEM.LABEL(["ForHTMLCSS","For HTML-CSS:"]),