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,34 +160,76 @@ editor.on("keyup", function () {
delay = setTimeout(updatePreview, 300); 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') { if(typeof prodOrDev !== 'undefined') {
var nodeEnv = prodOrDev === 'production' ? 'http://www.freecodecamp.com' : 'http://localhost:3001'; var nodeEnv = prodOrDev === 'production' ? 'http://www.freecodecamp.com' : 'http://localhost:3001';
if(challengeType === "0")
function updatePreview() { {
editorValueForIFrame = editor.getValue(); function updatePreview() {
var failedCommentTest = false; editorValueForIFrame = editor.getValue();
if (editorValueForIFrame.match(/\<\!\-\-/gi) && editorValueForIFrame.match(/\-\-\>/gi) == null) { var failedCommentTest = false;
failedCommentTest = true; if (editorValueForIFrame.match(/\<\!\-\-/gi) && editorValueForIFrame.match(/\-\-\>/gi) == null) {
failedCommentTest = true;
}
else if (editorValueForIFrame.match(/\<\!\-\-/gi) && editorValueForIFrame.match(/\<\!\-\-/gi).length > editorValueForIFrame.match(/\-\-\>/gi).length) {
failedCommentTest = true;
}
if (failedCommentTest) {
editor.setValue(editor.getValue() + "-->");
editorValueForIFrame = editorValueForIFrame + "-->";
}
safeHTMLRun(false);
} }
else if (editorValueForIFrame.match(/\<\!\-\-/gi) && editorValueForIFrame.match(/\<\!\-\-/gi).length > editorValueForIFrame.match(/\-\-\>/gi).length) {
failedCommentTest = true;
}
if (failedCommentTest) {
editor.setValue(editor.getValue() + "-->");
editorValueForIFrame = editorValueForIFrame + "-->";
}
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
//Here is the issue setTimeout(updatePreview, 300);
preview.open();
//preview.write(libraryIncludes + editor.getValue());
codeStorage.updateStorage();
preview.close();
} }
setTimeout(updatePreview, 300);
} }
/** /**
* "post" methods * "post" methods
@ -256,7 +298,6 @@ if (attempts) {
attempts = 0; attempts = 0;
} }
console.log(challengeType);
if(challengeType !== "0") { if(challengeType !== "0") {
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), { var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
lineNumbers: false, lineNumbers: false,
@ -428,39 +469,45 @@ function bonfireExecute() {
attempts++; attempts++;
ga('send', 'event', 'Challenge', 'ran-code', challenge_Name); ga('send', 'event', 'Challenge', 'ran-code', challenge_Name);
userTests = null; userTests = null;
var userJavaScript = myCodeMirror.getValue(); if(challengeType !== "0"){
var failedCommentTest = false; var userJavaScript = myCodeMirror.getValue();
if (userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\*\//gi) == null) { var failedCommentTest = false;
failedCommentTest = true; if (userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\*\//gi) == null) {
} failedCommentTest = true;
else if (!failedCommentTest && userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\/\*/gi).length > userJavaScript.match(/\*\//gi).length) { }
failedCommentTest = true; else if (!failedCommentTest && userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\/\*/gi).length > userJavaScript.match(/\*\//gi).length) {
} failedCommentTest = true;
userJavaScript = removeComments(userJavaScript); }
userJavaScript = scrapeTests(userJavaScript); userJavaScript = removeComments(userJavaScript);
// simple fix in case the user forgets to invoke their function userJavaScript = scrapeTests(userJavaScript);
// simple fix in case the user forgets to invoke their function
submit(userJavaScript, function (cls, message) { submit(userJavaScript, function (cls, message) {
if (failedCommentTest) { if (failedCommentTest) {
myCodeMirror.setValue(myCodeMirror.getValue() + "*/"); myCodeMirror.setValue(myCodeMirror.getValue() + "*/");
console.log('Caught Unfinished Comment'); console.log('Caught Unfinished Comment');
if(challengeType !== 0)
codeOutput.setValue("Unfinished mulit-line comment"); codeOutput.setValue("Unfinished mulit-line comment");
failedCommentTest = false; failedCommentTest = false;
} }
else if (cls) { else if (cls) {
if(challengeType !== 0)
codeOutput.setValue(message.error); codeOutput.setValue(message.error);
runTests('Error', null); runTests('Error', null);
} else { } else {
if(challengeType !== 0)
codeOutput.setValue(message.output); codeOutput.setValue(message.output);
if(challengeType !== 0)
codeOutput.setValue(codeOutput.getValue().replace(/\\\"/gi, '')); codeOutput.setValue(codeOutput.getValue().replace(/\\\"/gi, ''));
message.input = removeLogs(message.input); message.input = removeLogs(message.input);
runTests(null, message); runTests(null, message);
}
});
}
else {
editorValueForIFrame = editor.getValue();
if (failedCommentTest) {
editor.setValue(editor.getValue() + "-->");
editorValueForIFrame = editorValueForIFrame + "-->";
} }
}); safeHTMLRun(true);
}
} }
$('#submitButton').on('click', function() { $('#submitButton').on('click', function() {

View File

@ -73,7 +73,9 @@ var reset = function() {
setTimeout( function() { setTimeout( function() {
endLoading(); endLoading();
console.log("resetting on fatal plugin error"); console.log("resetting on fatal plugin error");
codeOutput.setValue("Sorry, your code is either too slow, has a fatal error, or contains an infinite loop."); if(challengeType === 0){
codeOutput.setValue("Sorry, your code is either too slow, has a fatal error, or contains an infinite loop.");
}
reset(); reset();
}, 10); }, 10);
}); });