combine sandbox into commonFramework
a @benmcmahon suggestion
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -1,91 +0,0 @@
|
|||||||
/* global jailed */
|
|
||||||
var printCallback;
|
|
||||||
|
|
||||||
// sends the input to the plugin for evaluation
|
|
||||||
function submit(code, callback) {
|
|
||||||
printCallback = callback;
|
|
||||||
|
|
||||||
// postpone the evaluation until the plugin is initialized
|
|
||||||
plugin.whenConnected(function() {
|
|
||||||
if (requests === 0) {
|
|
||||||
startLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
requests++;
|
|
||||||
plugin.remote.run(code);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// puts the message on the terminal
|
|
||||||
var print = function(cls, msg) {
|
|
||||||
printCallback(cls, msg);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// will restart the plugin if it does not respond
|
|
||||||
var disconnectTimeout = null;
|
|
||||||
var startLoading = function() {
|
|
||||||
disconnectTimeout = setTimeout(disconnect, 3000);
|
|
||||||
};
|
|
||||||
|
|
||||||
var endLoading = function() {
|
|
||||||
clearTimeout(disconnectTimeout);
|
|
||||||
};
|
|
||||||
|
|
||||||
var disconnect = function() {
|
|
||||||
plugin.disconnect();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// interface provided to the plugin
|
|
||||||
var api = {
|
|
||||||
output: function(data) {
|
|
||||||
endLoading();
|
|
||||||
// print('input', data.input);
|
|
||||||
|
|
||||||
if (data.error) {
|
|
||||||
print('Error', data);
|
|
||||||
reset();
|
|
||||||
} else {
|
|
||||||
print(null, data);
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// obtaining absolute path of this script
|
|
||||||
var scripts = document.getElementsByTagName('script');
|
|
||||||
var path = scripts[scripts.length - 1].src
|
|
||||||
.split('?')[0]
|
|
||||||
.split('/')
|
|
||||||
.slice(0, -1)
|
|
||||||
.join('/') + '/';
|
|
||||||
|
|
||||||
var requests;
|
|
||||||
|
|
||||||
// (re)initializes the plugin
|
|
||||||
var reset = function() {
|
|
||||||
requests = 0;
|
|
||||||
plugin = new jailed.Plugin(path + 'plugin.js', api);
|
|
||||||
plugin.whenDisconnected( function() {
|
|
||||||
// give some time to handle the last responce
|
|
||||||
setTimeout( function() {
|
|
||||||
endLoading();
|
|
||||||
console.log('resetting on fatal plugin error');
|
|
||||||
|
|
||||||
if (challengeType === 0) {
|
|
||||||
codeOutput.setValue(
|
|
||||||
'Sorry, your code is either too slow, has a fatal error, ' +
|
|
||||||
'or contains an infinite loop.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
reset();
|
|
||||||
}, 10);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// initialize everything
|
|
||||||
var plugin = null;
|
|
||||||
|
|
||||||
reset();
|
|
@ -14,7 +14,6 @@ block content
|
|||||||
link(rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono")
|
link(rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||||
script(type='text/javascript', src='/js/lib/codemirror/mode/javascript/javascript.js')
|
script(type='text/javascript', src='/js/lib/codemirror/mode/javascript/javascript.js')
|
||||||
script(type='text/javascript', src='/js/lib/jailed/jailed.js')
|
script(type='text/javascript', src='/js/lib/jailed/jailed.js')
|
||||||
script(type='text/javascript', src=rev('/js', 'sandbox.js'))
|
|
||||||
|
|
||||||
.row(ng-controller="pairedWithController")
|
.row(ng-controller="pairedWithController")
|
||||||
.col-xs-12.col-sm-12.col-md-4.col-lg-3
|
.col-xs-12.col-sm-12.col-md-4.col-lg-3
|
||||||
|
@ -14,7 +14,6 @@ block content
|
|||||||
link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono")
|
link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||||
script(src='/js/lib/codemirror/mode/javascript/javascript.js')
|
script(src='/js/lib/codemirror/mode/javascript/javascript.js')
|
||||||
script(src='/js/lib/jailed/jailed.js')
|
script(src='/js/lib/jailed/jailed.js')
|
||||||
script(src=rev('/js', 'sandbox.js'))
|
|
||||||
script(src='/js/lib/codemirror/mode/xml/xml.js')
|
script(src='/js/lib/codemirror/mode/xml/xml.js')
|
||||||
script(src='/js/lib/codemirror/mode/css/css.js')
|
script(src='/js/lib/codemirror/mode/css/css.js')
|
||||||
script(src='/js/lib/codemirror/mode/htmlmixed/htmlmixed.js')
|
script(src='/js/lib/codemirror/mode/htmlmixed/htmlmixed.js')
|
||||||
|
@ -13,7 +13,6 @@ block content
|
|||||||
link(rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono")
|
link(rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono")
|
||||||
script(type='text/javascript', src='/js/lib/codemirror/mode/javascript/javascript.js')
|
script(type='text/javascript', src='/js/lib/codemirror/mode/javascript/javascript.js')
|
||||||
script(type='text/javascript', src='/js/lib/jailed/jailed.js')
|
script(type='text/javascript', src='/js/lib/jailed/jailed.js')
|
||||||
script(type='text/javascript', src=rev('/js', 'sandbox.js'))
|
|
||||||
.row(ng-controller="pairedWithController")
|
.row(ng-controller="pairedWithController")
|
||||||
.col-xs-12.col-sm-12.col-md-4.col-lg-3
|
.col-xs-12.col-sm-12.col-md-4.col-lg-3
|
||||||
.scroll-locker(id = "scroll-locker")
|
.scroll-locker(id = "scroll-locker")
|
||||||
|
Reference in New Issue
Block a user