From c7ebffe8313297ab27497cf49b34af47272cf547 Mon Sep 17 00:00:00 2001 From: adevezin Date: Sun, 9 Oct 2022 17:11:08 -0400 Subject: [PATCH] Fix submit of code by adding language --- .../swiftplugin/static/js/src/swiftplugin.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/swiftplugin/swiftplugin/static/js/src/swiftplugin.js b/swiftplugin/swiftplugin/static/js/src/swiftplugin.js index 6efee18..500de8d 100644 --- a/swiftplugin/swiftplugin/static/js/src/swiftplugin.js +++ b/swiftplugin/swiftplugin/static/js/src/swiftplugin.js @@ -9,10 +9,16 @@ function SwiftPluginXBlock(runtime, element) { var solutionCodeMirror = null; const run_btn = document.getElementById('run-btn'); - run_btn.onclick = function (eventObject) { + + function getCodeAndMode() { var user_code = myCodeMirror.getValue() - var code_mode = myCodeMirror.getMode() + var code_mode = myCodeMirror.getMode() var mode = code_mode.helperType ? code_mode.helperType : code_mode.name; + return {user_code, mode}; + } + + run_btn.onclick = function (eventObject) { + const {user_code, mode} = getCodeAndMode(); $.ajax({ type: "POST", url: handlerUrl, @@ -24,11 +30,11 @@ function SwiftPluginXBlock(runtime, element) { const submit_btn = document.getElementById('submit-btn'); submit_btn.onclick = function (eventObject) { - var user_code = myCodeMirror.getValue(); + const {user_code, mode} = getCodeAndMode(); $.ajax({ type: "POST", url: handlerUrl, - data: JSON.stringify({type: 'submit', code: user_code}), + data: JSON.stringify({type: 'submit', code: user_code, language: mode}), success: updateResponse }); }