Editor can now load runner automatically

master
Hauke D 7 years ago
parent c3adf73863
commit 6d8fad9b1a

@ -63,7 +63,12 @@ the same level as the Perl editor IFrame(s). The frames communicate
via the "window.postMessage()" mechanism, which is safe for via the "window.postMessage()" mechanism, which is safe for
cross-origin communications and sandboxing. Currently, in order to cross-origin communications and sandboxing. Currently, in order to
conserve memory, a single runner serves multiple "clients", that is, conserve memory, a single runner serves multiple "clients", that is,
the "editor" IFrames below. --> the "editor" IFrames below.
It is also possible to link to perleditor.html directly: if it
detects that it is not running in an IFrame, it will load the runner
on its own (after a very brief delay).
-->
<iframe name="perlrunner" sandbox="allow-scripts" src="perlrunner.html" style="display:none;"></iframe> <iframe name="perlrunner" sandbox="allow-scripts" src="perlrunner.html" style="display:none;"></iframe>

@ -39,6 +39,7 @@ var mergeStdOutErr = 0; // Possible To-Do for Later: could make an options hash
var perlRunner; // the Perl runner iframe found by findPerlRunner() 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()
function makeCM (textarea,plain,ro) { function makeCM (textarea,plain,ro) {
return CodeMirror.fromTextArea( textarea[0], { return CodeMirror.fromTextArea( textarea[0], {
@ -87,18 +88,31 @@ function findPerlRunner () {
buttonBlockers.runnerState = 1; buttonBlockers.runnerState = 1;
updateButtonState(); updateButtonState();
// poll for perlRunner, which gets set by the message listener // poll for perlRunner, which gets set by the message listener
var pollUntil = Date.now() + 10*1000; // milliseconds var warnAt = Date.now() + 15*1000; // milliseconds
var loadIframe = Date.now() + 3*1000; // milliseconds
var pollId; var pollId;
pollId = window.setInterval( function () { pollId = window.setInterval( function () {
if (perlRunner) if (perlRunner)
window.clearInterval(pollId); window.clearInterval(pollId);
else if (!loadedRunnerIframe && self===top && Date.now()>loadIframe) {
console.debug("Perl Editor is attempting to load Perl Runner...");
/* This is a special case: We appear to be the toplevel window,
* and are unable to contact the runner within a fixed amount of time.
* So we assume that someone has linked directly to this page instead
* of loading it in an IFrame, so we'll load the runner ourselves. */
$('<iframe/>',{name:"perlrunner",sandbox:"allow-scripts",
src:"perlrunner.html",style:"display:none;"})
.appendTo('body');
loadedRunnerIframe = true;
}
else { else {
if (window.parent && window.parent.frames["perlrunner"]) if (window.parent && window.parent.frames["perlrunner"])
window.parent.frames["perlrunner"].postMessage( window.parent.frames["perlrunner"].postMessage(
{perlRunnerDiscovery:1}, '*'); {perlRunnerDiscovery:1}, '*');
if ( Date.now()>pollUntil ) { if ( Date.now()>warnAt ) {
$('#runnererrors>pre').text("Perl does not appear to have loaded yet, still waiting..."); $('#runnererrors>pre').text("Perl does not appear to have loaded yet, still waiting...");
$('#runnererrors').show(); $('#runnererrors').show();
warnAt = Date.now() + 5*1000; // milliseconds
} }
} }
}, 100); }, 100);

Loading…
Cancel
Save