Rework onmessage

This commit is contained in:
Bálint Bokros 2017-11-27 19:01:32 +01:00
parent fac9202b3d
commit 18c8f45a19

View File

@ -1,5 +1,9 @@
let ws = new WebSocket('ws://' + document.location.host + '/ws'); let ws = new WebSocket('ws://' + document.location.host + '/ws');
let converter = new showdown.Converter();
hljs.initHighlightingOnLoad();
$('#container').on('click', '.anchor', ( function (event) { $('#container').on('click', '.anchor', ( function (event) {
let anchorName = $(this).attr('id').replace('_event', ''); let anchorName = $(this).attr('id').replace('_event', '');
@ -37,5 +41,15 @@ ws.onopen = function () {
ws.onmessage = function (messageEvent) { ws.onmessage = function (messageEvent) {
let message = JSON.parse(messageEvent.data); let message = JSON.parse(messageEvent.data);
$('#' + message['anchor']).text(message['data']); console.log('Receiving: ');
console.log(message);
let $anchor = $('#' + message['anchor']);
if (message['anchor'] === 'anchor_webide') {
let code = hljs.highlightAuto(message['data']);
$anchor.html(code.value);
}
else {
let formatted_message = converter.makeHtml(message['data']);
$anchor.html(formatted_message);
}
}; };