mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 11:52:54 +00:00 
			
		
		
		
	Rework onmessage
This commit is contained in:
		@@ -1,5 +1,9 @@
 | 
			
		||||
let ws = new WebSocket('ws://' + document.location.host + '/ws');
 | 
			
		||||
 | 
			
		||||
let converter = new showdown.Converter();
 | 
			
		||||
 | 
			
		||||
hljs.initHighlightingOnLoad();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
$('#container').on('click', '.anchor', ( function (event) {
 | 
			
		||||
    let anchorName = $(this).attr('id').replace('_event', '');
 | 
			
		||||
@@ -37,5 +41,15 @@ ws.onopen = function () {
 | 
			
		||||
 | 
			
		||||
ws.onmessage = function (messageEvent) {
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user