Markdown Editor clean up.

This commit is contained in:
Wojciech Zawistowski 2014-04-04 20:22:18 +02:00
parent e7601db730
commit 2566d106d7

View file

@ -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(/<p>~~marker~~<\/p>/g, '<span class="marker"></span>')
.replace(/~~marker~~/g, '<span class="marker"></span>');
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/(\n|\r|\r\n)/g, '<br>')
.replace('~~caret~~', '<span class="caret"></span>')
.replace(/~~marker~~<br><br>/g, '<span class="marker"></span>');
previewText = converter.makeHtml(text.replace('~~caret~~', ''))
.replace(/<p>~~marker~~<\/p>/g, '<span class="marker"></span>')
.replace(/~~marker~~/g, '<span class="marker"></span>');
previewScrollerText = text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/(\n|\r|\r\n)/g, '<br>')
.replace('~~caret~~', '<span class="caret"></span>')
.replace(/~~marker~~<br><br>/g, '<span class="marker"></span>');
} 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();
}