Skip to content

Commit

Permalink
Merging of the framework: Ready for QA run
Browse files Browse the repository at this point in the history
  • Loading branch information
benmcmahon100 committed Aug 24, 2015
1 parent 390469a commit f06d6ca
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 53 deletions.
151 changes: 99 additions & 52 deletions public/js/lib/coursewares/commonFrameWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,76 @@ editor.on("keyup", function () {
delay = setTimeout(updatePreview, 300);
});

if(typeof prodOrDev !== 'undefined') {
var nodeEnv = prodOrDev === 'production' ? 'http://www.freecodecamp.com' : 'http://localhost:3001';

function updatePreview() {
editorValueForIFrame = editor.getValue();
var failedCommentTest = false;
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;
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();
}
if (failedCommentTest) {
editor.setValue(editor.getValue() + "-->");
editorValueForIFrame = editorValueForIFrame + "-->";
else{
preview.open();
preview.write(libraryIncludes + editor.getValue());
codeStorage.updateStorage();
preview.close();
}
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
}
}

//Here is the issue
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;
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);
}

preview.open();
//preview.write(libraryIncludes + editor.getValue());
codeStorage.updateStorage();
preview.close();
setTimeout(updatePreview, 300);
}

setTimeout(updatePreview, 300);
}
/**
* "post" methods
Expand Down Expand Up @@ -256,7 +298,6 @@ if (attempts) {
attempts = 0;
}

console.log(challengeType);
if(challengeType !== "0") {
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), {
lineNumbers: false,
Expand Down Expand Up @@ -428,39 +469,45 @@ function bonfireExecute() {
attempts++;
ga('send', 'event', 'Challenge', 'ran-code', challenge_Name);
userTests = null;
var userJavaScript = myCodeMirror.getValue();
var failedCommentTest = false;
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;
}
userJavaScript = removeComments(userJavaScript);
userJavaScript = scrapeTests(userJavaScript);
// simple fix in case the user forgets to invoke their function

submit(userJavaScript, function (cls, message) {
if (failedCommentTest) {
myCodeMirror.setValue(myCodeMirror.getValue() + "*/");
console.log('Caught Unfinished Comment');
if(challengeType !== 0)
codeOutput.setValue("Unfinished mulit-line comment");
failedCommentTest = false;
if(challengeType !== "0"){
var userJavaScript = myCodeMirror.getValue();
var failedCommentTest = false;
if (userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\*\//gi) == null) {
failedCommentTest = true;
}
else if (cls) {
if(challengeType !== 0)
else if (!failedCommentTest && userJavaScript.match(/\/\*/gi) && userJavaScript.match(/\/\*/gi).length > userJavaScript.match(/\*\//gi).length) {
failedCommentTest = true;
}
userJavaScript = removeComments(userJavaScript);
userJavaScript = scrapeTests(userJavaScript);
// simple fix in case the user forgets to invoke their function

submit(userJavaScript, function (cls, message) {
if (failedCommentTest) {
myCodeMirror.setValue(myCodeMirror.getValue() + "*/");
console.log('Caught Unfinished Comment');
codeOutput.setValue("Unfinished mulit-line comment");
failedCommentTest = false;
}
else if (cls) {
codeOutput.setValue(message.error);
runTests('Error', null);
} else {
if(challengeType !== 0)
runTests('Error', null);
} else {
codeOutput.setValue(message.output);
if(challengeType !== 0)
codeOutput.setValue(codeOutput.getValue().replace(/\\\"/gi, ''));
message.input = removeLogs(message.input);
runTests(null, message);
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() {
Expand Down
4 changes: 3 additions & 1 deletion public/js/lib/coursewares/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ var reset = function() {
setTimeout( function() {
endLoading();
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();
}, 10);
});
Expand Down

0 comments on commit f06d6ca

Please sign in to comment.