mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Markdown Editor clean up.
This commit is contained in:
parent
e7601db730
commit
2566d106d7
1 changed files with 29 additions and 22 deletions
|
@ -861,6 +861,7 @@
|
||||||
var oldInputText;
|
var oldInputText;
|
||||||
var maxDelay = 3000;
|
var maxDelay = 3000;
|
||||||
var startType = "delayed"; // The other legal value is "manual"
|
var startType = "delayed"; // The other legal value is "manual"
|
||||||
|
var scrollSyncOn = !!panels.previewScroller;
|
||||||
|
|
||||||
var paneContentHeight = function(pane) {
|
var paneContentHeight = function(pane) {
|
||||||
var $pane = $(pane);
|
var $pane = $(pane);
|
||||||
|
@ -869,11 +870,10 @@
|
||||||
return pane.scrollHeight - paneVerticalPadding;
|
return pane.scrollHeight - paneVerticalPadding;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (scrollSyncOn) {
|
||||||
var prevScrollPosition = $(panels.input).scrollTop();
|
var prevScrollPosition = $(panels.input).scrollTop();
|
||||||
var caretMarkerPosition = 0;
|
var caretMarkerPosition = 0;
|
||||||
var markerPositions;
|
var markerPositions = {
|
||||||
if (panels.previewScroller) {
|
|
||||||
markerPositions = {
|
|
||||||
scroller: [0, paneContentHeight(panels.previewScroller)],
|
scroller: [0, paneContentHeight(panels.previewScroller)],
|
||||||
preview: [0, paneContentHeight(panels.preview)]
|
preview: [0, paneContentHeight(panels.preview)]
|
||||||
};
|
};
|
||||||
|
@ -1020,6 +1020,10 @@
|
||||||
|
|
||||||
var prevTime = new Date().getTime();
|
var prevTime = new Date().getTime();
|
||||||
|
|
||||||
|
var previewText;
|
||||||
|
var previewScrollerText;
|
||||||
|
|
||||||
|
if (scrollSyncOn) {
|
||||||
var caretPosition = getCaretPosition();
|
var caretPosition = getCaretPosition();
|
||||||
text = text.slice(0, caretPosition) + '~~caret~~' + text.slice(caretPosition);
|
text = text.slice(0, caretPosition) + '~~caret~~' + text.slice(caretPosition);
|
||||||
text = text.replace(/(\n|\r|\r\n)(\n|\r|\r\n)+/g, "$&~~marker~~$1$1");
|
text = text.replace(/(\n|\r|\r\n)(\n|\r|\r\n)+/g, "$&~~marker~~$1$1");
|
||||||
|
@ -1035,6 +1039,9 @@
|
||||||
.replace(/(\n|\r|\r\n)/g, '<br>')
|
.replace(/(\n|\r|\r\n)/g, '<br>')
|
||||||
.replace('~~caret~~', '<span class="caret"></span>')
|
.replace('~~caret~~', '<span class="caret"></span>')
|
||||||
.replace(/~~marker~~<br><br>/g, '<span class="marker"></span>');
|
.replace(/~~marker~~<br><br>/g, '<span class="marker"></span>');
|
||||||
|
} else {
|
||||||
|
previewText = converter.makeHtml(text);
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the processing time of the HTML creation.
|
// Calculate the processing time of the HTML creation.
|
||||||
// It's used as the delay time in the event listener.
|
// It's used as the delay time in the event listener.
|
||||||
|
@ -1043,7 +1050,7 @@
|
||||||
|
|
||||||
Ember.run(function() {
|
Ember.run(function() {
|
||||||
pushPreviewHtml(previewText, previewScrollerText);
|
pushPreviewHtml(previewText, previewScrollerText);
|
||||||
if (panels.previewScroller) {
|
if (scrollSyncOn) {
|
||||||
cacheMarkerPositions();
|
cacheMarkerPositions();
|
||||||
cacheCaretMarkerPosition();
|
cacheCaretMarkerPosition();
|
||||||
syncScroll(true);
|
syncScroll(true);
|
||||||
|
@ -1154,14 +1161,14 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
ieSafeSet(panels.preview, previewText);
|
ieSafeSet(panels.preview, previewText);
|
||||||
if (panels.previewScroller) {
|
if (scrollSyncOn) {
|
||||||
ieSafeSet(panels.previewScroller, previewScrollerText);
|
ieSafeSet(panels.previewScroller, previewScrollerText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var nonSuckyBrowserPreviewSet = function (previewText, previewScrollerText) {
|
var nonSuckyBrowserPreviewSet = function (previewText, previewScrollerText) {
|
||||||
panels.preview.innerHTML = previewText;
|
panels.preview.innerHTML = previewText;
|
||||||
if (panels.previewScroller) {
|
if (scrollSyncOn) {
|
||||||
panels.previewScroller.innerHTML = previewScrollerText;
|
panels.previewScroller.innerHTML = previewScrollerText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1213,7 +1220,7 @@
|
||||||
// TODO: make option to disable. We don't need this in discourse
|
// TODO: make option to disable. We don't need this in discourse
|
||||||
// setupEvents(panels.input, applyTimeout);
|
// setupEvents(panels.input, applyTimeout);
|
||||||
|
|
||||||
if (panels.previewScroller) {
|
if (scrollSyncOn) {
|
||||||
setupScrollSync();
|
setupScrollSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue