Merge pull request #2228 from velesin/markdown_editor_clean_up
Markdown Editor clean up.
This commit is contained in:
commit
5b602cc043
|
@ -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;
|
||||
};
|
||||
|
||||
if (scrollSyncOn) {
|
||||
var prevScrollPosition = $(panels.input).scrollTop();
|
||||
var caretMarkerPosition = 0;
|
||||
var markerPositions;
|
||||
if (panels.previewScroller) {
|
||||
markerPositions = {
|
||||
var markerPositions = {
|
||||
scroller: [0, paneContentHeight(panels.previewScroller)],
|
||||
preview: [0, paneContentHeight(panels.preview)]
|
||||
};
|
||||
|
@ -1020,6 +1020,10 @@
|
|||
|
||||
var prevTime = new Date().getTime();
|
||||
|
||||
var previewText;
|
||||
var previewScrollerText;
|
||||
|
||||
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");
|
||||
|
@ -1035,6 +1039,9 @@
|
|||
.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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue