diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-01-04 00:02:21 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-01-04 00:02:21 +0900 |
commit | 09116c1ab91677f950b7e4795d7a31324253be6d (patch) | |
tree | 49a5302b7eda3d32c057b0ee0d0e85a54b13c68a /app/assets/javascripts/snippets.es6 | |
parent | ad5967a256dfefe5191013b56f1fc37fdb87e33c (diff) | |
download | poe-09116c1ab91677f950b7e4795d7a31324253be6d.tar.gz |
🔪
Diffstat (limited to 'app/assets/javascripts/snippets.es6')
-rw-r--r-- | app/assets/javascripts/snippets.es6 | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/assets/javascripts/snippets.es6 b/app/assets/javascripts/snippets.es6 new file mode 100644 index 0000000..d3c3be1 --- /dev/null +++ b/app/assets/javascripts/snippets.es6 @@ -0,0 +1,53 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. + +const codeField = document.querySelector("#code-field"); +if (codeField !== null) { + const origTextarea = codeField.querySelector("textarea[name=\"snippet[code]\"]"); + const codeMirror = CodeMirror.fromTextArea(origTextarea, { + mode: "ruby", + lineNumbers: true, + }); + codeMirror.on("change", cm => cm.save()); +} + +const agg = (elm, n) => { + if (!n) n = 0; + n++; + setTimeout(() => { + $.ajax({ + type: "GET", + url: "/results/" + elm.getAttribute("data-id"), + dataType: "text", + success: (text, st) => { + console.log(text); + elm.outerHTML = text; + if (n < 3) agg(elm, n); + } + }); + }, 1000); +}; + +const refresher = () => { + const runnings = document.querySelectorAll(".result-item[data-status=running]"); + for (var i = 0, len = runnings.length; i < len; i++) { + agg(runnings[i]); + } +}; +refresher(); + +const notrans = document.querySelectorAll(".result-item[data-status=notran]"); +const snippet_id = document.querySelector("#snippet-id").innerHTML; +for (var i = 0, len = notrans.length; i < len; i++) { + const elm = notrans[i]; + $.ajax({ + type: "POST", + url: "/results/run", + dataType: "text", + data: { compiler_id: elm.getAttribute("data-compiler-id"), snippet_id: snippet_id }, + success: (text, st) => { + console.log(text); + elm.outerHTML = text; + } + }); +} |