function sendMarkdown() {
    if (document.getElementById('editor').value.trim().length == 0) { // if #editor is empty
        document.getElementById('previewValue').innerHTML = "";
        document.getElementById('toc').innerHTML = "";
        document.getElementById('comments').innerHTML = "";
        annotation = [];

    } else {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var response = xhttp.responseXML;
                $('#preview').off('scroll');
                document.getElementById('previewValue').innerHTML = response.getElementsByTagName("preview")[0].innerHTML;
                document.getElementById('toc').innerHTML = response.getElementsByTagName('toc')[0].innerHTML;
                document.getElementById('comments').innerHTML = response.getElementsByTagName('comments')[0].innerHTML;
                var respAnnotation = response.getElementsByTagName('annotations')[0].innerHTML;
                if (respAnnotation == '') {
                    annotation = [];
                } else {
                    annotation = respAnnotation.split(',,,');
                }

                if (loadMermaid) {
                    mermaid.init(undefined, ".mermaid");
                }

                $('textarea#editor').scroll(); // after set all data sync scroll position
            }
        };
        sendAjax("False", xhttp, []);
    }
}
/**
 * Using ajax to communicate with server. Send on server content of #editor and from response get preview, table of
 * content, table of comments and list of annotations. This values are set to page elements.
 */
Using ajax to communicate with server. Send on server content of #editor and from response get preview, table of
content, table of comments and list of annotations. This values are set to page elements.
Using ajax to communicate with server . Send on server content of #editor and from response get preview table of content table of comments and list of annotations . This values are set to page elements .
function sendMarkdown() {
    if (document.getElementById('editor').value.trim().length == 0) { 
        document.getElementById('previewValue').innerHTML = "";
        document.getElementById('toc').innerHTML = "";
        document.getElementById('comments').innerHTML = "";
        annotation = [];
    } else {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var response = xhttp.responseXML;
                $('#preview').off('scroll');
                document.getElementById('previewValue').innerHTML = response.getElementsByTagName("preview")[0].innerHTML;
                document.getElementById('toc').innerHTML = response.getElementsByTagName('toc')[0].innerHTML;
                document.getElementById('comments').innerHTML = response.getElementsByTagName('comments')[0].innerHTML;
                var respAnnotation = response.getElementsByTagName('annotations')[0].innerHTML;
                if (respAnnotation == '') {
                    annotation = [];
                } else {
                    annotation = respAnnotation.split(',,,');
                }
                if (loadMermaid) {
                    mermaid.init(undefined, ".mermaid");
                }
                $('textarea#editor').scroll(); 
            }
        };
        sendAjax("False", xhttp, []);
    }
}
function sendMarkdown ( ) { if ( document . getElementById ( 'editor' ) . value . trim ( ) . length == 0 ) { document . getElementById ( 'previewValue' ) . innerHTML = "" ; document . getElementById ( 'toc' ) . innerHTML = "" ; document . getElementById ( 'comments' ) . innerHTML = "" ; annotation = [ ] ; } else { var xhttp = new XMLHttpRequest ( ) ; xhttp . onreadystatechange = function ( ) { if ( xhttp . readyState == 4 && xhttp . status == 200 ) { var response = xhttp . responseXML ; $ ( '#preview' ) . off ( 'scroll' ) ; document . getElementById ( 'previewValue' ) . innerHTML = response . getElementsByTagName ( "preview" ) [ 0 ] . innerHTML ; document . getElementById ( 'toc' ) . innerHTML = response . getElementsByTagName ( 'toc' ) [ 0 ] . innerHTML ; document . getElementById ( 'comments' ) . innerHTML = response . getElementsByTagName ( 'comments' ) [ 0 ] . innerHTML ; var respAnnotation = response . getElementsByTagName ( 'annotations' ) [ 0 ] . innerHTML ; if ( respAnnotation == '' ) { annotation = [ ] ; } else { annotation = respAnnotation . split ( ',,,' ) ; } if ( loadMermaid ) { mermaid . init ( undefined , ".mermaid" ) ; } $ ( 'textarea#editor' ) . scroll ( ) ; } } ; sendAjax ( "False" , xhttp , [ ] ) ; } }
Using ajax to communicate with server.
Using ajax to communicate with server .
// if #editor is empty // after set all data sync scroll position