/** * Created by nathanleniz on 2/2/15. */ var widgets = []; var myCodeMirror = CodeMirror.fromTextArea(document.getElementById("codeEditor"), { lineNumbers: true, mode: "text/html", theme: 'monokai', runnable: true, //lint: true, matchBrackets: true, autoCloseBrackets: true, scrollbarStyle: 'null', lineWrapping: true, gutters: ["CodeMirror-lint-markers"], onKeyEvent: doLinting }); var editor = myCodeMirror; // Hijack tab key to insert two spaces instead editor.setOption("extraKeys", { Tab: function(cm) { if (cm.somethingSelected()){ cm.indentSelection("add"); } else { var spaces = Array(cm.getOption("indentUnit") + 1).join(" "); 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(); return false; } }); editor.setSize("100%", "auto"); var libraryIncludes = "" + "" + "" + "" + "" + "" + "" + "" + ""; var allTests = ''; (function() { tests.forEach(function(elem) { allTests += elem + ' '; }); })(); var otherTestsForNow = ""; var delay; // Initialize CodeMirror editor with a nice html5 canvas demo. editor.on("change", function () { clearTimeout(delay); delay = setTimeout(updatePreview, 300); }); var nodeEnv = prodOrDev === 'production' ? 'http://www.freecodecamp.com' : 'http://localhost:3001'; function updatePreview() { goodTests = 0; var previewFrame = document.getElementById('preview'); var preview = previewFrame.contentDocument || previewFrame.contentWindow.document; preview.open(); $('#testSuite').empty(); preview.write(libraryIncludes + editor.getValue() + otherTestsForNow); preview.close(); } setTimeout(updatePreview, 300); /** * "post" methods */ var postSuccess = function(data) { var testDoc = document.createElement("div"); $(testDoc) .html("