From: Jean Privat Date: Thu, 23 Jun 2016 18:18:20 +0000 (-0400) Subject: nitlight_aas: ajax update the content X-Git-Url: http://nitlanguage.org nitlight_aas: ajax update the content Signed-off-by: Jean Privat --- diff --git a/src/examples/nitlight_as_a_service.nit b/src/examples/nitlight_as_a_service.nit index 808837a..f0847f9 100644 --- a/src/examples/nitlight_as_a_service.nit +++ b/src/examples/nitlight_as_a_service.nit @@ -120,6 +120,19 @@ class HighlightAction var hlcode = null if code != null then hlcode = hightlightcode(hl, code) + if http_request.post_args.get_or_null("ajax") == "true" and hlcode != null then + page.add hlcode.code_mirror_update + page.add """ + document.getElementById("lightcode").innerHTML = "{{{hl.html.write_to_string.escape_to_c}}}"; + nitmessage(); + """ + + var response = new HttpResponse(200) + response.header["Content-Type"] = "application/javascript" + response.body = page.write_to_string + return response + end + page.add """ {{{hl.head_content}}} @@ -147,6 +160,8 @@ class HighlightAction page.add "
  • {m.location.as(not null)}: {m.text}
  • " end page.add "" + else + page.add "
    " end page.add hl.foot_content @@ -170,6 +185,20 @@ class HighlightAction var widgets = []; nitmessage(); + function updatePage() { + $.post("", { ajax: true, code: editor.getValue()}, function(data) { + eval(data); + $(".popupable").popover({html:true, placement:'top'}); + }); + } + + var waiting; + editor.on("change", function() { + clearTimeout(waiting); + waiting = setTimeout(updatePage, 500); + }); + waiting = setTimeout(updatePage, 500); + """