Merge pull request #2228 from velesin/markdown_editor_clean_up

Markdown Editor clean up.
This commit is contained in:
Robin Ward 2014-04-04 15:35:20 -04:00
commit 5b602cc043
1 changed files with 29 additions and 22 deletions

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();
}