From 7342aebe664c7deed6dd844ef188adbd65f24c9d Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 9 Dec 2015 16:16:45 -0500 Subject: [PATCH] Allow page to enable/disable previews via API calls (for use with editor previews, for example). --- unpacked/extensions/fast-preview.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/unpacked/extensions/fast-preview.js b/unpacked/extensions/fast-preview.js index a14a6d719..c71108205 100644 --- a/unpacked/extensions/fast-preview.js +++ b/unpacked/extensions/fast-preview.js @@ -33,6 +33,7 @@ var FastPreview = MathJax.Extension["fast-preview"] = { version: "2.6.0-beta", + enabled: true, // // Configuration for the chunking of the main output @@ -62,7 +63,7 @@ HUB.Config({"HTML-CSS": config.Chunks, CommonHTML: config.Chunks, SVG: config.Chunks}); } HUB.Register.MessageHook("Begin Math Output",function () { - if (!done && SETTINGS.FastPreview && SETTINGS.renderer !== "PreviewHTML") { + if (!done && SETTINGS.FastPreview && this.enabled && SETTINGS.renderer !== "PreviewHTML") { update = HUB.processUpdateTime; delay = HUB.processUpdateDelay; style = HUB.config.messageStyle; HUB.processUpdateTime = config.updateTime; @@ -81,13 +82,19 @@ } }); }, + + // + // Allow page to override user settings (for things like editor previews) + // + Disable: function () {this.enabled = false}, + Enable: function () {this.enabled = true}, // // Insert a preview span, if there isn't one already, // and call the PreviewHTML output jax to create the preview // Preview: function (data) { - if (!SETTINGS.FastPreview || SETTINGS.renderer === "PreviewHTML") return; + if (!SETTINGS.FastPreview || !this.enabled || SETTINGS.renderer === "PreviewHTML") return; var preview = data.script.MathJax.preview || data.script.previousSibling; if (!preview || preview.className !== MathJax.Hub.config.preRemoveClass) { preview = HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});