From 3d90c22fe7951a68e38fa1de59a4d9f3bf63d7a1 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Fri, 19 Oct 2018 19:28:39 +0200 Subject: [PATCH] Added "autorun" option --- web/democode/demo.html | 7 +++++++ web/democode/perleditor.html | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/web/democode/demo.html b/web/democode/demo.html index 5d973bc..e691d7c 100644 --- a/web/democode/demo.html +++ b/web/democode/demo.html @@ -171,6 +171,12 @@ this will not work. Additional options: Setting "mergeStdOutErr" to a true value causes STDOUT and STDERR output to be output together, similar to the way 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. --> @@ -186,6 +192,7 @@ document.getElementById('perl2').src = { fn: "other.txt", text: "Hello, World!" }, ], outputs: [ "vowels.txt" ], + autorun: true, } )); //iFrameResize({checkOrigin:false}, document.getElementById('perl2')); diff --git a/web/democode/perleditor.html b/web/democode/perleditor.html index 0b2cba7..2e55d09 100644 --- a/web/democode/perleditor.html +++ b/web/democode/perleditor.html @@ -44,6 +44,7 @@ var perlRunner; // the Perl runner iframe found by findPerlRunner() var buttonBlockers = {}; // for updateButtonState() var lastExitStatus; // for runnerState() var loadedRunnerIframe = false; // for findPerlRunner() +var autoRunPerl = false; // for the message listener function makeCM (textarea,plain,ro) { return CodeMirror.fromTextArea( textarea[0], { @@ -129,6 +130,10 @@ window.addEventListener('message', function (event) { perlRunner = event.source; delete buttonBlockers.runnerState; updateButtonState(); + if (autoRunPerl) { + autoRunPerl = false; + $('#runperl').click(); + } } else if ( data.perlRunnerState=="Ended" ) { if ('exitStatus' in data) @@ -418,6 +423,17 @@ $(function () { 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 $('#runperl').click( function () { clearStdOutput(); @@ -437,6 +453,7 @@ $(function () { var data = getFileData(); if (!data) return; delete data.argv; + if (!autorunstate.text().match(/without/i)) data.autorun=true; var loc = new URL(window.location); loc.hash = encodeURIComponent(JSON.stringify(data)); copyit(loc); @@ -444,6 +461,7 @@ $(function () { $('#copyjson').click(function () { var data = getFileData(); if (!data) return; + if (!autorunstate.text().match(/without/i)) data.autorun=true; copyit(JSON.stringify(data, null, "\t")); }); @@ -497,6 +515,8 @@ $(function () {   Copy URL / JSON + (with + autorun)