Do not reload css on every message

This commit is contained in:
Igor Shymko 2016-12-05 13:36:57 +02:00
parent c415d7e4a7
commit c197aa51cc
2 changed files with 3 additions and 11 deletions

View File

@ -88,6 +88,8 @@
(preview-file (concat dir-of-buffer-to-preview markdown-preview-file-name)))
(with-temp-file preview-file
(insert-file-contents markdown-preview--preview-template)
(if (search-forward "${MD_STYLE}" nil t)
(replace-match markdown-preview-style t))
(if (search-forward "${WS_HOST}" nil t)
(replace-match markdown-preview-host t))
(if (search-forward "${WS_PORT}" nil t)
@ -157,9 +159,6 @@
(websocket-send-text websocket
(concat
"<div>"
"<span id='style'>"
markdown-preview-style
"</span>"
"<span id='position-percentage'>"
mark-position-percent
"</span>"

View File

@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
<title>Markdown preview</title>
<link href="http://thomasf.github.io/solarized-css/solarized-dark.min.css" rel="stylesheet"></link>
<link href="${MD_STYLE}" rel="stylesheet"></link>
<style>
code.json {
line-height: 1.2em;
@ -26,7 +26,6 @@
console.log('Code: ' + event.code + ' reason: ' + event.reason);
};
socket.onmessage = function(event) {
loadCSS($(event.data).find("#style").text());
$("#markdown-body").html($(event.data).find("#content").html());
var scroll = $(document).height() * ($(event.data).find("#position-percentage").html() / 100);
$("html, body").animate({ scrollTop: scroll }, 600);
@ -34,12 +33,6 @@
socket.onerror = function(error) {
alert("Error: " + error.message);
};
loadCSS = function(href) {
var cssLink = $("<link rel='stylesheet' type='text/css' href='"+href+"'>");
$("link[rel='stylesheet']").remove();
$("head").append(cssLink);
};
})(jQuery);
</script>
</head>