diff --git a/index.html b/index.html
index d927bf09..738a73f5 100644
--- a/index.html
+++ b/index.html
@@ -513,6 +513,13 @@
+
+
+
+
+
+
diff --git a/js/Markdown.Editor.js b/js/Markdown.Editor.js
index c54595fd..8b5c9cef 100644
--- a/js/Markdown.Editor.js
+++ b/js/Markdown.Editor.js
@@ -828,7 +828,7 @@
var elapsedTime;
var oldInputText;
var maxDelay = 3000;
- var startType = "delayed"; // The other legal value is "manual"
+ var startType = "manual"; // The other legal value is "manual"
// Adds event listeners to elements
var setupEvents = function (inputElem, listener) {
diff --git a/js/core.js b/js/core.js
index 5a4e4461..a8723bae 100644
--- a/js/core.js
+++ b/js/core.js
@@ -207,6 +207,7 @@ define(
// Setting management
core.settings = {
converterType : "markdown-extra-prettify",
+ enableMathJax : true,
layoutOrientation : "horizontal",
scrollLink : true,
editorFontSize : 14,
@@ -233,6 +234,8 @@ define(
$("#input-settings-scroll-link").prop("checked", core.settings.scrollLink);
// Converter type
$("#input-settings-converter-type").val(core.settings.converterType);
+ // MathJax
+ $("#input-settings-enable-mathjax").prop("checked", core.settings.enableMathJax);
// Editor font size
$("#input-settings-editor-font-size").val(core.settings.editorFontSize);
// Default content
@@ -251,6 +254,8 @@ define(
"input:radio[name=radio-layout-orientation]:checked").prop("value");
// Converter type
newSettings.converterType = $("#input-settings-converter-type").val();
+ // MathJax
+ newSettings.enableMathJax = $("#input-settings-enable-mathjax").prop("checked");
// Scroll Link
newSettings.scrollLink = $("#input-settings-scroll-link").prop("checked");
// Editor font size
@@ -355,7 +360,6 @@ define(
// apply Scroll Link
lastEditorScrollTop = -9;
- lastPreviewScrollTop = -9;
scrollLink();
}, 500);
@@ -370,7 +374,6 @@ define(
var editorScrollTop = editorElt.scrollTop();
var previewElt = $("#wmd-preview");
var previewScrollTop = previewElt.scrollTop();
- console.log(previewScrollTop);
function animate(srcScrollTop, srcSectionList, destElt, destSectionList, callback) {
// Find the section corresponding to the offset
var sectionIndex = undefined;
@@ -501,8 +504,11 @@ define(
if(core.settings.converterType == "markdown-extra-prettify") {
editor.hooks.chain("onPreviewRefresh", prettyPrint);
}
- if(viewerMode === false && core.settings.scrollLink === true) {
- editor.hooks.chain("onPreviewRefresh", function() {
+ function previewFinished() {
+ if(viewerMode === false && core.settings.scrollLink === true) {
+ // MathJax may have change the scroll position. Restore it
+ $("#wmd-preview").scrollTop(lastPreviewScrollTop);
+ // Update Scroll Link sections
// Modify scroll position of the preview not the editor
lastEditorScrollTop = -9;
buildSections();
@@ -511,7 +517,14 @@ define(
lastEditorScrollTop = -9;
buildSections();
});
- });
+ }
+ }
+ // MathJax
+ if(core.settings.enableMathJax === true) {
+ mathjaxEditing.prepareWmdForMathJax(editor, [["$", "$"], ["\\\\(", "\\\\)"]], previewFinished);
+ }
+ else {
+ editor.hooks.chain("onPreviewRefresh", previewFinished);
}
// Custom insert link dialog
editor.hooks.set("insertLinkDialog", function (callback) {
@@ -527,11 +540,10 @@ define(
$("#modal-insert-image").modal();
return true;
});
- // MathJax
- mathjaxEditing.prepareWmdForMathJax(editor, [["$", "$"], ["\\\\(", "\\\\)"]]);
editor.run();
firstChange = false;
+ $("#wmd-input").bind('input propertychange', _.throttle(editor.refreshPreview, 1000));
// Hide default buttons
$(".wmd-button-row").addClass("btn-group").find("li:not(.wmd-spacer)")
diff --git a/js/mathjax-editing.js b/js/mathjax-editing.js
index 7b40135e..005a610f 100644
--- a/js/mathjax-editing.js
+++ b/js/mathjax-editing.js
@@ -1,4 +1,4 @@
-define([ "jquery", "../lib/MathJax/MathJax" ], function($) {
+define([ "../lib/MathJax/MathJax" ], function() {
MathJax.Hub.Config({"HTML-CSS": {preferredFont: "TeX",availableFonts: ["STIX", "TeX"],linebreaks: {automatic: true},EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50), imageFont: null},
tex2jax: {inlineMath: [["$", "$"], ["\\\\(", "\\\\)"]],displayMath: [["$$", "$$"], ["\\[", "\\]"]],processEscapes: true,ignoreClass: "tex2jax_ignore|dno"},
@@ -151,24 +151,12 @@ define([ "jquery", "../lib/MathJax/MathJax" ], function($) {
// This is run to restart MathJax after it has finished
// the previous run (that may have been canceled)
//
+ var refreshCallback = undefined;
function RestartMJ() {
pending = false;
HUB.cancelTypeset = false; // won't need to do this in the future
- // Keep scroll position (due to a weird behavior when updating div)
- var scrollTop = undefined;
- console.log($(preview).scrollTop());
- HUB.Queue(function() {
- console.log($(preview).scrollTop());
- scrollTop = preview.scrollTop;
- });
HUB.Queue([ "Typeset", HUB, preview ]);
- HUB.Queue(function() {
- console.log($(preview).scrollTop());
- setTimeout(function() {
- console.log($(preview).scrollTop());
- preview.scrollTop = scrollTop;
- }, 1000);
- });
+ HUB.Queue(refreshCallback);
}
//
@@ -179,7 +167,6 @@ define([ "jquery", "../lib/MathJax/MathJax" ], function($) {
if (!pending && ready) {
pending = true;
HUB.Cancel();
- console.log($(preview).scrollTop());
HUB.Queue(RestartMJ);
}
}
@@ -190,7 +177,8 @@ define([ "jquery", "../lib/MathJax/MathJax" ], function($) {
// to handle escaping the math.
// Create a preview refresh hook to handle starting MathJax.
//
- function prepareWmdForMathJax(editorObject, delimiters) {
+ function prepareWmdForMathJax(editorObject, delimiters, callback) {
+ refreshCallback = callback;
preview = document.getElementById("wmd-preview");
inline = delimiters[0][0];