throttle markdown preview
parent
d49e6deffb
commit
dc80b6b11f
|
@ -110,6 +110,10 @@ define([
|
|||
return stringify(obj);
|
||||
};
|
||||
|
||||
var drawPreview = Cryptpad.throttle(function () {
|
||||
DiffMd.apply(DiffMd.render(editor.getValue()), $preview);
|
||||
}, 150);
|
||||
|
||||
var onLocal = config.onLocal = function () {
|
||||
if (initializing) { return; }
|
||||
if (isHistoryMode) { return; }
|
||||
|
@ -117,7 +121,7 @@ define([
|
|||
|
||||
editor.save();
|
||||
|
||||
DiffMd.apply(DiffMd.render(editor.getValue()), $preview);
|
||||
drawPreview();
|
||||
|
||||
var textValue = canonicalize(CodeMirror.$textarea.val());
|
||||
var shjson = stringifyInner(textValue);
|
||||
|
@ -324,14 +328,13 @@ define([
|
|||
var hjson = JSON.parse(shjson);
|
||||
var remoteDoc = hjson.content;
|
||||
|
||||
DiffMd.apply(DiffMd.render(remoteDoc), $preview);
|
||||
|
||||
var highlightMode = hjson.highlightMode;
|
||||
if (highlightMode && highlightMode !== APP.highlightMode) {
|
||||
CodeMirror.setMode(highlightMode, onModeChanged);
|
||||
}
|
||||
|
||||
CodeMirror.setValueAndCursor(oldDoc, remoteDoc, TextPatcher);
|
||||
drawPreview();
|
||||
|
||||
if (!readOnly) {
|
||||
var textValue = canonicalize(CodeMirror.$textarea.val());
|
||||
|
|
|
@ -122,5 +122,14 @@ define([], function () {
|
|||
xhr.send(null);
|
||||
};
|
||||
|
||||
Util.throttle = function (f, ms) {
|
||||
var to;
|
||||
var g = function () {
|
||||
window.clearTimeout(to);
|
||||
to = window.setTimeout(f, ms);
|
||||
};
|
||||
return g;
|
||||
};
|
||||
|
||||
return Util;
|
||||
});
|
||||
|
|
|
@ -71,6 +71,7 @@ define([
|
|||
common.bytesToMegabytes = Util.bytesToMegabytes;
|
||||
common.bytesToKilobytes = Util.bytesToKilobytes;
|
||||
common.fetch = Util.fetch;
|
||||
common.throttle = Util.throttle;
|
||||
|
||||
// import hash utilities for export
|
||||
var createRandomHash = common.createRandomHash = Hash.createRandomHash;
|
||||
|
|
Loading…
Reference in New Issue