Files
freeCodeCamp/client/sandbox.js
Berkeley Martinez 306c441ae7 add revisioning to js/css files to break caching
This moves the location of javascript files, commonFramework,
iFrameScript, sandbox, plugin, and all the less files.
On gulp or gulp build these files are moved and revisioned.
Places where they are references in jade/html are now removed and
replaced with the use of a helper function `rev`. This function will
take the required file and return a string referencing the revisioned
file. This should alleviate the need for hard refreshing and will break
caches when files change, so fixes for firefox caching issue as well.

NOTE: @benmcmahon @quincylarson, This means files will need to be build
on the server in production before doing a server restart/reload
In production: 'npm run build' To build and revision js/css files

`gulp` and `gulp build` will used in development

npm install also needs to be run in production on initial deploy
2015-08-26 23:30:33 -07:00

90 lines
1.9 KiB
JavaScript

var printCallback;
// sends the input to the plugin for evaluation
var submit = function(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();