diff --git a/app/assets/javascripts/discourse/lib/Markdown.Editor.js b/app/assets/javascripts/discourse/lib/Markdown.Editor.js index c011a0ca6..1e3fec006 100644 --- a/app/assets/javascripts/discourse/lib/Markdown.Editor.js +++ b/app/assets/javascripts/discourse/lib/Markdown.Editor.js @@ -861,6 +861,7 @@ var oldInputText; var maxDelay = 3000; var startType = "delayed"; // The other legal value is "manual" + var scrollSyncOn = !!panels.previewScroller; var paneContentHeight = function(pane) { var $pane = $(pane); @@ -869,11 +870,10 @@ return pane.scrollHeight - paneVerticalPadding; }; - var prevScrollPosition = $(panels.input).scrollTop(); - var caretMarkerPosition = 0; - var markerPositions; - if (panels.previewScroller) { - markerPositions = { + if (scrollSyncOn) { + var prevScrollPosition = $(panels.input).scrollTop(); + var caretMarkerPosition = 0; + var markerPositions = { scroller: [0, paneContentHeight(panels.previewScroller)], preview: [0, paneContentHeight(panels.preview)] }; @@ -1020,21 +1020,28 @@ var prevTime = new Date().getTime(); - var caretPosition = getCaretPosition(); - text = text.slice(0, caretPosition) + '~~caret~~' + text.slice(caretPosition); - text = text.replace(/(\n|\r|\r\n)(\n|\r|\r\n)+/g, "$&~~marker~~$1$1"); + var previewText; + var previewScrollerText; - previewText = converter.makeHtml(text.replace('~~caret~~', '')) - .replace(/

~~marker~~<\/p>/g, '') - .replace(/~~marker~~/g, ''); + if (scrollSyncOn) { + var caretPosition = getCaretPosition(); + text = text.slice(0, caretPosition) + '~~caret~~' + text.slice(caretPosition); + text = text.replace(/(\n|\r|\r\n)(\n|\r|\r\n)+/g, "$&~~marker~~$1$1"); - previewScrollerText = text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/(\n|\r|\r\n)/g, '
') - .replace('~~caret~~', '') - .replace(/~~marker~~

/g, ''); + previewText = converter.makeHtml(text.replace('~~caret~~', '')) + .replace(/

~~marker~~<\/p>/g, '') + .replace(/~~marker~~/g, ''); + + previewScrollerText = text + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/(\n|\r|\r\n)/g, '
') + .replace('~~caret~~', '') + .replace(/~~marker~~

/g, ''); + } else { + previewText = converter.makeHtml(text); + } // Calculate the processing time of the HTML creation. // It's used as the delay time in the event listener. @@ -1043,7 +1050,7 @@ Ember.run(function() { pushPreviewHtml(previewText, previewScrollerText); - if (panels.previewScroller) { + if (scrollSyncOn) { cacheMarkerPositions(); cacheCaretMarkerPosition(); syncScroll(true); @@ -1154,14 +1161,14 @@ }; ieSafeSet(panels.preview, previewText); - if (panels.previewScroller) { + if (scrollSyncOn) { ieSafeSet(panels.previewScroller, previewScrollerText); } } var nonSuckyBrowserPreviewSet = function (previewText, previewScrollerText) { panels.preview.innerHTML = previewText; - if (panels.previewScroller) { + if (scrollSyncOn) { panels.previewScroller.innerHTML = previewScrollerText; } } @@ -1213,7 +1220,7 @@ // TODO: make option to disable. We don't need this in discourse // setupEvents(panels.input, applyTimeout); - if (panels.previewScroller) { + if (scrollSyncOn) { setupScrollSync(); }