Merging of the framework: Ready for QA run

This commit is contained in:
benmcmahon100
2015-08-24 01:16:15 +01:00
parent 390469a1b6
commit f06d6ca650
2 changed files with 101 additions and 52 deletions

View File

@ -160,9 +160,58 @@ editor.on("keyup", function () {
delay = setTimeout(updatePreview, 300);
});
function safeHTMLRun(test){
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
if(editor.getValue().match(/\<script\>/gi) !== null) {
var s = editor.getValue().split(/\<\s?script\s?\>/gi)[1].split(/\<\s?\/\s?script\s?\>/gi)[0];
submit(
s, function (cls, message) {
if (cls) {
console.log(message.error);
$('#mainEditorPanel').html("<div class = \"runTimeError\">" + message.error + "</div>" + $('#mainEditorPanel').html());
$('.runTimeError').hide().fadeIn(function(){
setTimeout(function(){
$(this).remove();
}, 3000)
});
} else {
if(test){
preview.open();
preview.write(libraryIncludes + editor.getValue() +iFrameScript);
codeStorage.updateStorage();
preview.close();
}
else{
preview.open();
preview.write(libraryIncludes + editor.getValue());
codeStorage.updateStorage();
preview.close();
}
}
}
);
}
else {
if(test){
preview.open();
preview.write(libraryIncludes + editor.getValue() +iFrameScript);
codeStorage.updateStorage();
preview.close();
}
else{
preview.open();
preview.write(libraryIncludes + editor.getValue());
codeStorage.updateStorage();
preview.close();
}
}
}
if(typeof prodOrDev !== 'undefined') {
var nodeEnv = prodOrDev === 'production' ? 'http://www.freecodecamp.com' : 'http://localhost:3001';
if(challengeType === "0")
{
function updatePreview() {
editorValueForIFrame = editor.getValue();
var failedCommentTest = false;
@ -176,19 +225,12 @@ if(typeof prodOrDev !== 'undefined') {
editor.setValue(editor.getValue() + "-->");
editorValueForIFrame = editorValueForIFrame + "-->";
}
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
//Here is the issue
preview.open();
//preview.write(libraryIncludes + editor.getValue());
codeStorage.updateStorage();
preview.close();
safeHTMLRun(false);
}
setTimeout(updatePreview, 300);
}
}
/**
* "post" methods
*/
@ -256,7 +298,6 @@ if (attempts) {
attempts = 0;
}
console.log(challengeType);
if(challengeType !== "0") {
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
lineNumbers: false,
@ -428,6 +469,7 @@ function bonfireExecute() {
attempts++;
ga('send', 'event', 'Challenge', 'ran-code', challenge_Name);
userTests = null;
if(challengeType !== "0"){
var userJavaScript = myCodeMirror.getValue();
var failedCommentTest = false;
if (userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\*\//gi) == null) {
@ -444,24 +486,29 @@ function bonfireExecute() {
if (failedCommentTest) {
myCodeMirror.setValue(myCodeMirror.getValue() + "*/");
console.log('Caught Unfinished Comment');
if(challengeType !== 0)
codeOutput.setValue("Unfinished mulit-line comment");
failedCommentTest = false;
}
else if (cls) {
if(challengeType !== 0)
codeOutput.setValue(message.error);
runTests('Error', null);
} else {
if(challengeType !== 0)
codeOutput.setValue(message.output);
if(challengeType !== 0)
codeOutput.setValue(codeOutput.getValue().replace(/\\\"/gi, ''));
message.input = removeLogs(message.input);
runTests(null, message);
}
});
}
else {
editorValueForIFrame = editor.getValue();
if (failedCommentTest) {
editor.setValue(editor.getValue() + "-->");
editorValueForIFrame = editorValueForIFrame + "-->";
}
safeHTMLRun(true);
}
}
$('#submitButton').on('click', function() {
bonfireExecute();

View File

@ -73,7 +73,9 @@ var reset = function() {
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);
});