From 963a435ae1e9248b42b4665acf106dcffa549678 Mon Sep 17 00:00:00 2001 From: Yukai Huang Date: Sat, 8 Oct 2016 20:02:30 +0800 Subject: Resolve dependency module requiring * es5 style module exports * remove script tag require * webpack config ProvidePlugin Note that this commit only fix JavaScript module loading runtime error. --- public/js/syncscroll.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'public/js/syncscroll.js') diff --git a/public/js/syncscroll.js b/public/js/syncscroll.js index 96663f77..444cdebd 100644 --- a/public/js/syncscroll.js +++ b/public/js/syncscroll.js @@ -1,5 +1,8 @@ // Inject line numbers for sync scroll. +var extra = require('./extra'); +var md = extra.md; + function addPart(tokens, idx) { if (tokens[idx].map && tokens[idx].level === 0) { var startline = tokens[idx].map[0] + 1; @@ -71,7 +74,7 @@ md.renderer.rules.fence = function (tokens, idx, options, env, self) { if (highlighted.indexOf(' scrollInfo.clientHeight && scrollTop >= preLastLinePos) { posTo = preLastLineHeight; topDiffPercent = (scrollTop - preLastLinePos) / (viewBottom - preLastLinePos); @@ -281,7 +286,7 @@ function syncScrollToEdit(event, preventAnimate) { posToNextDiff = textHeight * lineDiff * topDiffPercent; posTo += Math.ceil(posToNextDiff); } - + if (preventAnimate) { editArea.scrollTop(posTo); } else { @@ -292,7 +297,7 @@ function syncScrollToEdit(event, preventAnimate) { scrollTop: posTo }, duration, "linear"); } - + viewScrolling = true; clearTimeout(viewScrollingTimer); viewScrollingTimer = setTimeout(viewScrollingTimeoutInner, duration * 1.5); @@ -322,7 +327,7 @@ function syncScrollToView(event, preventAnimate) { return; } if (viewScrolling) return; - + var lineNo, posTo; var topDiffPercent, posToNextDiff; var scrollInfo = editor.getScrollInfo(); @@ -341,7 +346,7 @@ function syncScrollToView(event, preventAnimate) { posToNextDiff = (scrollMap[lineNo + 1] - posTo) * topDiffPercent; posTo += Math.floor(posToNextDiff); } - + if (preventAnimate) { viewArea.scrollTop(posTo); } else { @@ -352,7 +357,7 @@ function syncScrollToView(event, preventAnimate) { scrollTop: posTo }, duration, "linear"); } - + editScrolling = true; clearTimeout(editScrollingTimer); editScrollingTimer = setTimeout(editScrollingTimeoutInner, duration * 1.5); @@ -360,4 +365,10 @@ function syncScrollToView(event, preventAnimate) { function editScrollingTimeoutInner() { editScrolling = false; -} \ No newline at end of file +} + +module.exports = { + setupSyncAreas: setupSyncAreas, + clearMap: clearMap, + syncScrollToEdit: syncScrollToEdit +}; -- cgit v1.2.3