From f082b1b1b4117d389c4cba729d3aaa69e83da6f0 Mon Sep 17 00:00:00 2001 From: erjanmx Date: Tue, 6 Mar 2018 17:36:00 +0300 Subject: [PATCH] Add keyboard command Check for status code --- src/resources/assets/js/app.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/resources/assets/js/app.js b/src/resources/assets/js/app.js index 236d651..5725267 100644 --- a/src/resources/assets/js/app.js +++ b/src/resources/assets/js/app.js @@ -6,6 +6,7 @@ editor.on('change', function () { localStorage.setItem('live-tinker', editor.getValue()); }); +// Add keyboard commands editor.commands.addCommand({ name: 'runAll', bindKey: {win: 'Ctrl-Enter', mac: 'Command-Enter'}, @@ -13,16 +14,28 @@ editor.commands.addCommand({ sendCode(editor.getValue()) } }); +editor.commands.addCommand({ + name: 'runSelected', + bindKey: {win: 'Ctrl-Shift-Enter', mac: 'Command-Shift-Enter'}, + exec: function(editor) { + sendCode(editor.getSelectedText()) + } +}); function sendCode(text) { var xhr = new XMLHttpRequest(); xhr.open('POST', '/live-tinker/ajax'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onload = function() { - document.Response.document.body.innerHTML = xhr.responseText; + var response = xhr.responseText; + if (xhr.status === 200) { + response = '
' + response + '
'; + } + + document.Response.document.body.innerHTML = response; changeButtonsState(false); }; - xhr.send('code=' + encodeURIComponent(text)); + xhr.send('c=' + encodeURIComponent(text)); changeButtonsState(true); document.Response.document.body.innerHTML = '';