Added "autorun" option

master
Hauke D 7 years ago
parent 1381ced6fe
commit 3d90c22fe7

@ -171,6 +171,12 @@ this will not work.
Additional options: Setting "mergeStdOutErr" to a true value causes Additional options: Setting "mergeStdOutErr" to a true value causes
STDOUT and STDERR output to be output together, similar to the way STDOUT and STDERR output to be output together, similar to the way
they would be on the console. they would be on the console.
If you set the "autorun" option, the editor will attempt to run the
script as soon as the runner is ready. *WARNING:* If you have
multiple editors embedded in the page, *do not* enable "autorun"
for more than one editor, as otherwise you will likely trigger a
race condition, resulting in an error being shown to the user.
--> -->
<iframe id="perl2" sandbox="allow-scripts" class="perleditor" style="height:42em;"></iframe> <iframe id="perl2" sandbox="allow-scripts" class="perleditor" style="height:42em;"></iframe>
@ -186,6 +192,7 @@ document.getElementById('perl2').src =
{ fn: "other.txt", text: "Hello, World!" }, { fn: "other.txt", text: "Hello, World!" },
], ],
outputs: [ "vowels.txt" ], outputs: [ "vowels.txt" ],
autorun: true,
} )); } ));
//iFrameResize({checkOrigin:false}, document.getElementById('perl2')); //iFrameResize({checkOrigin:false}, document.getElementById('perl2'));
</script> </script>

@ -44,6 +44,7 @@ var perlRunner; // the Perl runner iframe found by findPerlRunner()
var buttonBlockers = {}; // for updateButtonState() var buttonBlockers = {}; // for updateButtonState()
var lastExitStatus; // for runnerState() var lastExitStatus; // for runnerState()
var loadedRunnerIframe = false; // for findPerlRunner() var loadedRunnerIframe = false; // for findPerlRunner()
var autoRunPerl = false; // for the message listener
function makeCM (textarea,plain,ro) { function makeCM (textarea,plain,ro) {
return CodeMirror.fromTextArea( textarea[0], { return CodeMirror.fromTextArea( textarea[0], {
@ -129,6 +130,10 @@ window.addEventListener('message', function (event) {
perlRunner = event.source; perlRunner = event.source;
delete buttonBlockers.runnerState; delete buttonBlockers.runnerState;
updateButtonState(); updateButtonState();
if (autoRunPerl) {
autoRunPerl = false;
$('#runperl').click();
}
} }
else if ( data.perlRunnerState=="Ended" ) { else if ( data.perlRunnerState=="Ended" ) {
if ('exitStatus' in data) if ('exitStatus' in data)
@ -418,6 +423,17 @@ $(function () {
setupOutputFile(); setupOutputFile();
}); });
// autorun option
if (hash["autorun"])
autoRunPerl = true;
var autorunstate = $('#autorunstate');
$('#autoruntoggle').click(function () {
// the text keeps state (bit of a hack, I know)
autorunstate.text(
autorunstate.text().match(/without/i)
? "with" : "without" );
});
// "run perl" button // "run perl" button
$('#runperl').click( function () { $('#runperl').click( function () {
clearStdOutput(); clearStdOutput();
@ -437,6 +453,7 @@ $(function () {
var data = getFileData(); var data = getFileData();
if (!data) return; if (!data) return;
delete data.argv; delete data.argv;
if (!autorunstate.text().match(/without/i)) data.autorun=true;
var loc = new URL(window.location); var loc = new URL(window.location);
loc.hash = encodeURIComponent(JSON.stringify(data)); loc.hash = encodeURIComponent(JSON.stringify(data));
copyit(loc); copyit(loc);
@ -444,6 +461,7 @@ $(function () {
$('#copyjson').click(function () { $('#copyjson').click(function () {
var data = getFileData(); var data = getFileData();
if (!data) return; if (!data) return;
if (!autorunstate.text().match(/without/i)) data.autorun=true;
copyit(JSON.stringify(data, null, "\t")); copyit(JSON.stringify(data, null, "\t"));
}); });
@ -497,6 +515,8 @@ $(function () {
&nbsp; &nbsp;
<span id="copyurl" class="fakelink">Copy URL</span> <span id="copyurl" class="fakelink">Copy URL</span>
/ <span id="copyjson" class="fakelink">JSON</span> / <span id="copyjson" class="fakelink">JSON</span>
(<span id="autorunstate">with</span>
<span id="autoruntoggle" class="fakelink">autorun</span>)
</span> </span>
</div> </div>
</div> </div>

Loading…
Cancel
Save