Commit 97b06b16 authored by Sli's avatar Sli

core: add delay on live preview for MarkdownInput to avoid making too much request to the API

parent 19c1361e
Pipeline #1672 passed with stage
in 13 minutes
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script src="{{ statics.js }}"> </script> <script src="{{ statics.js }}"> </script>
<script type="text/javascript"> <script type="text/javascript">
var css = "{{ statics.css }}"; var css = "{{ statics.css }}";
var lastAPICall;
// Only import the css once // Only import the css once
if (!document.head.innerHTML.includes(css)){ if (!document.head.innerHTML.includes(css)){
...@@ -40,7 +41,6 @@ ...@@ -40,7 +41,6 @@
}).done(function (msg) { }).done(function (msg) {
preview.innerHTML = msg; preview.innerHTML = msg;
}); });
return preview.innerHTML;
} }
// Pretty markdown input // Pretty markdown input
...@@ -48,7 +48,11 @@ ...@@ -48,7 +48,11 @@
element: document.getElementById("{{ widget.attrs.id }}"), element: document.getElementById("{{ widget.attrs.id }}"),
spellChecker: false, spellChecker: false,
previewRender: function(plainText, preview){ // Async method previewRender: function(plainText, preview){ // Async method
return customMarkdownParser(plainText, preview); clearTimeout(lastAPICall);
lastAPICall = setTimeout(function (plainText, preview){
customMarkdownParser(plainText, preview);
}, 300, plainText, preview);
return preview.innerHTML;
}, },
// showIcons: ["code", "table", "clean-block"], // showIcons: ["code", "table", "clean-block"],
toolbar: [ toolbar: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment