mid finished linting commonFramework

pull/2770/head
Berkeley Martinez 2015-08-27 00:15:13 -07:00
parent 8f54932cab
commit 384dec42ac
1 changed files with 92 additions and 76 deletions

View File

@ -1,4 +1,4 @@
/* globals CodeMirror, challenge_Name */ /* globals CodeMirror, challenge_Name, challengeType */
// codeStorage // codeStorage
var codeStorageFactory = (function($, localStorage) { var codeStorageFactory = (function($, localStorage) {
@ -68,6 +68,12 @@ var codeStorageFactory = (function($, localStorage) {
return codeStorageFactory; return codeStorageFactory;
}($, localStorage)); }($, localStorage));
function replaceSafeTags(value) {
return value
.replace(/fccss/gi, '<script>')
.replace(/fcces/gi, '</script>');
}
var isInitRun = false; var isInitRun = false;
var initPreview = true; var initPreview = true;
var editor; var editor;
@ -106,30 +112,30 @@ var allSeeds = '';
}); });
})(); })();
editor.setOption("extraKeys", { editor.setOption('extraKeys', {
Tab: function(cm) { Tab: function(cm) {
if (cm.somethingSelected()){ if (cm.somethingSelected()) {
cm.indentSelection("add"); cm.indentSelection('add');
} else { } else {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" "); var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
cm.replaceSelection(spaces); cm.replaceSelection(spaces);
}
},
"Shift-Tab": function(cm) {
if (cm.somethingSelected()){
cm.indentSelection("subtract");
} else {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces);
}
},
"Ctrl-Enter": function() {
bonfireExecute(true);
return false;
} }
},
'Shift-Tab': function(cm) {
if (cm.somethingSelected()) {
cm.indentSelection('subtract');
} else {
var spaces = Array(cm.getOption('indentUnit') + 1).join(' ');
cm.replaceSelection(spaces);
}
},
'Ctrl-Enter': function() {
bonfireExecute(true);
return false;
}
}); });
editor.setSize("100%", "auto"); editor.setSize('100%', 'auto');
var libraryIncludes = "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>" + var libraryIncludes = "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>" +
"<script src='/js/lib/chai/chai.js'></script>" + "<script src='/js/lib/chai/chai.js'></script>" +
@ -141,39 +147,44 @@ var libraryIncludes = "<script src='//ajax.googleapis.com/ajax/libs/jquery/2.1.3
"<style>body { padding: 0px 3px 0px 3px; }</style>" + "<style>body { padding: 0px 3px 0px 3px; }</style>" +
"<script>var expect = chai.expect; var should = chai.should(); var assert = chai.assert;</script>"; "<script>var expect = chai.expect; var should = chai.should(); var assert = chai.assert;</script>";
var editorValueForIFrame; var editorValueForIFrame;
var iFrameScript = "<script src='/js/iFrameScripts.js'></script>"; var iFrameScript = "<script src='/js/iFrameScripts.js'></script>";
var delay; var delay;
// Initialize CodeMirror editor with a nice html5 canvas demo. // Initialize CodeMirror editor with a nice html5 canvas demo.
editor.on("keyup", function () { editor.on('keyup', function() {
clearTimeout(delay); clearTimeout(delay);
delay = setTimeout(updatePreview, 300); delay = setTimeout(updatePreview, 300);
}); });
function workerError(error){ function workerError(error) {
var display = $('.runTimeError'); var display = $('.runTimeError');
var housing = $('#testSuite'); var housing = $('#testSuite');
if(display.html() != error){ if (display.html() !== error) {
display.remove(); display.remove();
housing.prepend("<div class = \"runTimeError\" style= \"font-size: 18px;\"><code>" + error.replace(/j\$/gi, "$").replace(/jdocument/gi, "document").replace(/jjQuery/gi, "jQuery") + "</code></div>"); housing.prepend(
display.hide().fadeIn(function(){ '<div class="runTimeError" style="font-size: 18px;"><code>' +
setTimeout(function(){ error.replace(/j\$/gi, '$').replace(/jdocument/gi, 'document').replace(/jjQuery/gi, 'jQuery') +
display.fadeOut(function(){ '</code></div>'
display.remove(); );
}); display.hide().fadeIn(function() {
}, 1000) setTimeout(function() {
display.fadeOut(function() {
display.remove();
}); });
} }, 1000);
});
}
} }
function scopejQuery(s){ function scopejQuery(str) {
return(s.replace(/\$/gi, "j$").replace(/document/gi, "jdocument").replace(/jQuery/gi, "jjQuery")); return str
.replace(/\$/gi, 'j$')
.replace(/document/gi, 'jdocument')
.replace(/jQuery/gi, 'jjQuery');
} }
function safeHTMLRun(test){ function safeHTMLRun(test) {
if(challengeType === "0"){ if(challengeType === "0"){
var previewFrame = document.getElementById('preview'); var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document; var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
@ -328,32 +339,36 @@ function showCompletion() {
} }
var resetEditor = function resetEditor() { var resetEditor = function resetEditor() {
editor.setValue(allSeeds.replace((/fccss/gi), '<script>').replace((/fcces/gi), '</script>')); editor.setValue(replaceSafeTags(allSeeds));
$('#testSuite').empty(); $('#testSuite').empty();
bonfireExecute(true); bonfireExecute(true);
codeStorage.updateStorage(); codeStorage.updateStorage();
}; };
var attempts = 0; var attempts = 0;
if (attempts) { if (attempts) {
attempts = 0; attempts = 0;
} }
if(challengeType !== "0") { if (challengeType !== '0') {
var codeOutput = CodeMirror.fromTextArea(document.getElementById("codeOutput"), { var codeOutput = CodeMirror.fromTextArea(
lineNumbers: false, document.getElementById('codeOutput'),
mode: "text", {
theme: 'monokai', lineNumbers: false,
readOnly: 'nocursor', mode: 'text',
lineWrapping: true theme: 'monokai',
}); readOnly: 'nocursor',
lineWrapping: true
}
);
codeOutput.setValue('/**\n' + codeOutput.setValue('/**\n' +
' * Your output will go here.\n' + ' * Console.log() -type statements\n' + ' * Your output will go here.\n' + ' * Console.log() -type statements\n' +
' * will appear in your browser\'s\n' + ' * DevTools JavaScript console.\n' + ' * will appear in your browser\'s\n' + ' * DevTools JavaScript console.\n' +
' */'); ' */');
codeOutput.setSize("100%", "100%"); codeOutput.setSize("100%", "100%");
} }
var info = editor.getScrollInfo(); var info = editor.getScrollInfo();
var after = editor.charCoords({ var after = editor.charCoords({
line: editor.getCursor().line + 1, line: editor.getCursor().line + 1,
@ -584,21 +599,22 @@ $('#submitButton').on('click', function() {
}); });
$(document).ready(function() { $(document).ready(function() {
var $preview = $('#preview'); var $preview = $('#preview');
isInitRun = true; isInitRun = true;
editorValue = codeStorage.isAlive() ? editorValue = codeStorage.isAlive() ?
codeStorage.getStoredValue() : codeStorage.getStoredValue() :
allSeeds; allSeeds;
myCodeMirror.setValue(editorValue.replace(/fccss/gi, '<script>').replace(/fcces/gi, "</script>")); myCodeMirror.setValue(replaceSafeTags(editorValue));
if (typeof $preview.html() !== 'undefined') {
$preview.load(function(){ if (typeof $preview.html() !== 'undefined') {
if (initPreview) { $preview.load(function() {
bonfireExecute(true); if (initPreview) {
}
});
} else{
bonfireExecute(true); bonfireExecute(true);
} }
});
} else {
bonfireExecute(true);
}
}); });